Exemplo n.º 1
0
            public async Task StreamRoleBlacklist(AddRemove action, [Remainder] IGuildUser user)
            {
                var success = await this.Service.ApplyListAction(StreamRoleListType.Blacklist, Context.Guild, action, user.Id, user.ToString())
                              .ConfigureAwait(false);

                if (action == AddRemove.Add)
                {
                    if (success)
                    {
                        await ReplyConfirmLocalized("stream_role_bl_add", Format.Bold(user.ToString())).ConfigureAwait(false);
                    }
                    else
                    {
                        await ReplyConfirmLocalized("stream_role_bl_add_fail", Format.Bold(user.ToString())).ConfigureAwait(false);
                    }
                }
                else
                if (success)
                {
                    await ReplyConfirmLocalized("stream_role_bl_rem", Format.Bold(user.ToString())).ConfigureAwait(false);
                }
                else
                {
                    await ReplyErrorLocalized("stream_role_bl_rem_fail", Format.Bold(user.ToString())).ConfigureAwait(false);
                }
            }
Exemplo n.º 2
0
            public async Task StreamRoleWhitelist(AddRemove action, [Leftover] IGuildUser user)
            {
                var success = await this._service.ApplyListAction(StreamRoleListType.Whitelist, ctx.Guild, action, user.Id, user.ToString())
                              .ConfigureAwait(false);

                if (action == AddRemove.Add)
                {
                    if (success)
                    {
                        await ReplyConfirmLocalizedAsync("stream_role_wl_add", Format.Bold(user.ToString())).ConfigureAwait(false);
                    }
                    else
                    {
                        await ReplyConfirmLocalizedAsync("stream_role_wl_add_fail", Format.Bold(user.ToString())).ConfigureAwait(false);
                    }
                }
                else
                if (success)
                {
                    await ReplyConfirmLocalizedAsync("stream_role_wl_rem", Format.Bold(user.ToString())).ConfigureAwait(false);
                }
                else
                {
                    await ReplyErrorLocalizedAsync("stream_role_wl_rem_fail", Format.Bold(user.ToString())).ConfigureAwait(false);
                }
            }
Exemplo n.º 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 = id, Type = type
                        };
                        uow.BotConfig.GetOrCreate().Blacklist.Add(item);
                        BlacklistedItems.Add(item);
                    }
                    else
                    {
                        uow.BotConfig.GetOrCreate().Blacklist.RemoveWhere(bi => bi.ItemId == id && bi.Type == type);
                        BlacklistedItems.RemoveWhere(bi => bi.ItemId == id && bi.Type == type);
                    }
                    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;

                    default:
                        break;
                    }
                }

                if (action == AddRemove.Add)
                {
                    await Context.Channel.SendConfirmAsync($"Blacklisted a `{type}` with id `{id}`").ConfigureAwait(false);
                }
                else
                {
                    await Context.Channel.SendConfirmAsync($"Unblacklisted a `{type}` with id `{id}`").ConfigureAwait(false);
                }
            }
Exemplo n.º 4
0
            private async Task Blacklist(AddRemove action, ulong id, BlacklistType type)
            {
                if (action == AddRemove.Add && _creds.OwnerIds.Contains(id))
                {
                    return;
                }

                using (var uow = _db.UnitOfWork)
                {
                    if (action == AddRemove.Add)
                    {
                        var item = new BlacklistItem {
                            ItemId = id, Type = type
                        };
                        uow.BotConfig.GetOrCreate().Blacklist.Add(item);
                        if (type == BlacklistType.Server)
                        {
                            BlacklistedGuilds.Add(id);
                        }
                        else if (type == BlacklistType.Channel)
                        {
                            BlacklistedChannels.Add(id);
                        }
                        else if (type == BlacklistType.User)
                        {
                            BlacklistedUsers.Add(id);
                        }
                    }
                    else
                    {
                        uow.BotConfig.GetOrCreate().Blacklist.RemoveWhere(bi => bi.ItemId == id && bi.Type == type);
                        if (type == BlacklistType.Server)
                        {
                            BlacklistedGuilds.TryRemove(id);
                        }
                        else if (type == BlacklistType.Channel)
                        {
                            BlacklistedChannels.TryRemove(id);
                        }
                        else if (type == BlacklistType.User)
                        {
                            BlacklistedUsers.TryRemove(id);
                        }
                    }
                    await uow.CompleteAsync().ConfigureAwait(false);
                }

                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);
                }
            }
