From 84e2914e4024f71c2967c757ba3281d0782edf64 Mon Sep 17 00:00:00 2001 From: A My Sour <52638772+aMySour@users.noreply.github.com> Date: Sat, 5 Nov 2022 17:35:10 -0300 Subject: [PATCH] Add webhook message when a new Team Pick is added (#528) * Add webhook message when a new Team Pick is added * Update ProjectLighthouse.Servers.Website/Controllers/Admin/ModerationSlotController.cs Co-authored-by: Josh * Update ModerationSlotController.cs * Include ServerConfiguration class Co-authored-by: Alex_Sour <52638772+Alex-Sour@users.noreply.github.com> Co-authored-by: Josh --- .../Controllers/Admin/ModerationSlotController.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/ProjectLighthouse.Servers.Website/Controllers/Admin/ModerationSlotController.cs b/ProjectLighthouse.Servers.Website/Controllers/Admin/ModerationSlotController.cs index f7cf2ec6..20ebae4a 100644 --- a/ProjectLighthouse.Servers.Website/Controllers/Admin/ModerationSlotController.cs +++ b/ProjectLighthouse.Servers.Website/Controllers/Admin/ModerationSlotController.cs @@ -1,8 +1,10 @@ #nullable enable +using LBPUnion.ProjectLighthouse.Configuration; using LBPUnion.ProjectLighthouse.Levels; using LBPUnion.ProjectLighthouse.PlayerData.Profiles; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; +using LBPUnion.ProjectLighthouse.Helpers; namespace LBPUnion.ProjectLighthouse.Servers.Website.Controllers.Admin; @@ -23,10 +25,13 @@ public class ModerationSlotController : ControllerBase User? user = this.database.UserFromWebRequest(this.Request); if (user == null || !user.IsModerator) return this.StatusCode(403, ""); - Slot? slot = await this.database.Slots.FirstOrDefaultAsync(s => s.SlotId == id); + Slot? slot = await this.database.Slots.Include(s => s.Creator).FirstOrDefaultAsync(s => s.SlotId == id); if (slot == null) return this.NotFound(); slot.TeamPick = true; + // Send webhook with slot.Name and slot.Creator.Username + await WebhookHelper.SendWebhook("New Team Pick!", $"The level [**{slot.Name}**]({ServerConfiguration.Instance.ExternalUrl}/slot/{slot.SlotId}) by **{slot.Creator?.Username}** has been team picked"); + await this.database.SaveChangesAsync(); return this.Redirect("~/slot/" + id); } @@ -58,4 +63,4 @@ public class ModerationSlotController : ControllerBase return this.Redirect("~/slots/0"); } -} \ No newline at end of file +}