Пример #1
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));
Пример #2
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)));
Пример #3
0
            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);
                }
            }
Пример #4
0
 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));