public async Task SaveAsync()
        {
            if (BlacklistedUsers != null && BlacklistedUsers.Any())
            {
                await SaveListToFile(Common.BlackListFile, BlacklistedUsers).ConfigureAwait(false);
            }

            if (TrustedUsers != null && TrustedUsers.Any())
            {
                await SaveListToFile(Common.TrustedListFile, TrustedUsers).ConfigureAwait(false);
            }

            Toml.WriteFile(this, Common.SettingsFile);
        }
Beispiel #2
0
 public Task <bool> TryBlockEarly(IGuild guild, IUserMessage usrMsg)
 => Task.FromResult((guild != null && BlacklistedGuilds.Contains(guild.Id)) ||
                    BlacklistedChannels.Contains(usrMsg.Channel.Id) ||
                    BlacklistedUsers.Contains(usrMsg.Author.Id));
            private async Task Blacklist(AddRemove action, ulong id, BlacklistType type)
            {
                using (var uow = DbHandler.UnitOfWork())
                {
                    if (action == AddRemove.Add)
                    {
                        var item = new BlacklistItem {
                            ItemId = (long)id, Type = type
                        };
                        uow.BotConfig.GetOrCreate().Blacklist.Add(item);
                        if (type == BlacklistType.Server)
                        {
                            BlacklistedGuilds.Add((long)id);
                        }
                        else if (type == BlacklistType.Channel)
                        {
                            BlacklistedChannels.Add((long)id);
                        }
                        else if (type == BlacklistType.User)
                        {
                            BlacklistedUsers.Add((long)id);
                        }
                    }
                    else
                    {
                        uow.BotConfig.GetOrCreate().Blacklist.RemoveWhere(bi => bi.ItemId == (long)id && bi.Type == type);
                        if (type == BlacklistType.Server)
                        {
                            BlacklistedGuilds.TryRemove((long)id);
                        }
                        else if (type == BlacklistType.Channel)
                        {
                            BlacklistedChannels.TryRemove((long)id);
                        }
                        else if (type == BlacklistType.User)
                        {
                            BlacklistedUsers.TryRemove((long)id);
                        }
                    }
                    await uow.CompleteAsync().ConfigureAwait(false);
                }
                if (action == AddRemove.Add)
                {
                    TriviaGame tg;
                    switch (type)
                    {
                    case BlacklistType.Server:
                        Games.Games.TriviaCommands.RunningTrivias.TryRemove(id, out tg);
                        if (tg != null)
                        {
                            await tg.StopGame().ConfigureAwait(false);
                        }
                        break;

                    case BlacklistType.Channel:
                        var item = Games.Games.TriviaCommands.RunningTrivias.FirstOrDefault(kvp => kvp.Value.Channel.Id == id);
                        Games.Games.TriviaCommands.RunningTrivias.TryRemove(item.Key, out tg);
                        if (tg != null)
                        {
                            await tg.StopGame().ConfigureAwait(false);
                        }
                        break;

                    case BlacklistType.User:
                        break;
                    }
                }

                if (action == AddRemove.Add)
                {
                    await ReplyConfirmLocalized("blacklisted", Format.Code(type.ToString()), Format.Code(id.ToString())).ConfigureAwait(false);
                }
                else
                {
                    await ReplyConfirmLocalized("unblacklisted", Format.Code(type.ToString()), Format.Code(id.ToString())).ConfigureAwait(false);
                }
            }
Beispiel #4
0
 public Task <bool> TryBlockEarly(IGuild guild, IUserMessage userMessage, bool realExecution = true)
 => Task.FromResult(!_creds.IsOwner(userMessage.Author) && (guild != null && BlacklistedGuilds.Contains(guild.Id) || BlacklistedChannels.Contains(userMessage.Channel.Id) || BlacklistedUsers.Contains(userMessage.Author.Id)));
 public Task <bool> RunBehavior(DiscordSocketClient _, IGuild guild, IUserMessage usrMsg)
 => Task.FromResult((guild != null && BlacklistedGuilds.Contains(guild.Id)) ||
                    BlacklistedChannels.Contains(usrMsg.Channel.Id) ||
                    BlacklistedUsers.Contains(usrMsg.Author.Id));