Exemplo n.º 5
0
        private string AddRemoveLastChar(string text, char lchar, AddRemove ar)
        {
            if (ar == AddRemove.Add && text.Last <char>() != lchar)
            {
                text += lchar;
            }
            else if (ar == AddRemove.Remove && text.Last <char>() == lchar)
            {
                text = text.Remove(text.Length - 1);
            }

            return(text);
        }
Exemplo n.º 6
0
            private async Task Blacklist(IUserMessage imsg, AddRemove action, ulong id, BlacklistType type)
            {
                var channel = imsg.Channel;

                using (var uow = DbHandler.UnitOfWork())
                {
                    if (action == AddRemove.Add)
                    {
                        var item = new BlacklistItem { ItemId = id, Type = type };
                        uow.BotConfig.GetOrCreate().Blacklist.Add(item);
                        BlacklistedItems.Add(item);
                    }
                    else
                    {
                        uow.BotConfig.GetOrCreate().Blacklist.RemoveWhere(bi => bi.ItemId == id && bi.Type == type);
                        BlacklistedItems.RemoveWhere(bi => bi.ItemId == id && bi.Type == type);
                    }
                    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;
                        default:
                            break;
                    }

                }

                await channel.SendMessageAsync(":ok:").ConfigureAwait(false);
            }
Exemplo n.º 7
0
        public static MbccBeerDiff FromBeer(MbccBeer beer, AddRemove action, DateTime changed)
        {
            var diff = new MbccBeerDiff
            {
                BreweryName = beer.BreweryName,
                BeerName    = beer.BeerName,
                ABV         = beer.ABV,
                Style       = beer.Style,
                Session     = beer.Session,
                Action      = action,
                Changed     = changed
            };

            return(diff);
        }
            private async Task Blacklist(AddRemove action, ulong id, BlacklistType type)
            {
                if (action == AddRemove.Add)
                {
                    uow.BotConfig.GetOrCreate().Blacklist.Add(new BlacklistItem {
                        ItemId = id,
                        Type   = type,
                    });
                }
                else
                {
                    uow.BotConfig.GetOrCreate().Blacklist.RemoveWhere(bi => bi.ItemId == id && bi.Type == type);
                }
                await uow.SaveChangesAsync(false).ConfigureAwait(false);

                await ReplyConfirmLocalized(action == AddRemove.Add? "blacklisted" : "unblacklisted", Format.Code(type.ToString()), Format.Code(id.ToString())).ConfigureAwait(false);
            }
Exemplo n.º 9
0
        public async Task EditFilterCommandAsync(CommandContext ctx,
                                                 [Description("Name of the filter.")]
                                                 string filterName,

                                                 [Description("Add or Remove words from the filter.")]
                                                 AddRemove operation,

                                                 [Description("Words to add or remove")]
                                                 params string[] words)
        {
            var name = filterName.ToLower();

            var filter = await this._model.FindAsync <GuildFilters>(ctx.Guild.Id);

            if (filter is null || !filter.Filters.TryGetValue(name, out var filterData))
            {
                await RespondBasicErrorAsync("Filter does not exist");

                return;
            }

            HashSet <string> editWords   = words.Where(x => GuildFilters.regex.IsMatch(x)).ToHashSet();
            HashSet <string> filterWords = filterData.Item2;

            switch (operation)
            {
            case AddRemove.Add:
                filterWords.UnionWith(editWords);
                break;

            case AddRemove.Remove:
                filterWords.ExceptWith(editWords);
                break;
            }

            this._model.Update(filter);
            filter.Filters[name] = new Tuple <int, HashSet <string> >(filterData.Item1, filterWords);
            await this._model.SaveChangesAsync();

            await RespondBasicSuccessAsync($"Edited filter {name}, the filter now contains the words:\n" +
                                           $"`{string.Join("`, `", filterWords)}`");
        }
