private async Task ExecuteTempbanCommand(CommandContext ctx, DiscordMember member, TimeSpan time, String Reason, Boolean Silent, Boolean DmMember) { if (!ctx.Member.HasPermission("insanitybot.moderation.tempban")) { await ctx.Channel.SendMessageAsync(InsanityBot.LanguageConfig["insanitybot.error.lacking_permission"]); return; } String BanReason = Reason switch { "usedefault" => GetFormattedString(InsanityBot.LanguageConfig["insanitybot.moderation.no_reason_given"], ctx, member), _ => GetFormattedString(Reason, ctx, member) }; DiscordEmbedBuilder embedBuilder = null; DiscordEmbedBuilder moderationEmbedBuilder = new() { Title = "TEMPBAN", Color = DiscordColor.Red, Footer = new DiscordEmbedBuilder.EmbedFooter { Text = "InsanityBot 2020-2021" } }; moderationEmbedBuilder.AddField("Moderator", ctx.Member.Mention, true) .AddField("Member", member.Mention, true) .AddField("Duration", time.ToString(), true) .AddField("Reason", BanReason, true); try { BanStartingEvent(); Timer callbackTimer = new(DateTime.Now.Add(time), $"tempban_{member.Id}"); moderationEmbedBuilder.AddField("Timer GUID", callbackTimer.Guid.ToString(), true); TimeHandler.AddTimer(callbackTimer); _ = member.TryAddModlogEntry(ModlogEntryType.ban, BanReason); embedBuilder = new DiscordEmbedBuilder { Description = GetFormattedString(InsanityBot.LanguageConfig["insanitybot.moderation.ban.success"], ctx, member), Color = DiscordColor.Red, Footer = new DiscordEmbedBuilder.EmbedFooter { Text = "InsanityBot 2020-2021" } }; _ = InsanityBot.HomeGuild.BanMemberAsync(member, 0, BanReason); _ = InsanityBot.ModlogQueue.QueueMessage(ModlogMessageType.Moderation, new DiscordMessageBuilder { Embed = moderationEmbedBuilder }); } catch { embedBuilder = new DiscordEmbedBuilder { Description = GetFormattedString(InsanityBot.LanguageConfig["insanitybot.moderation.ban.failure"], ctx, member), Color = DiscordColor.Red, Footer = new DiscordEmbedBuilder.EmbedFooter { Text = "InsanityBot 2020-2021" } }; } finally { if (embedBuilder == null) { InsanityBot.Client.Logger.LogError(new EventId(1151, "Tempban"), "Could not execute tempban command, an unknown exception occured."); } else { await ctx.Channel.SendMessageAsync(embed : embedBuilder.Build()); } } }
private async Task ExecuteTempmuteCommand(CommandContext ctx, DiscordMember member, TimeSpan time, String Reason, Boolean Silent, Boolean DmMember) { if (!ctx.Member.HasPermission("insanitybot.moderation.tempmute")) { await ctx.RespondAsync(InsanityBot.LanguageConfig["insanitybot.error.lacking_permission"]); return; } String MuteReason = Reason switch { "usedefault" => GetFormattedString(InsanityBot.LanguageConfig["insanitybot.moderation.no_reason_given"], ctx, member), _ => GetFormattedString(Reason, ctx, member) }; DiscordEmbedBuilder embedBuilder = null; DiscordEmbedBuilder moderationEmbedBuilder = new DiscordEmbedBuilder { Title = "TEMPMUTE", Color = DiscordColor.Red, Footer = new DiscordEmbedBuilder.EmbedFooter { Text = "InsanityBot - ExaInsanity 2020-2021" } }; moderationEmbedBuilder.AddField("Moderator", ctx.Member.Mention, true) .AddField("Member", member.Mention, true) .AddField("Duration", time.ToString(), true) .AddField("Reason", MuteReason, true); try { MuteStartingEvent(); Timer callbackTimer = new Timer(DateTime.Now.Add(time), $"tempmute_{member.Id}"); moderationEmbedBuilder.AddField("Timer GUID", callbackTimer.Guid.ToString(), true); TimeHandler.AddTimer(callbackTimer); member.AddModlogEntry(ModlogEntryType.mute, MuteReason); embedBuilder = new DiscordEmbedBuilder { Description = GetFormattedString(InsanityBot.LanguageConfig["insanitybot.moderation.mute.success"], ctx, member), Color = DiscordColor.Red, Footer = new DiscordEmbedBuilder.EmbedFooter { Text = "InsanityBot - ExaInsanity 2020-2021" } }; _ = member.GrantRoleAsync(InsanityBot.HomeGuild.GetRole( ToUInt64(InsanityBot.Config["insanitybot.identifiers.moderation.mute_role_id"])), MuteReason); _ = InsanityBot.HomeGuild.GetChannel(ToUInt64(InsanityBot.Config["insanitybot.identifiers.commands.modlog_channel_id"])) .SendMessageAsync(embed: moderationEmbedBuilder.Build()); } catch { embedBuilder = new DiscordEmbedBuilder { Description = GetFormattedString(InsanityBot.LanguageConfig["insanitybot.moderation.mute.failure"], ctx, member), Color = DiscordColor.Red, Footer = new DiscordEmbedBuilder.EmbedFooter { Text = "InsanityBot - ExaInsanity 2020-2021" } }; } finally { if (embedBuilder == null) { InsanityBot.Client.Logger.LogError(new EventId(1131, "Tempmute"), "Could not execute tempmute command, an unknown exception occured."); } else { await ctx.RespondAsync(embed : embedBuilder.Build()); } } }