public async Task WarnPunish(int number, PunishmentAction punish, StoopidTime time = null) { if ((punish != PunishmentAction.Ban && punish != PunishmentAction.Mute) && time != null) { return; } if (number <= 0 || (time != null && time.Time > TimeSpan.FromDays(49))) { return; } using (var uow = _db.UnitOfWork) { var ps = uow.GuildConfigs.ForId(Context.Guild.Id, set => set.Include(x => x.WarnPunishments)).WarnPunishments; ps.RemoveAll(x => x.Count == number); ps.Add(new WarningPunishment() { Count = number, Punishment = punish, Time = (int?)(time?.Time.TotalMinutes) ?? 0, }); uow.Complete(); } await ReplyConfirmLocalized("warn_punish_set", Format.Bold(punish.ToString()), Format.Bold(number.ToString())).ConfigureAwait(false); }
public bool WarnPunish(ulong guildId, int number, PunishmentAction punish, StoopidTime time) { if ((punish != PunishmentAction.Ban && punish != PunishmentAction.Mute) && time != null) { return(false); } if (number <= 0 || (time != null && time.Time > TimeSpan.FromDays(49))) { return(false); } using (var uow = _db.UnitOfWork) { var ps = uow.GuildConfigs.ForId(guildId, set => set.Include(x => x.WarnPunishments)).WarnPunishments; ps.RemoveAll(x => x.Count == number); ps.Add(new WarningPunishment() { Count = number, Punishment = punish, Time = (int?)(time?.Time.TotalMinutes) ?? 0, }); uow.Complete(); } return(true); }
public bool WarnPunish(ulong guildId, int number, PunishmentAction punish, StoopidTime time) { if ((punish != PunishmentAction.Ban && punish != PunishmentAction.Mute) && time != null) { return(false); } if (number <= 0 || (time != null && time.Time > TimeSpan.FromDays(49))) { return(false); } using (var uow = _db.GetDbContext()) { var ps = uow.GuildConfigs.ForId(guildId, set => set.Include(x => x.WarnPunishments)).WarnPunishments; var toDelete = ps.Where(x => x.Count == number); uow._context.RemoveRange(toDelete); ps.Add(new WarningPunishment() { Count = number, Punishment = punish, Time = (int?)(time?.Time.TotalMinutes) ?? 0, }); uow.SaveChanges(); } return(true); }
public async Task AntiSpam(IUserMessage imsg, int messageCount = 3, PunishmentAction action = PunishmentAction.Mute) { var channel = (ITextChannel)imsg.Channel; if (messageCount < 2 || messageCount > 10) { return; } AntiSpamSetting throwaway; if (antiSpamGuilds.TryRemove(channel.Guild.Id, out throwaway)) { await channel.SendMessageAsync("`Anti-Spam feature disabled on this server.`").ConfigureAwait(false); } else { if (antiSpamGuilds.TryAdd(channel.Guild.Id, new AntiSpamSetting() { Action = action, MuteRole = await GetMuteRole(channel.Guild).ConfigureAwait(false), MessageThreshold = messageCount, })) { await channel.SendMessageAsync("`Anti-Spam feature enabled on this server.`").ConfigureAwait(false); } } }
public async Task WarnPunish(int number, PunishmentAction punish, StoopidTime time = null) { // this should never happen. Addrole has its own method with higher priority if (punish == PunishmentAction.AddRole) { return; } var success = _service.WarnPunish(ctx.Guild.Id, number, punish, time); if (!success) { return; } if (time is null) { await ReplyConfirmLocalizedAsync("warn_punish_set", Format.Bold(punish.ToString()), Format.Bold(number.ToString())).ConfigureAwait(false); } else { await ReplyConfirmLocalizedAsync("warn_punish_set_timed", Format.Bold(punish.ToString()), Format.Bold(number.ToString()), Format.Bold(time.Input)).ConfigureAwait(false); } }
public async Task InternalAntiSpam(int messageCount, PunishmentAction action, StoopidTime timeData = null, IRole role = null) { if (messageCount < 2 || messageCount > 10) { return; } if (!(timeData is null)) { if (!_service.IsDurationAllowed(action)) { await ReplyErrorLocalizedAsync("prot_cant_use_time"); } } var time = (int?)timeData?.Time.TotalMinutes ?? 0; if (time < 0 || time > 60 * 24) { return; } var stats = await _service.StartAntiSpamAsync(ctx.Guild.Id, messageCount, action, time, role?.Id).ConfigureAwait(false); await ctx.Channel.SendConfirmAsync(GetText("prot_enable", "Anti-Spam"), $"{ctx.User.Mention} {GetAntiSpamString(stats)}").ConfigureAwait(false); }
public async Task WarnPunish(int number, PunishmentAction punish, int time = 0) { if (punish != PunishmentAction.Mute && time != 0) { return; } if (number <= 0) { return; } using (var uow = DbHandler.UnitOfWork()) { var ps = uow.GuildConfigs.For(Context.Guild.Id, set => set.Include(x => x.WarnPunishments)).WarnPunishments; ps.RemoveAll(x => x.Count == number); ps.Add(new WarningPunishment() { Count = number, Punishment = punish, Time = time, }); uow.Complete(); } await ReplyConfirmLocalized("warn_punish_set", Format.Bold(punish.ToString()), Format.Bold(number.ToString())).ConfigureAwait(false); }
public static async Task TriggeredAntiProtection(IGuildUser[] users, PunishmentAction action, ProtectionType protection) { if (users.Length == 0) return; LogSetting logSetting; if (!GuildLogSettings.TryGetValue(users.First().Guild.Id, out logSetting) || !logSetting.IsLogging) return; ITextChannel logChannel; if ((logChannel = TryGetLogChannel(users.First().Guild, logSetting)) == null) return; var punishment = ""; if (action == PunishmentAction.Mute) { punishment = "🔇 MUTED"; //punishment = "MUTED"; } else if (action == PunishmentAction.Kick) { punishment = "☣ SOFT-BANNED (KICKED)"; //punishment = "KICKED"; } else if (action == PunishmentAction.Ban) { punishment = "⛔️ BANNED"; //punishment = "BANNED"; } await logChannel.SendMessageAsync(String.Join("\n",users.Select(user=>$"‼️ {Format.Bold(user.ToString())} got **{punishment}** due to __**{protection}**__ protection on **{user.Guild.Name}** server."))) //await logChannel.SendMessageAsync(String.Join("\n",users.Select(user=>$"{Format.Bold(user.ToString())} was **{punishment}** due to `{protection}` protection on **{user.Guild.Name}** server."))) .ConfigureAwait(false); }
public async Task ExecuteGroupAsync(CommandContext ctx, [Description("desc-enable")] bool enable, [Description("desc-sens")] short sens, [Description("desc-punish-action")] PunishmentAction action = PunishmentAction.TemporaryMute) { if (sens is < AntispamSettings.MinSensitivity or > AntispamSettings.MaxSensitivity) { throw new CommandFailedException(ctx, "cmd-err-range-sens", AntispamSettings.MinSensitivity, AntispamSettings.MaxSensitivity); } var settings = new AntispamSettings { Action = action, Enabled = enable, Sensitivity = sens }; await ctx.Services.GetRequiredService <GuildConfigService>().ModifyConfigAsync(ctx.Guild.Id, gcfg => gcfg.AntispamSettings = settings); await ctx.GuildLogAsync(emb => { emb.WithLocalizedTitle("evt-cfg-upd"); emb.WithColor(this.ModuleColor); if (enable) { emb.WithLocalizedDescription("evt-as-enable"); emb.AddLocalizedTitleField("str-sensitivity", settings.Sensitivity, inline: true); emb.AddLocalizedTitleField("str-punish-action", settings.Action.Humanize(), inline: true); } else { emb.WithLocalizedDescription("evt-as-disable"); } }); await ctx.InfoAsync(enable? "evt-as-enable" : "evt-as-disable"); }
public async Task AntiSpam(int messageCount, PunishmentAction action = PunishmentAction.Mute, int time = 0) { if (messageCount < 2 || messageCount > 10) { return; } if (time < 0 || time > 60 * 12) { return; } try { await _mute.GetMuteRole(Context.Guild).ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); await ReplyErrorLocalized("prot_error").ConfigureAwait(false); return; } var stats = new AntiSpamStats { AntiSpamSettings = new AntiSpamSetting() { Action = action, MessageThreshold = messageCount, MuteTime = time, } }; stats = _service.AntiSpamGuilds.AddOrUpdate(Context.Guild.Id, stats, (key, old) => { stats.AntiSpamSettings.IgnoredChannels = old.AntiSpamSettings.IgnoredChannels; return(stats); }); using (var uow = _db.UnitOfWork) { var gc = uow.GuildConfigs.For(Context.Guild.Id, set => set.Include(x => x.AntiSpamSetting)); if (gc.AntiSpamSetting != null) { gc.AntiSpamSetting.Action = stats.AntiSpamSettings.Action; gc.AntiSpamSetting.MessageThreshold = stats.AntiSpamSettings.MessageThreshold; gc.AntiSpamSetting.MuteTime = stats.AntiSpamSettings.MuteTime; } else { gc.AntiSpamSetting = stats.AntiSpamSettings; } await uow.CompleteAsync().ConfigureAwait(false); } await Context.Channel.SendConfirmAsync(GetText("prot_enable", "Anti-Spam"), $"{Context.User.Mention} {GetAntiSpamString(stats)}").ConfigureAwait(false); }
public async Task AntiSpam(int messageCount = 3, PunishmentAction action = PunishmentAction.Mute) { if (messageCount < 2 || messageCount > 10) { return; } AntiSpamStats throwaway; if (antiSpamGuilds.TryRemove(Context.Guild.Id, out throwaway)) { using (var uow = DbHandler.UnitOfWork()) { var gc = uow.GuildConfigs.For(Context.Guild.Id, set => set.Include(x => x.AntiSpamSetting) .ThenInclude(x => x.IgnoredChannels)); gc.AntiSpamSetting = null; await uow.CompleteAsync().ConfigureAwait(false); } await Context.Channel.SendConfirmAsync("**Anti-Spam** has been **disabled** on this server.").ConfigureAwait(false); return; } try { await MuteCommands.GetMuteRole(Context.Guild).ConfigureAwait(false); } catch (Exception ex) { await Context.Channel.SendErrorAsync("⚠️ Failed creating a mute role. Give me ManageRoles permission" + "or create 'nadeko-mute' role with disabled SendMessages and try again.") .ConfigureAwait(false); _log.Warn(ex); return; } var stats = new AntiSpamStats { AntiSpamSettings = new AntiSpamSetting() { Action = action, MessageThreshold = messageCount, } }; antiSpamGuilds.AddOrUpdate(Context.Guild.Id, stats, (key, old) => stats); using (var uow = DbHandler.UnitOfWork()) { var gc = uow.GuildConfigs.For(Context.Guild.Id, set => set.Include(x => x.AntiSpamSetting)); gc.AntiSpamSetting = stats.AntiSpamSettings; await uow.CompleteAsync().ConfigureAwait(false); } await Context.Channel.SendConfirmAsync("Anti-Spam Enabled", $"{Context.User.Mention} {stats.ToString()}").ConfigureAwait(false); }
public Task TriggeredAntiProtection(PunishmentAction action, ProtectionType protection, params IGuildUser[] users) { var _ = Task.Run(async() => { try { if (users.Length == 0) { return; } if (!GuildLogSettings.TryGetValue(users.First().Guild.Id, out LogSetting logSetting) || (logSetting.LogOtherId == null)) { return; } ITextChannel logChannel; if ((logChannel = await TryGetLogChannel(users.First().Guild, logSetting, LogType.Other)) == null) { return; } var punishment = ""; switch (action) { case PunishmentAction.Mute: punishment = "🔇 " + GetText(logChannel.Guild, "muted_pl").ToUpperInvariant(); break; case PunishmentAction.Kick: punishment = "👢 " + GetText(logChannel.Guild, "kicked_pl").ToUpperInvariant(); break; case PunishmentAction.Softban: punishment = "☣ " + GetText(logChannel.Guild, "soft_banned_pl").ToUpperInvariant(); break; case PunishmentAction.Ban: punishment = "⛔️ " + GetText(logChannel.Guild, "banned_pl").ToUpperInvariant(); break; } var embed = new EmbedBuilder().WithAuthor(eab => eab.WithName($"🛡 Anti-{protection}")) .WithTitle(GetText(logChannel.Guild, "users") + " " + punishment) .WithDescription(string.Join("\n", users.Select(u => u.ToString()))) .WithFooter(fb => fb.WithText(CurrentTime(logChannel.Guild))) .WithOkColor(); await logChannel.EmbedAsync(embed).ConfigureAwait(false); } catch { // ignored } }); return(Task.CompletedTask); }
public async Task AntiSpam(int messageCount = 3, PunishmentAction action = PunishmentAction.Mute) { if (messageCount < 2 || messageCount > 10) { return; } AntiSpamStats throwaway; if (_antiSpamGuilds.TryRemove(Context.Guild.Id, out throwaway)) { throwaway.UserStats.ForEach(x => x.Value.Dispose()); using (var uow = DbHandler.UnitOfWork()) { var gc = uow.GuildConfigs.For(Context.Guild.Id, set => set.Include(x => x.AntiSpamSetting) .ThenInclude(x => x.IgnoredChannels)); gc.AntiSpamSetting = null; await uow.CompleteAsync().ConfigureAwait(false); } await ReplyConfirmLocalized("prot_disable", "Anti-Spam").ConfigureAwait(false); return; } try { await MuteCommands.GetMuteRole(Context.Guild).ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); await ReplyErrorLocalized("prot_error").ConfigureAwait(false); return; } var stats = new AntiSpamStats { AntiSpamSettings = new AntiSpamSetting() { Action = action, MessageThreshold = messageCount, } }; _antiSpamGuilds.AddOrUpdate(Context.Guild.Id, stats, (key, old) => stats); using (var uow = DbHandler.UnitOfWork()) { var gc = uow.GuildConfigs.For(Context.Guild.Id, set => set.Include(x => x.AntiSpamSetting)); gc.AntiSpamSetting = stats.AntiSpamSettings; await uow.CompleteAsync().ConfigureAwait(false); } await Context.Channel.SendConfirmAsync(GetText("prot_enable", "Anti-Spam"), $"{Context.User.Mention} {GetAntiSpamString(stats)}").ConfigureAwait(false); }
public Task AntiSpam(int messageCount, PunishmentAction action, [Leftover] IRole role) { if (action != PunishmentAction.AddRole) { return(Task.CompletedTask); } return(InternalAntiSpam(messageCount, action, null, role)); }
public async Task AntiRaid(int userThreshold = 5, int seconds = 10, PunishmentAction action = PunishmentAction.Mute) { if (userThreshold < 2 || userThreshold > 30) { await ReplyErrorLocalized("raid_cnt", 2, 30).ConfigureAwait(false); return; } if (seconds < 2 || seconds > 300) { await ReplyErrorLocalized("raid_time", 2, 300).ConfigureAwait(false); return; } var gc = uow.GuildConfigs.For(Context.Guild.Id, set => set.Include(x => x.AntiRaidSetting)); if (gc.AntiRaidSetting != null) { uow.Context.Remove(gc.AntiRaidSetting); await uow.SaveChangesAsync(false).ConfigureAwait(false); await ReplyConfirmLocalized("prot_disable", "Anti-Raid").ConfigureAwait(false); } else { try { await _mute.GetMuteRole(Context.Guild).ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); await ReplyErrorLocalized("prot_error").ConfigureAwait(false); return; } if (gc.AntiRaidSetting != null) { gc.AntiRaidSetting.Action = action; gc.AntiRaidSetting.Seconds = seconds; gc.AntiRaidSetting.UserThreshold = userThreshold; } else { gc.AntiRaidSetting = new AntiRaidSetting { Action = action, Seconds = seconds, UserThreshold = userThreshold, }; } await uow.SaveChangesAsync(false).ConfigureAwait(false); await Context.Channel.SendConfirmAsync($"{Context.User.Mention} {GetAntiRaidString(gc.AntiRaidSetting)}", GetText("prot_enable", "Anti-Raid")).ConfigureAwait(false); } }
private static async Task PunishUsers(PunishmentAction action, ProtectionType pt, params IGuildUser[] gus) { _log.Info($"[{pt}] - Punishing [{gus.Length}] users with [{action}] in {gus[0].Guild.Name} guild"); foreach (var gu in gus) { switch (action) { case PunishmentAction.Mute: try { await MuteCommands.MuteUser(gu).ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex, "I can't apply punishement"); } break; case PunishmentAction.Kick: try { await gu.KickAsync().ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex, "I can't apply punishement"); } break; case PunishmentAction.Softban: try { await gu.Guild.AddBanAsync(gu, 7).ConfigureAwait(false); try { await gu.Guild.RemoveBanAsync(gu).ConfigureAwait(false); } catch { await gu.Guild.RemoveBanAsync(gu).ConfigureAwait(false); // try it twice, really don't want to ban user if // only kick has been specified as the punishement } } catch (Exception ex) { _log.Warn(ex, "I can't apply punishment"); } break; case PunishmentAction.Ban: try { await gu.Guild.AddBanAsync(gu, 7).ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex, "I can't apply punishment"); } break; } } await LogCommands.TriggeredAntiProtection(gus, action, pt).ConfigureAwait(false); }
public async Task AntiAlt(StoopidTime minAge, PunishmentAction action, [Leftover] IRole role) { var minAgeMinutes = (int)minAge.Time.TotalMinutes; if (minAgeMinutes < 1) { return; } await _service.StartAntiAltAsync(ctx.Guild.Id, minAgeMinutes, action, roleId : role.Id); await ctx.OkAsync(); }
public async Task WarnPunish(int number, PunishmentAction punish, StoopidTime time = null) { var success = _service.WarnPunish(Context.Guild.Id, number, punish, time); if (!success) { return; } await ReplyConfirmLocalizedAsync("warn_punish_set", Format.Bold(punish.ToString()), Format.Bold(number.ToString())).ConfigureAwait(false); }
private async Task InternalAntiRaid(int userThreshold, int seconds = 10, PunishmentAction action = PunishmentAction.Mute, StoopidTime punishTime = null) { if (action == PunishmentAction.AddRole) { await ReplyErrorLocalizedAsync("punishment_unsupported", action); return; } if (userThreshold < 2 || userThreshold > 30) { await ReplyErrorLocalizedAsync("raid_cnt", 2, 30).ConfigureAwait(false); return; } if (seconds < 2 || seconds > 300) { await ReplyErrorLocalizedAsync("raid_time", 2, 300).ConfigureAwait(false); return; } if (!(punishTime is null)) { if (!_service.IsDurationAllowed(action)) { await ReplyErrorLocalizedAsync("prot_cant_use_time"); } } var time = (int?)punishTime?.Time.TotalMinutes ?? 0; if (time < 0 || time > 60 * 24) { return; } var stats = await _service.StartAntiRaidAsync(ctx.Guild.Id, userThreshold, seconds, action, time).ConfigureAwait(false); if (stats == null) { return; } await ctx.Channel.SendConfirmAsync(GetText("prot_enable", "Anti-Raid"), $"{ctx.User.Mention} {GetAntiRaidString(stats)}") .ConfigureAwait(false); }
public async Task AntiAlt(StoopidTime minAge, PunishmentAction action, [Leftover] StoopidTime punishTime = null) { var minAgeMinutes = (int)minAge.Time.TotalMinutes; var punishTimeMinutes = (int?)punishTime?.Time.TotalMinutes ?? 0; if (minAgeMinutes < 1 || punishTimeMinutes < 0) { return; } await _service.StartAntiAltAsync(ctx.Guild.Id, minAgeMinutes, action, (int?)punishTime?.Time.TotalMinutes ?? 0); await ctx.OkAsync(); }
public bool IsDurationAllowed(PunishmentAction action) { switch (action) { case PunishmentAction.Ban: case PunishmentAction.Mute: case PunishmentAction.ChatMute: case PunishmentAction.VoiceMute: case PunishmentAction.AddRole: return(true); default: return(false); } }
private async Task PunishUsers(PunishmentAction action, IRole muteRole, ProtectionType pt, params IGuildUser[] gus) { foreach (var gu in gus) { switch (action) { case PunishmentAction.Mute: try { await gu.AddRolesAsync(muteRole); } catch (Exception ex) { _log.Warn(ex, "I can't apply punishement"); } break; case PunishmentAction.Kick: try { await gu.Guild.AddBanAsync(gu, 7); try { await gu.Guild.RemoveBanAsync(gu); } catch { await gu.Guild.RemoveBanAsync(gu); // try it twice, really don't want to ban user if // only kick has been specified as the punishement } } catch (Exception ex) { _log.Warn(ex, "I can't apply punishment"); } break; case PunishmentAction.Ban: try { await gu.Guild.AddBanAsync(gu, 7); } catch (Exception ex) { _log.Warn(ex, "I can't apply punishment"); } break; default: break; } } await LogCommands.TriggeredAntiProtection(gus, action, pt).ConfigureAwait(false); }
public async Task AntiSpam(int messageCount, PunishmentAction action = PunishmentAction.Mute, int time = 0) { if (messageCount < 2 || messageCount > 10) { return; } if (time < 0 || time > 60 * 60 * 12) { return; } var stats = await _service.StartAntiSpamAsync(Context.Guild.Id, messageCount, time, action).ConfigureAwait(false); await Context.Channel.SendConfirmAsync(GetText("prot_enable", "Anti-Spam"), $"{Context.User.Mention} {GetAntiSpamString(stats)}").ConfigureAwait(false); }
public async Task WarnPunish(int numberOfWarns, PunishmentAction punish, int time = 0) { if ((punish == PunishmentAction.Mute || time == 0) && numberOfWarns > 0) { var warnPunishments = uow.GuildConfigs.For(Context.Guild.Id, set => set.Include(x => x.WarnPunishments)).WarnPunishments; warnPunishments.RemoveAll(x => x.Count == numberOfWarns); warnPunishments.Add(new WarningPunishment { Count = numberOfWarns, Punishment = punish, Time = time, }); uow.SaveChanges(false); await ConfirmLocalized("userpunish_warnpunish_warn_punish_set", Format.Bold(punish.ToString()), Format.Bold(numberOfWarns.ToString())).ConfigureAwait(false); } }
public async Task StartAntiAltAsync(ulong guildId, int minAgeMinutes, PunishmentAction action, int actionDurationMinutes = 0, ulong?roleId = null) { using var uow = _db.GetDbContext(); var gc = uow.GuildConfigs.ForId(guildId, set => set.Include(x => x.AntiAltSetting)); gc.AntiAltSetting = new AntiAltSetting() { Action = action, ActionDurationMinutes = actionDurationMinutes, MinAge = TimeSpan.FromMinutes(minAgeMinutes), RoleId = roleId, }; await uow.SaveChangesAsync(); _antiAltGuilds[guildId] = new AntiAltStats(gc.AntiAltSetting); }
public async Task ExecuteGroupAsync(CommandContext ctx, [Description("desc-enable")] bool enable, [Description("desc-sens")] short sens, [Description("desc-punish-action")] PunishmentAction action = PunishmentAction.Kick, [Description("desc-cooldown")] TimeSpan?cooldown = null) { if (sens is < AntifloodSettings.MinSensitivity or > AntifloodSettings.MaxSensitivity) { throw new CommandFailedException(ctx, "cmd-err-range-sens", AntifloodSettings.MinSensitivity, AntifloodSettings.MaxSensitivity); } cooldown ??= TimeSpan.FromSeconds(10); if (cooldown.Value.TotalSeconds is < AntifloodSettings.MinCooldown or > AntifloodSettings.MaxCooldown) { throw new CommandFailedException(ctx, "cmd-err-range-cd", AntifloodSettings.MinCooldown, AntifloodSettings.MaxCooldown); } var settings = new AntifloodSettings { Action = action, Cooldown = (short)cooldown.Value.TotalSeconds, Enabled = enable, Sensitivity = sens }; await ctx.Services.GetRequiredService <GuildConfigService>().ModifyConfigAsync(ctx.Guild.Id, gcfg => gcfg.AntifloodSettings = settings); await ctx.GuildLogAsync(emb => { emb.WithLocalizedTitle("evt-cfg-upd"); emb.WithColor(this.ModuleColor); if (enable) { emb.WithLocalizedDescription("evt-af-enable"); emb.AddLocalizedTitleField("str-sensitivity", settings.Sensitivity, inline: true); emb.AddLocalizedTitleField("str-cooldown", settings.Cooldown, inline: true); emb.AddLocalizedTitleField("str-punish-action", settings.Action.Humanize(), inline: true); } else { emb.WithLocalizedDescription("evt-af-disable"); } }); await ctx.InfoAsync(this.ModuleColor, enable? "evt-af-enable" : "evt-af-disable"); }
public async Task AntiRaid(int userThreshold, int seconds, PunishmentAction action) { if (userThreshold < 2 || userThreshold > 30) { await Context.Channel.SendErrorAsync("❗️User threshold must be between **2** and **30**.").ConfigureAwait(false); return; } if (seconds < 2 || seconds > 300) { await Context.Channel.SendErrorAsync("❗️Time must be between **2** and **300** seconds.").ConfigureAwait(false); return; } try { await MuteCommands.GetMuteRole(Context.Guild).ConfigureAwait(false); } catch (Exception ex) { await Context.Channel.SendConfirmAsync("⚠️ Failed creating a mute role. Give me ManageRoles permission" + "or create 'nadeko-mute' role with disabled SendMessages and try again.") .ConfigureAwait(false); _log.Warn(ex); return; } var setting = new AntiRaidSetting() { Action = action, Seconds = seconds, UserThreshold = userThreshold, }; antiRaidGuilds.AddOrUpdate(Context.Guild.Id, setting, (id, old) => setting); await Context.Channel.SendConfirmAsync($"ℹ️ {Context.User.Mention} If **{userThreshold}** or more users join within **{seconds}** seconds, I will **{action}** them.") .ConfigureAwait(false); }
public async Task AntiSpam(int messageCount, PunishmentAction action = PunishmentAction.Mute, int time = 0) { if (messageCount < 2 || messageCount > 10) { return; } if (time < 0 || time > 60 * 12) { return; } try { await _mute.GetMuteRole(Context.Guild).ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); await ReplyErrorLocalized("prot_error").ConfigureAwait(false); return; } var gc = uow.GuildConfigs.For(Context.Guild.Id, set => set.Include(x => x.AntiSpamSetting)); if (gc.AntiSpamSetting != null) { gc.AntiSpamSetting.Action = action; gc.AntiSpamSetting.MessageThreshold = messageCount; gc.AntiSpamSetting.MuteTime = time; } else { gc.AntiSpamSetting = new AntiSpamSetting { Action = action, MessageThreshold = messageCount, MuteTime = time, }; } await uow.SaveChangesAsync(false).ConfigureAwait(false); await Context.Channel.SendConfirmAsync($"{Context.User.Mention} {GetAntiSpamString(gc.AntiSpamSetting)}", GetText("prot_enable", "Anti-Spam")).ConfigureAwait(false); }
public static async Task TriggeredAntiProtection(IGuildUser[] users, PunishmentAction action, ProtectionType protection) { if (users.Length == 0) { return; } LogSetting logSetting; if (!GuildLogSettings.TryGetValue(users.First().Guild.Id, out logSetting) || !logSetting.IsLogging) { return; } ITextChannel logChannel; if ((logChannel = TryGetLogChannel(users.First().Guild, logSetting)) == null) { return; } var punishment = ""; if (action == PunishmentAction.Mute) { punishment = "🔇 MUTED"; //punishment = "MUTED"; } else if (action == PunishmentAction.Kick) { punishment = "☣ SOFT-BANNED (KICKED)"; //punishment = "KICKED"; } else if (action == PunishmentAction.Ban) { punishment = "⛔️ BANNED"; //punishment = "BANNED"; } await logChannel.SendMessageAsync(String.Join("\n", users.Select(user => $"‼️ {Format.Bold(user.ToString())} got **{punishment}** due to __**{protection}**__ protection on **{user.Guild.Name}** server."))) //await logChannel.SendMessageAsync(String.Join("\n",users.Select(user=>$"{Format.Bold(user.ToString())} was **{punishment}** due to `{protection}` protection on **{user.Guild.Name}** server."))) .ConfigureAwait(false); }
public async Task AntiSpam(IUserMessage imsg, int messageCount = 3, PunishmentAction action = PunishmentAction.Mute) { var channel = (ITextChannel)imsg.Channel; if (messageCount < 2 || messageCount > 10) { return; } AntiSpamSetting throwaway; if (antiSpamGuilds.TryRemove(channel.Guild.Id, out throwaway)) { await channel.SendMessageAsync("🆗 **Anti-Spam feature** has been **disabled** on this server.").ConfigureAwait(false); } else { try { await GetMuteRole(channel.Guild).ConfigureAwait(false); } catch (Exception ex) { await channel.SendMessageAsync("⚠️ Failed creating a mute role. Give me ManageRoles permission" + "or create 'nadeko-mute' role with disabled SendMessages and try again.") .ConfigureAwait(false); _log.Warn(ex); return; } if (antiSpamGuilds.TryAdd(channel.Guild.Id, new AntiSpamSetting() { Action = action, MessageThreshold = messageCount, })) { await channel.SendMessageAsync("✅ **Anti-Spam feature** has been **enabled** on this server.").ConfigureAwait(false); } } }
public async Task AntiRaid(int userThreshold, int seconds = 10, PunishmentAction action = PunishmentAction.Mute) { if (userThreshold < 2 || userThreshold > 30) { await ReplyErrorLocalizedAsync("raid_cnt", 2, 30).ConfigureAwait(false); return; } if (seconds < 2 || seconds > 300) { await ReplyErrorLocalizedAsync("raid_time", 2, 300).ConfigureAwait(false); return; } var stats = await _service.StartAntiRaidAsync(Context.Guild.Id, userThreshold, seconds, action).ConfigureAwait(false); await Context.Channel.SendConfirmAsync(GetText("prot_enable", "Anti-Raid"), $"{Context.User.Mention} {GetAntiRaidString(stats)}") .ConfigureAwait(false); }
public async Task AntiRaid(IUserMessage imsg, int userThreshold, int seconds, PunishmentAction action) { var channel = (ITextChannel)imsg.Channel; if (userThreshold < 2 || userThreshold > 30) { await channel.SendMessageAsync("❗️User threshold must be between **2** and **30**.").ConfigureAwait(false); return; } if (seconds < 2 || seconds > 300) { await channel.SendMessageAsync("❗️Time must be between **2** and **300** seconds.").ConfigureAwait(false); return; } try { await GetMuteRole(channel.Guild).ConfigureAwait(false); } catch (Exception ex) { await channel.SendMessageAsync("⚠️ Failed creating a mute role. Give me ManageRoles permission" + "or create 'nadeko-mute' role with disabled SendMessages and try again.") .ConfigureAwait(false); _log.Warn(ex); return; } var setting = new AntiRaidSetting() { Action = action, Seconds = seconds, UserThreshold = userThreshold, }; antiRaidGuilds.AddOrUpdate(channel.Guild.Id, setting, (id, old) => setting); await channel.SendMessageAsync($"ℹ️ {imsg.Author.Mention} If **{userThreshold}** or more users join within **{seconds}** seconds, I will **{action}** them.") .ConfigureAwait(false); }
public async Task AntiSpam(IUserMessage imsg, int messageCount=3, PunishmentAction action = PunishmentAction.Mute) { var channel = (ITextChannel)imsg.Channel; if (messageCount < 2 || messageCount > 10) return; AntiSpamSetting throwaway; if (antiSpamGuilds.TryRemove(channel.Guild.Id, out throwaway)) { await channel.SendMessageAsync("🆗 **Anti-Spam feature** has been **disabled** on this server.").ConfigureAwait(false); } else { try { await GetMuteRole(channel.Guild).ConfigureAwait(false); } catch (Exception ex) { await channel.SendMessageAsync("⚠️ Failed creating a mute role. Give me ManageRoles permission" + "or create 'nadeko-mute' role with disabled SendMessages and try again.") .ConfigureAwait(false); _log.Warn(ex); return; } if (antiSpamGuilds.TryAdd(channel.Guild.Id, new AntiSpamSetting() { Action = action, MessageThreshold = messageCount, })) await channel.SendMessageAsync("✅ **Anti-Spam feature** has been **enabled** on this server.").ConfigureAwait(false); } }