private void RemoveIdFromWhitelistForModule(GuildAccount guild, ModuleInfo module, ulong id, bool isChannel) { for (int i = 0; i < module.Commands.Count; i++) { var cmd = module.Commands[i]; guild.RemoveFromWhitelist(_commands.FormatCommandName(cmd), id, isChannel); } for (int i = 0; i < module.Submodules.Count; i++) { RemoveIdFromWhitelistForModule(guild, module.Submodules[i], id, isChannel); } }
public void DisableGuildCommandOrModule(GuildAccount guild, string input) { var result = _commands.AdvancedSearch(input); if (result.Key is null) { guild.DisableCommand(_commands.FormatCommandName(result.Value)); } else { DisableEntireModuleInGuild(guild, result.Key); } }
private void DisableWhitelistForModule(GuildAccount guild, ModuleInfo module, bool isChannel) { for (int i = 0; i < module.Commands.Count; i++) { var cmd = module.Commands[i]; guild.DisableWhitelist(_commands.FormatCommandName(cmd), isChannel); } for (int i = 0; i < module.Submodules.Count; i++) { DisableWhitelistForModule(guild, module.Submodules[i], isChannel); } }
private void DisableEntireModuleInGuild(GuildAccount guild, ModuleInfo module) { for (int i = 0; i < module.Commands.Count; i++) { var cmd = module.Commands[i]; guild.DisableCommand(_commands.FormatCommandName(cmd)); } for (int i = 0; i < module.Submodules.Count; i++) { DisableEntireModuleInGuild(guild, module.Submodules[i]); } }
public void AddIdToWhitelistForCommandOrModule(GuildAccount guild, string input, ulong id, bool isChannel) { var result = _commands.AdvancedSearch(input); if (result.Key is null) { guild.AddToWhitelist(_commands.FormatCommandName(result.Value), id, isChannel); } else { AddIdToWhitelistForModule(guild, result.Key, id, isChannel); } }
internal void ToggleDeleteMessageForCommandOrModule(GuildAccount guild, string input) { var result = _commands.AdvancedSearch(input); if (result.Key is null) { guild.ToggleDeleteMsgOnCommand(_commands.FormatCommandName(result.Value)); } else { ToggleDeleteMessageForModule(guild, result.Key); } }
private async Task <AutoModInfraction> AddAutoModInfractionToGuild(GuildAccount guild, ulong userId, AutoModInfractionType type, string trigger = "") { var infraction = guild.AddAutoModInfractionToGuild(userId, type, trigger); if (guild.AutoMod.LogChannelId != 0) { var channel = _client.GetChannel(guild.AutoMod.LogChannelId) as ITextChannel; var embed = await GetMessageEmbedForLogAsync(infraction); await channel.SendMessageAsync("", false, embed); } return(infraction); }
public async Task HandleMessageReceivedChecksAsync(GuildAccount guild, IMessage message) { if (message.Author.IsBot) { return; } if (!UserCanBypass(message.Author as IGuildUser, message.Channel.Id, guild.AutoMod.BlacklistedWordsSettings.WhitelistedRoles, guild.AutoMod.BlacklistedWordsSettings.WhitelistedChannels) && MessageContainsBlacklistedWords(guild.AutoMod, message.Content.ToLower(), out string trigger)) { await AddAutoModInfractionToGuild(guild, message.Author.Id, AutoModInfractionType.BlacklistedWords, trigger); await message.DeleteAsync(); } else if (!UserCanBypass(message.Author as IGuildUser, message.Channel.Id, guild.AutoMod.SpamSettings.WhitelistedRoles, guild.AutoMod.SpamSettings.WhitelistedChannels) && UserIsSpamming(guild, message.Author.Id, message.Timestamp)) { await AddAutoModInfractionToGuild(guild, message.Author.Id, AutoModInfractionType.Spam, $"<#{message.Channel.Id}>"); var messages = await message.Channel.GetMessagesAsync(10).FlattenAsync(); messages = messages.Where(x => x.Author.Id == message.Author.Id).Take(5); await((ITextChannel)message.Channel).DeleteMessagesAsync(messages); var violations = guild.AutoModInfractions.Count(x => x.InfractionerId == message.Author.Id && x.Type == AutoModInfractionType.Spam); if (violations >= 3) { _guilds.SaveGuildAccount(guild); _moderation.MuteUser(message.Author as IGuildUser, _client.CurrentUser.Id, new TimeSpan(0, 1, 0, 0, 0), $"Spam Automod violation #{violations}"); return; } } else if (message.MentionedUserIds.Count >= 5) { await AddAutoModInfractionToGuild(guild, message.Author.Id, AutoModInfractionType.MassMention, $"<#{message.Channel.Id}>"); _guilds.SaveGuildAccount(guild); _moderation.MuteUser(message.Author as IGuildUser, _client.CurrentUser.Id, new TimeSpan(0, 1, 30, 0, 0), "Mass mention Automod violation."); return; } _guilds.SaveGuildAccount(guild); }
private bool CommandIsAllowedToRun(GuildAccount guild) { var currentCommand = guild.Commands.Find(x => x.Name == ExpandedCommandName); // If command doesn't exist in database, recreate it. if (currentCommand == null) { guild.AddNewCommand(_currentCommand); } Accounts.SaveGuildAccount(guild); currentCommand = guild.Commands.Find(x => x.Name == ExpandedCommandName); var userRoles = (Context.User as SocketGuildUser).Roles.ToList(); if (!currentCommand.IsEnabled) { return(false); } if (userRoles.Find(x => x.Id == guild.ModRoleId) != null) { return(true); } var userHasRoleInList = UserHasRoleInList(currentCommand); if (currentCommand.RolesListIsBlacklist && userHasRoleInList || !currentCommand.RolesListIsBlacklist && !userHasRoleInList) { return(false); } var channelIsInList = currentCommand.WhitelistedChannels.Contains(Context.Channel.Id); if (currentCommand.ChannelListIsBlacklist && channelIsInList || !currentCommand.ChannelListIsBlacklist && !channelIsInList) { return(false); } return(true); }
public static string ChangeLanguage(GuildAccount guildAccount, string language) { if (language == "polish" || language == "polski") { guildAccount.ConfigLang = "Texts/pl_PL.json"; GuildAccounts.SaveGuilds(); return("polish"); } else if (language == "english") { guildAccount.ConfigLang = "Texts/en_US.json"; GuildAccounts.SaveGuilds(); return("english"); } else { return(null); } }
private Infraction AddInfractionToGuild(ulong userId, ulong modId, InfractionType type, DateTime?endsAt, string reason, GuildAccount guild) { var infraction = guild.AddInfractionToGuild(userId, modId, type, endsAt, reason); if (guild.ModLogsChannelId != 0) { var channel = _client.GetChannel(guild.ModLogsChannelId) as ITextChannel; var embed = GetMessageEmbedForLog(infraction); channel.SendMessageAsync("", false, embed).GetAwaiter().GetResult(); } return(infraction); }