Exemplo n.º 10
0
        public async Task XpRoleReward(int level, AddRemove action, [Leftover] IRole role)
        {
            if (level < 1)
            {
                return;
            }

            _service.SetRoleReward(ctx.Guild.Id, level, role.Id, action == AddRemove.Remove);
            if (action == AddRemove.Add)
            {
                await ReplyConfirmLocalizedAsync("xp_role_reward_add_role",
                                                 level,
                                                 Format.Bold(role.ToString()));
            }
            else
            {
                await ReplyConfirmLocalizedAsync("xp_role_reward_remove_role",
                                                 Format.Bold(level.ToString()),
                                                 Format.Bold(role.ToString()));
            }
        }
Exemplo n.º 11
0
            private async Task Blacklist(AddRemove action, ulong id, BlacklistType type)
            {
                if (action == AddRemove.Add && _creds.OwnerIds.Contains(id))
                {
                    return;
                }

                using (var uow = _db.UnitOfWork)
                {
                    if (action == AddRemove.Add)
                    {
                        var item = new BlacklistItem {
                            ItemId = id, Type = type
                        };
                        uow.BotConfig.GetOrCreate().Blacklist.Add(item);
                    }
                    else
                    {
                        var objs = uow.BotConfig
                                   .GetOrCreate(set => set.Include(x => x.Blacklist))
                                   .Blacklist
                                   .Where(bi => bi.ItemId == id && bi.Type == type);

                        if (objs.Any())
                        {
                            uow._context.Set <BlacklistItem>().RemoveRange(objs);
                        }
                    }
                    await uow.CompleteAsync().ConfigureAwait(false);
                }

                if (action == AddRemove.Add)
                {
                    await ReplyConfirmLocalizedAsync("blacklisted", Format.Code(type.ToString()), Format.Code(id.ToString())).ConfigureAwait(false);
                }
                else
                {
                    await ReplyConfirmLocalizedAsync("unblacklisted", Format.Code(type.ToString()), Format.Code(id.ToString())).ConfigureAwait(false);
                }
            }
Exemplo n.º 12
0
 public Task ServerBlacklist(AddRemove action, IGuild guild)
 => Blacklist(action, guild.Id, BlacklistType.Server);
Exemplo n.º 13
0
 public Task ServerBlacklist(AddRemove action, ulong id)
 => Blacklist(action, id, BlacklistType.Server);
Exemplo n.º 14
0
 public Task ChannelBlacklist(AddRemove action, ulong id)
 => Blacklist(action, id, BlacklistType.Channel);
Exemplo n.º 15
0
 public Task UserBlacklist(AddRemove action, IUser usr)
 => Blacklist(action, usr.Id, BlacklistType.User);
Exemplo n.º 16
0
        /// <summary>
        /// Adds or removes a user from a blacklist or a whitelist in the specified guild.
        /// </summary>
        /// <param name="guild">Guild</param>
        /// <param name="action">Add or rem action</param>
        /// <param name="userId">User's Id</param>
        /// <param name="userName">User's name#discrim</param>
        /// <returns>Whether the operation was successful</returns>
        public async Task <bool> ApplyListAction(StreamRoleListType listType, IGuild guild, AddRemove action, ulong userId, string userName)
        {
            userName.ThrowIfNull(nameof(userName));

            bool success = false;

            using (var uow = _db.UnitOfWork)
            {
                var streamRoleSettings = uow.GuildConfigs.GetStreamRoleSettings(guild.Id);

                if (listType == StreamRoleListType.Whitelist)
                {
                    var userObj = new StreamRoleWhitelistedUser()
                    {
                        UserId   = userId,
                        Username = userName,
                    };

                    if (action == AddRemove.Rem)
                    {
                        var toDelete = streamRoleSettings.Whitelist.FirstOrDefault(x => x.Equals(userObj));
                        if (toDelete != null)
                        {
                            uow._context.Remove(toDelete);
                            success = true;
                        }
                    }
                    else
                    {
                        success = streamRoleSettings.Whitelist.Add(userObj);
                    }
                }
                else
                {
                    var userObj = new StreamRoleBlacklistedUser()
                    {
                        UserId   = userId,
                        Username = userName,
                    };

                    if (action == AddRemove.Rem)
                    {
                        var toRemove = streamRoleSettings.Blacklist.FirstOrDefault(x => x.Equals(userObj));
                        if (toRemove != null)
                        {
                            success = true;
                            success = streamRoleSettings.Blacklist.Remove(toRemove);
                        }
                    }
                    else
                    {
                        success = streamRoleSettings.Blacklist.Add(userObj);
                    }
                }

                await uow.CompleteAsync();

                UpdateCache(guild.Id, streamRoleSettings);
            }
            if (success)
            {
                await RescanUsers(guild).ConfigureAwait(false);
            }
            return(success);
        }
