public async Task SendPunishmentWebhook(int punishmentId) { PlayerPunishment punishment = database.GetPunishment(punishmentId); if (punishment == null) { return; } using (var client = new DiscordWebhookClient(webhookUrl)) { EmbedBuilder eb = new EmbedBuilder(); eb.WithColor(Color.Blue); eb.WithTitle($"{CultureInfo.CurrentCulture.TextInfo.ToTitleCase(punishment.Category)}"); eb.AddField("Player", $"[{punishment.Player.PlayerName}](https://steamcommunity.com/profiles/{punishment.PlayerId})"); eb.AddField("Punisher", $"[{punishment.Punisher.PlayerName}](https://steamcommunity.com/profiles/{punishment.PunisherId})"); eb.AddField("Reason", punishment.Reason == null ? "unkown" : punishment.Reason); if (punishment.ExpiryDate.HasValue) { eb.AddField("Expires", punishment.ExpiryDate); } eb.WithTimestamp(punishment.CreateDate); await client.SendMessageAsync(embeds : new List <Embed>() { eb.Build() }); } }
public static int CreatePunishment(this DatabaseManager database, PlayerPunishment punishment) { string sql = "INSERT INTO dbo.PlayerPunishments (PlayerId, PunisherId, Category, Reason, ExpiryDate, CreateDate) OUTPUT INSERTED.PunishmentId " + "VALUES (@PlayerId, @PunisherId, @Category, @Reason, @ExpiryDate, @CreateDate);"; using (var conn = database.connection) { return(conn.ExecuteScalar <int>(sql, punishment)); } }
public async Task <PlayerPunishment> CreatePunishment([FromBody] PlayerPunishment punishment) { Console.ForegroundColor = ConsoleColor.Red; punishment.PunisherId = User.FindFirst(ClaimTypes.Name).Value; punishment.CreateDate = DateTime.Now; punishment.PunishmentId = _database.CreatePunishment(punishment); punishment = _database.GetPunishment(punishment.PunishmentId); await Task.Factory.StartNew(async() => { await _messager.SendPunishmentWebhook(punishment.PunishmentId); }); return(punishment); }
public async Task SendUnbanWebhook(int punishmentId) { PlayerPunishment punishment = database.GetPunishment(punishmentId); if (punishment == null) { return; } using (var client = new DiscordWebhookClient(webhookUrl)) { EmbedBuilder eb = new EmbedBuilder(); eb.WithColor(Color.Green); eb.WithDescription($"{punishment.Player.PlayerName}'s ban expired!"); eb.WithTimestamp(DateTime.Now); await client.SendMessageAsync(embeds : new List <Embed>() { eb.Build() }); } }