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 <josh@slendy.pw>

* Update ModerationSlotController.cs

* Include ServerConfiguration class

Co-authored-by: Alex_Sour <52638772+Alex-Sour@users.noreply.github.com>
Co-authored-by: Josh <josh@slendy.pw>
This commit is contained in:
A My Sour 2022-11-05 17:35:10 -03:00 committed by GitHub
parent 58a5311a7d
commit 84e2914e40
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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");
}
}
}