Exemplo n.º 17
0
 public Task ChannelBlacklist(IUserMessage imsg, AddRemove action, ulong id)
     => Blacklist(imsg, action, id, BlacklistType.Channel);
 public Task BlacklistChannel(AddRemove action, IChannel channel)
 => Blacklist(action, channel.Id, BlacklistType.Channel);
 public Task BlacklistUser(AddRemove action, IUser user)
 => Blacklist(action, user.Id, BlacklistType.User);
Exemplo n.º 20
0
 public Task UserBlacklist(IUserMessage imsg, AddRemove action, IUser usr)
     => Blacklist(imsg, action, usr.Id, BlacklistType.User);
Exemplo n.º 21
0
 public Task UserBlacklist(IUserMessage imsg, AddRemove action, IUser usr)
 => Blacklist(imsg, action, usr.Id, BlacklistType.User);
Exemplo n.º 22
0
 public Task ServerBlacklist(IUserMessage imsg, AddRemove action, ulong id)
 => Blacklist(imsg, action, id, BlacklistType.Server);
Exemplo n.º 23
0
 public Task ServerBlacklist(IUserMessage imsg, AddRemove action, ulong id)
     => Blacklist(imsg, action, id, BlacklistType.Server);
Exemplo n.º 24
0
 public Task ServerBlacklist(IUserMessage imsg, AddRemove action, IGuild guild)
     => Blacklist(imsg, action, guild.Id, BlacklistType.Server);
Exemplo n.º 25
0
 private SetEvent(AddRemove kind, T value) : this()
 {
     Kind  = kind;
     Value = value;
 }
Exemplo n.º 26
0
 public Task ChannelBlacklist(IUserMessage imsg, AddRemove action, ulong id)
 => Blacklist(imsg, action, id, BlacklistType.Channel);
 public Task BlacklistUser(AddRemove action, ulong id)
 => Blacklist(action, id, BlacklistType.User);
Exemplo n.º 28
0
 public Task ServerBlacklist(IUserMessage imsg, AddRemove action, IGuild guild)
 => Blacklist(imsg, action, guild.Id, BlacklistType.Server);
Exemplo n.º 29
0
            private async Task Blacklist(AddRemove action, ulong id, BlacklistType type)
            {
                if (action == AddRemove.Add && _creds.OwnerIds.Contains(id))
                {
                    return;
                }

                using (var uow = _db.UnitOfWork)
                {
                    if (action == AddRemove.Add)
                    {
                        var item = new BlacklistItem {
                            ItemId = id, Type = type
                        };
                        uow.BotConfig.GetOrCreate().Blacklist.Add(item);
                        if (type == BlacklistType.Server)
                        {
                            BlacklistedGuilds.Add(id);
                        }
                        else if (type == BlacklistType.Channel)
                        {
                            BlacklistedChannels.Add(id);
                        }
                        else if (type == BlacklistType.User)
                        {
                            BlacklistedUsers.Add(id);
                        }
                    }
                    else
                    {
                        uow.BotConfig.GetOrCreate().Blacklist.RemoveWhere(bi => bi.ItemId == id && bi.Type == type);
                        if (type == BlacklistType.Server)
                        {
                            BlacklistedGuilds.TryRemove(id);
                        }
                        else if (type == BlacklistType.Channel)
                        {
                            BlacklistedChannels.TryRemove(id);
                        }
                        else if (type == BlacklistType.User)
                        {
                            BlacklistedUsers.TryRemove(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);
                }
            }