public async Task AntispamIgnore() { var channel = (ITextChannel)Context.Channel; var obj = new AntiSpamIgnore() { ChannelId = channel.Id }; bool added; using (var uow = DbHandler.UnitOfWork()) { var gc = uow.GuildConfigs.For(Context.Guild.Id, set => set.Include(x => x.AntiSpamSetting).ThenInclude(x => x.IgnoredChannels)); var spam = gc.AntiSpamSetting; if (spam == null) { return; } if (spam.IgnoredChannels.Add(obj)) { AntiSpamStats temp; if (antiSpamGuilds.TryGetValue(Context.Guild.Id, out temp)) { temp.AntiSpamSettings.IgnoredChannels.Add(obj); } added = true; } else { spam.IgnoredChannels.Remove(obj); AntiSpamStats temp; if (antiSpamGuilds.TryGetValue(Context.Guild.Id, out temp)) { temp.AntiSpamSettings.IgnoredChannels.Remove(obj); } added = false; } await uow.CompleteAsync().ConfigureAwait(false); } if (added) { await Context.Channel.SendConfirmAsync("Anti-Spam will ignore this channel.").ConfigureAwait(false); } else { await Context.Channel.SendConfirmAsync("Anti-Spam will no longer ignore this channel.").ConfigureAwait(false); } }
public async Task AntispamIgnore() { var channel = (ITextChannel)Context.Channel; var obj = new AntiSpamIgnore() { ChannelId = channel.Id }; bool added; using (var uow = _db.UnitOfWork) { var gc = uow.GuildConfigs.For(Context.Guild.Id, set => set.Include(x => x.AntiSpamSetting).ThenInclude(x => x.IgnoredChannels)); var spam = gc.AntiSpamSetting; if (spam == null) { return; } if (spam.IgnoredChannels.Add(obj)) { AntiSpamStats temp; if (_service.AntiSpamGuilds.TryGetValue(Context.Guild.Id, out temp)) { temp.AntiSpamSettings.IgnoredChannels.Add(obj); } added = true; } else { spam.IgnoredChannels.Remove(obj); AntiSpamStats temp; if (_service.AntiSpamGuilds.TryGetValue(Context.Guild.Id, out temp)) { temp.AntiSpamSettings.IgnoredChannels.Remove(obj); } added = false; } await uow.CompleteAsync().ConfigureAwait(false); } if (added) { await ReplyConfirmLocalized("spam_ignore", "Anti-Spam").ConfigureAwait(false); } else { await ReplyConfirmLocalized("spam_not_ignore", "Anti-Spam").ConfigureAwait(false); } }
public async Task <bool?> AntiSpamIgnoreAsync(ulong guildId, ulong channelId) { var obj = new AntiSpamIgnore() { ChannelId = channelId }; bool added; using (var uow = _db.UnitOfWork) { var gc = uow.GuildConfigs.ForId(guildId, set => set.Include(x => x.AntiSpamSetting).ThenInclude(x => x.IgnoredChannels)); var spam = gc.AntiSpamSetting; if (spam is null) { return(null); } if (spam.IgnoredChannels.Add(obj)) // if adding to db is successful { if (_antiSpamGuilds.TryGetValue(guildId, out var temp)) { temp.AntiSpamSettings.IgnoredChannels.Add(obj); // add to local cache } added = true; } else { var toRemove = spam.IgnoredChannels.First(x => x.ChannelId == channelId); uow._context.Set <AntiSpamIgnore>().Remove(toRemove); // remove from db if (_antiSpamGuilds.TryGetValue(guildId, out var temp)) { temp.AntiSpamSettings.IgnoredChannels.Remove(toRemove); // remove from local cache } added = false; } await uow.CompleteAsync().ConfigureAwait(false); } return(added); }
public async Task <bool> AntiSpamIgnoreAsync(ulong guildId, ulong channelId) { var obj = new AntiSpamIgnore() { ChannelId = channelId }; bool added; using (var uow = _db.UnitOfWork) { var gc = uow.GuildConfigs.For(guildId, set => set.Include(x => x.AntiSpamSetting).ThenInclude(x => x.IgnoredChannels)); var spam = gc.AntiSpamSetting; if (spam == null) { return(false); } if (spam.IgnoredChannels.Add(obj)) { if (_antiSpamGuilds.TryGetValue(guildId, out var temp)) { temp.AntiSpamSettings.IgnoredChannels.Add(obj); } added = true; } else { spam.IgnoredChannels.Remove(obj); if (_antiSpamGuilds.TryGetValue(guildId, out var temp)) { temp.AntiSpamSettings.IgnoredChannels.Remove(obj); } added = false; } await uow.CompleteAsync().ConfigureAwait(false); } return(added); }