public async Task SetActionAsync(CommandContext ctx, [Description("Action type.")] PunishmentActionType action) { CachedGuildConfig gcfg = this.Shared.GetGuildConfig(ctx.Guild.Id); gcfg.RatelimitSettings.Action = action; await this.Database.UpdateGuildSettingsAsync(ctx.Guild.Id, gcfg); DiscordChannel logchn = this.Shared.GetLogChannelForGuild((DiscordClientImpl)ctx.Client, ctx.Guild); if (logchn != null) { var emb = new DiscordEmbedBuilder() { Title = "Guild config changed", Color = this.ModuleColor }; emb.AddField("User responsible", ctx.User.Mention, inline: true); emb.AddField("Invoked in", ctx.Channel.Mention, inline: true); emb.AddField("Ratelimit action changed to", gcfg.RatelimitSettings.Action.ToTypeString()); await logchn.SendMessageAsync(embed : emb.Build()); } await this.InformAsync(ctx, $"Ratelimit action for this guild has been changed to {Formatter.Bold(gcfg.RatelimitSettings.Action.ToTypeString())}", important : false); }
public async Task ExecuteGroupAsync(CommandContext ctx, [Description("Enable?")] bool enable, [Description("Sensitivity (number of users allowed to join within a given timespan).")] short sensitivity, [Description("Action type.")] PunishmentActionType action = PunishmentActionType.Kick, [Description("Cooldown.")] TimeSpan?cooldown = null) { if (sensitivity < 2 || sensitivity > 20) { throw new CommandFailedException("The sensitivity is not in the valid range ([2, 20])."); } if (cooldown?.TotalSeconds < 5 || cooldown?.TotalSeconds > 60) { throw new CommandFailedException("The cooldown timespan is not in the valid range ([5, 60] seconds)."); } var settings = new AntifloodSettings { Action = action, Cooldown = (short?)cooldown?.TotalSeconds ?? 10, Enabled = enable, Sensitivity = sensitivity }; using (DatabaseContext db = this.Database.CreateContext()) { DatabaseGuildConfig gcfg = await this.GetGuildConfigAsync(ctx.Guild.Id); gcfg.AntifloodSettings = settings; db.GuildConfig.Update(gcfg); await db.SaveChangesAsync(); } DiscordChannel logchn = this.Shared.GetLogChannelForGuild(ctx.Client, ctx.Guild); if (!(logchn is null)) { var emb = new DiscordEmbedBuilder { Title = "Guild config changed", Description = $"Antiflood {(enable ? "enabled" : "disabled")}", Color = this.ModuleColor }; emb.AddField("User responsible", ctx.User.Mention, inline: true); emb.AddField("Invoked in", ctx.Channel.Mention, inline: true); if (enable) { emb.AddField("Antiflood sensitivity", settings.Sensitivity.ToString(), inline: true); emb.AddField("Antiflood cooldown", settings.Cooldown.ToString(), inline: true); emb.AddField("Antiflood action", settings.Action.ToTypeString(), inline: true); } await logchn.SendMessageAsync(embed : emb.Build()); } await this.InformAsync(ctx, $"{Formatter.Bold(enable ? "Enabled" : "Disabled")} antiflood actions.", important : false); }
public static string ToTypeString(this PunishmentActionType type) { switch (type) { case PunishmentActionType.Kick: return("Kick"); case PunishmentActionType.PermanentMute: return("Permanent mute"); case PunishmentActionType.PermanentBan: return("Permanent ban"); case PunishmentActionType.TemporaryBan: return("Temporary ban"); case PunishmentActionType.TemporaryMute: return("Temporary mute"); default: return("Unknown"); } }
public async Task ExecuteGroupAsync(CommandContext ctx, [Description("Enable?")] bool enable, [Description("Sensitivity (messages per 5s to trigger action).")] short sensitivity, [Description("Action type.")] PunishmentActionType action = PunishmentActionType.Mute) { if (sensitivity < 4 || sensitivity > 10) { throw new CommandFailedException("The sensitivity is not in the valid range ([4, 10])."); } CachedGuildConfig gcfg = this.Shared.GetGuildConfig(ctx.Guild.Id); gcfg.RatelimitSettings.Enabled = enable; gcfg.RatelimitSettings.Action = action; gcfg.RatelimitSettings.Sensitivity = sensitivity; await this.Database.UpdateGuildSettingsAsync(ctx.Guild.Id, gcfg); DiscordChannel logchn = this.Shared.GetLogChannelForGuild((DiscordClientImpl)ctx.Client, ctx.Guild); if (logchn != null) { var emb = new DiscordEmbedBuilder() { Title = "Guild config changed", Description = $"Ratelimit {(enable ? "enabled" : "disabled")}", Color = this.ModuleColor }; emb.AddField("User responsible", ctx.User.Mention, inline: true); emb.AddField("Invoked in", ctx.Channel.Mention, inline: true); if (enable) { emb.AddField("Ratelimit sensitivity", gcfg.RatelimitSettings.Sensitivity.ToString(), inline: true); emb.AddField("Ratelimit action", gcfg.RatelimitSettings.Action.ToTypeString(), inline: true); } await logchn.SendMessageAsync(embed : emb.Build()); } await this.InformAsync(ctx, $"{Formatter.Bold(gcfg.RatelimitSettings.Enabled ? "Enabled" : "Disabled")} ratelimit actions.", important : false); }
public async Task SetActionAsync(CommandContext ctx, [Description("Action type.")] PunishmentActionType action) { DatabaseGuildConfig gcfg = await this.ModifyGuildConfigAsync(ctx.Guild.Id, cfg => { cfg.AntifloodAction = action; }); DiscordChannel logchn = this.Shared.GetLogChannelForGuild(ctx.Client, ctx.Guild); if (!(logchn is null)) { var emb = new DiscordEmbedBuilder { Title = "Guild config changed", Color = this.ModuleColor }; emb.AddField("User responsible", ctx.User.Mention, inline: true); emb.AddField("Invoked in", ctx.Channel.Mention, inline: true); emb.AddField("Antiflood action changed to", gcfg.AntifloodAction.ToTypeString()); await logchn.SendMessageAsync(embed : emb.Build()); } await this.InformAsync(ctx, $"Antiflood action for this guild has been changed to {Formatter.Bold(gcfg.AntifloodAction.ToTypeString())}", important : false); }
public async Task ExecuteGroupAsync(CommandContext ctx, [Description("Enable?")] bool enable, [Description("Sensitivity (max repeated messages).")] short sensitivity, [Description("Action type.")] PunishmentActionType action = PunishmentActionType.TemporaryMute) { if (sensitivity < 3 || sensitivity > 10) { throw new CommandFailedException("The sensitivity is not in the valid range ([3, 10])."); } DatabaseGuildConfig gcfg = await this.ModifyGuildConfigAsync(ctx.Guild.Id, cfg => { cfg.AntispamEnabled = enable; cfg.AntispamAction = action; cfg.AntispamSensitivity = sensitivity; }); DiscordChannel logchn = this.Shared.GetLogChannelForGuild(ctx.Client, ctx.Guild); if (!(logchn is null)) { var emb = new DiscordEmbedBuilder { Title = "Guild config changed", Description = $"Antispam {(enable ? "enabled" : "disabled")}", Color = this.ModuleColor }; emb.AddField("User responsible", ctx.User.Mention, inline: true); emb.AddField("Invoked in", ctx.Channel.Mention, inline: true); if (enable) { emb.AddField("Antispam sensitivity", gcfg.AntispamSettings.Sensitivity.ToString(), inline: true); emb.AddField("Antispam action", gcfg.AntispamSettings.Action.ToTypeString(), inline: true); } await logchn.SendMessageAsync(embed : emb.Build()); } await this.InformAsync(ctx, $"{Formatter.Bold(gcfg.AntispamSettings.Enabled ? "Enabled" : "Disabled")} antispam actions.", important : false); }
public async Task PunishMemberAsync(DiscordGuild guild, DiscordMember member, PunishmentActionType type, TimeSpan?cooldown = null, string reason = null) { try { DiscordRole muteRole; SavedTaskInfo task; switch (type) { case PunishmentActionType.Kick: await member.RemoveAsync(reason ?? this.reason); break; case PunishmentActionType.PermanentMute: muteRole = await this.GetOrCreateMuteRoleAsync(guild); if (member.Roles.Contains(muteRole)) { return; } await member.GrantRoleAsync(muteRole, reason ?? this.reason); break; case PunishmentActionType.PermanentBan: await member.BanAsync(1, reason : reason ?? this.reason); break; case PunishmentActionType.TemporaryBan: await member.BanAsync(0, reason : reason ?? this.reason); task = new UnbanTaskInfo(guild.Id, member.Id, cooldown is null ? null : DateTimeOffset.Now + cooldown); await SavedTaskExecutor.ScheduleAsync(this.shard.SharedData, this.shard.Database, this.shard.Client, task); break; case PunishmentActionType.TemporaryMute: muteRole = await this.GetOrCreateMuteRoleAsync(guild); if (member.Roles.Contains(muteRole)) { return; } await member.GrantRoleAsync(muteRole, reason ?? this.reason); task = new UnmuteTaskInfo(guild.Id, member.Id, muteRole.Id, cooldown is null ? null : DateTimeOffset.Now + cooldown); await SavedTaskExecutor.ScheduleAsync(this.shard.SharedData, this.shard.Database, this.shard.Client, task); break; } } catch { var logchn = this.shard.SharedData.GetLogChannelForGuild(this.shard.Client, guild); if (!(logchn is null)) { var emb = new DiscordEmbedBuilder { Title = "User punish attemp failed! Check my permissions...", Color = DiscordColor.Red }; emb.AddField("User", member?.ToString() ?? "unknown", inline: true); emb.AddField("Reason", reason ?? this.reason, inline: false); await logchn.SendMessageAsync(embed : emb.Build()); } } }
public Task ExecuteGroupAsync(CommandContext ctx, [Description("Enable?")] bool enable, [Description("Action type.")] PunishmentActionType action, [Description("Sensitivity (number of users allowed to join within a given timespan).")] short sensitivity = 5, [Description("Cooldown.")] TimeSpan?cooldown = null) => this.ExecuteGroupAsync(ctx, enable, sensitivity, action, cooldown);
public Task ExecuteGroupAsync(CommandContext ctx, [Description("Enable?")] bool enable, [Description("Action type.")] PunishmentActionType action, [Description("Sensitivity (messages per 5s to trigger action).")] short sensitivity = 5) => this.ExecuteGroupAsync(ctx, enable, sensitivity, action);