public async Task WarnMemberAsync(CommandContext context, [Description("Guild Member to Warn")] DiscordMember member, [Description("Reason for warning")] [RemainingText] string reason) { DiscordEmbedBuilder successEmbed = new DiscordEmbedBuilder() .WithTitle($"You have received a warning!") .AddField("Guild:", context.Guild.Name) .AddField("Reason:", reason); using IBotAccessProvider provider = this.providerBuilder.Build(); DiscordChannel logChannel = await SendModerationEmbedAndGetLogChannel(successEmbed, member, context.Member, context.Guild, provider); provider.AddModerationAuditRecord(context.Guild.Id, context.User.Id, member.Id, ModerationActionType.WARN, reason); if (logChannel == null) { return; } successEmbed = new DiscordEmbedBuilder() .WithTitle($"{member.Username} has received a warning!") .AddField("Moderator:", context.User.Username) .AddField("Reason:", reason) .WithFooter($"{this.clock.GetCurrentInstant():g}"); await logChannel.SendMessageAsync(embed : successEmbed); await context.Message.CreateReactionAsync(DiscordEmoji.FromName(context.Client, ":white_check_mark:")); }
public async Task BanMemberAsync(CommandContext context, [Description("Guild Member to Ban")] DiscordMember member, [Description("Number of days worth of their messages to delete")] int numDays = 0, [Description("Reason for ban")] [RemainingText] string reason = null) { DiscordEmbedBuilder messageEmbed = new DiscordEmbedBuilder() .WithTitle($"You have been banned from {context.Guild.Name}!"); if (reason != null) { messageEmbed.AddField("Reason:", reason); } using IBotAccessProvider provider = this.providerBuilder.Build(); DiscordChannel logChannel = await SendModerationEmbedAndGetLogChannel(messageEmbed, member, context.Member, context.Guild, provider); await member.BanAsync(numDays, reason); provider.AddModerationAuditRecord(context.Guild.Id, context.User.Id, member.Id, ModerationActionType.BAN, reason); if (logChannel == null) { return; } DiscordEmbedBuilder successEmbed = new DiscordEmbedBuilder() .WithTitle($"{member.Username} was banned") .AddField("Moderator", context.User.Username) .WithFooter($"{this.clock.GetCurrentInstant():g}"); if (reason != null) { successEmbed.AddField("Reason:", reason); } await logChannel.SendMessageAsync(embed : successEmbed); await context.Message.CreateReactionAsync(DiscordEmoji.FromName(context.Client, ":white_check_mark:")); }
public async Task MuteMemberAsync(CommandContext context, [Description("The member to mute")] DiscordMember member, [RemainingText] [Description("The reason for the mute")] string reason = null) { DiscordRole mutedRole = await GetOrCreateMutedRole(context); DiscordEmbedBuilder successEmbed = new DiscordEmbedBuilder() .WithTitle($"You have been muted in {context.Guild.Name}!"); if (reason != null) { successEmbed.AddField("Reason:", reason); } using IBotAccessProvider provider = this.providerBuilder.Build(); DiscordChannel logChannel = await SendModerationEmbedAndGetLogChannel(successEmbed, member, context.Member, context.Guild, provider); await member.GrantRoleAsync(mutedRole, reason); provider.AddModerationAuditRecord(context.Guild.Id, context.User.Id, member.Id, ModerationActionType.MUTE, reason); await context.Message.CreateReactionAsync(DiscordEmoji.FromName(context.Client, ":white_check_mark:")); if (logChannel == null) { return; } successEmbed = new DiscordEmbedBuilder() .WithTitle($"{member.DisplayName} was muted") .AddField("Moderator", context.Member.DisplayName) .WithFooter($"{this.clock.GetCurrentInstant():g}"); if (reason != null) { successEmbed.AddField("Reason", reason); } await logChannel.SendMessageAsync(embed : successEmbed); }
public async Task TempMuteMemberAsync(CommandContext context, [Description("The member to mute")] DiscordMember member, [Description("Duration to mute the member for (must be quoted if there are any spaces, however it should work with colloquial language)")] string durationOfMute, [RemainingText] [Description("The reason for the mute")] string reason = null) { DateTimeV2ModelResult durationResult = DateTimeRecognizer .RecognizeDateTime(durationOfMute, culture: Culture.English) .Select(model => model.ToDateTimeV2ModelResult()) .Where(result => result.TypeName is DateTimeV2Type.Duration) .FirstOrDefault(); if (durationResult == null) { await context.RespondAsync("There was an error parsing the duration"); return; } Duration duration = (Duration)durationResult.Values.FirstOrDefault().Value; string durationString = Period.FromSeconds((long)duration.TotalSeconds).AsHumanReadableString(); DiscordRole mutedRole = await GetOrCreateMutedRole(context); DiscordEmbedBuilder successEmbed = new DiscordEmbedBuilder() .WithTitle($"You have been temporarily muted in {context.Guild.Name}!") .AddField("Duration", durationString); if (reason != null) { successEmbed.AddField("Reason:", reason); } using IBotAccessProvider provider = this.providerBuilder.Build(); DiscordChannel logChannel = await SendModerationEmbedAndGetLogChannel(successEmbed, member, context.Member, context.Guild, provider); await member.GrantRoleAsync(mutedRole, reason); provider.AddModerationAuditRecord(context.Guild.Id, context.User.Id, member.Id, ModerationActionType.MUTE, reason); await context.Message.CreateReactionAsync(DiscordEmoji.FromName(context.Client, ":white_check_mark:")); if (logChannel == null) { return; } successEmbed = new DiscordEmbedBuilder() .WithTitle($"{member.DisplayName} was muted") .AddField("Moderator", context.Member.DisplayName) .AddField("Duration", durationString) .WithFooter($"{this.clock.GetCurrentInstant():g}"); if (reason != null) { successEmbed.AddField("Reason", reason); } await logChannel.SendMessageAsync(embed : successEmbed); string jobId = BackgroundJob.Schedule <ModerationService>(service => service.RemoveRole(context.Guild.Id, member.Id, mutedRole.Id), duration.ToTimeSpan()); provider.AddGuildBackgroundJob(jobId, context.Guild.Id, $"Unmute - {member.DisplayName}", this.clock.GetCurrentInstant() + duration, GuildJobType.TEMP_MUTE); }