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; } IRole muteRole; try { muteRole = 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, MuteRole = muteRole, }; 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 AntiRaid(IUserMessage imsg, int userThreshold, int seconds, PunishmentAction action) { var channel = (ITextChannel)imsg.Channel; if (userThreshold < 2 || userThreshold > 30) { await channel.SendErrorAsync("❗️User threshold must be between **2** and **30**.").ConfigureAwait(false); return; } if (seconds < 2 || seconds > 300) { await channel.SendErrorAsync("❗️Time must be between **2** and **300** seconds.").ConfigureAwait(false); return; } try { await MuteCommands.GetMuteRole(channel.Guild).ConfigureAwait(false); } catch (Exception ex) { await 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(channel.Guild.Id, setting, (id, old) => setting); await channel.SendConfirmAsync($"ℹ️ {imsg.Author.Mention} If **{userThreshold}** or more users join within **{seconds}** seconds, I will **{action}** them.") .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); }
private string GetAntiRaidString(AntiRaidSetting antiRaidSettings) => GetText("raid_stats", Format.Bold(antiRaidSettings.UserThreshold.ToString()), Format.Bold(antiRaidSettings.Seconds.ToString()), Format.Bold(antiRaidSettings.Action.ToString()));