/// <summary> /// 新增警告数据 /// </summary> /// <param name="msg"></param> public static void AddWarningData(object msg) { if (Warns.Count > 0) { DateTime first = Warns.Last().Now; Warns.Add(new WarningData(msg)); DateTime last = Warns.Last().Now; TimeSpan cha = last - first; if (cha.TotalSeconds > 10) { Warns.Last().StyleStart = "<font color='red'>"; Warns.Last().StyleEnd = "</font>"; } else if (cha.TotalSeconds > 3) { Warns.Last().StyleStart = "<font color='blue'>"; Warns.Last().StyleEnd = "</font>"; } else if (cha.TotalSeconds > 0.2) { Warns.Last().StyleStart = "<font color='green'>"; Warns.Last().StyleEnd = "</font>"; } } else { Warns.Add(new WarningData(msg)); } }
internal async Task Warn(DiscordChannel channel, string reason = "No reason specified") { DiscordGuild Guild = await discord.GetGuildAsync(GuildID); DiscordMember Member = await Guild.GetMemberAsync(ID); DiscordEmbedBuilder WarnMessage = new DiscordEmbedBuilder { Title = $"Warns | {Member.Username}", Description = $"**{Member.Mention} has been warned for the following Reason:**\n{reason}\n**Muted: False**", Color = EmbedColor, Footer = new DiscordEmbedBuilder.EmbedFooter { Text = "Made by JokinAce 😎" }, Timestamp = DateTimeOffset.Now }; if ((Warns.Count + 1) >= 3) { if (!Muted) { DateTime MuteTime = DateTime.Now.AddDays(1); DiscordRole MutedRole = Guild.GetRole(Program.MutedRole); await Member.GrantRoleAsync(MutedRole); await SQLC.AddTempmute((long)Member.Id, MuteTime.ToBinary()); Muted = true; WarnMessage.WithDescription($"**{Member.Mention} has been warned for the following Reason:**\n{reason}\n**Muted: True**"); WarnMessage.WithTimestamp(MuteTime); _ = Task.Run(async() => { try { await Task.Delay(86400000); DiscordGuild Guild = await discord.GetGuildAsync(GuildID); DiscordRole MutedRole = Guild.GetRole(Program.MutedRole); var PS = await SQLC.GetPlayer(Member.Id); PS.Muted = false; await PS.Save(); await SQLC.DeleteTempmutesWithID((long)Member.Id); await Member.RevokeRoleAsync(MutedRole); } catch (Exception) { discord.Logger.LogInformation($"Failed the Warn Tempmute process for {Member.Username + "#" + Member.Discriminator}"); } }); } else { WarnMessage.WithDescription($"**{Member.Mention} has been warned for the following Reason:**\n{reason}\n**Muted: Already muted**"); } } var msg = await channel.SendMessageAsync(WarnMessage); Warns.Add($"{reason} | [Event]({msg.JumpLink})"); }
static void LogWarn(string error) { Warns.Add(error); }