From 2a3f4d99f7dd766e71e4a6aa015f5852d9e42f91 Mon Sep 17 00:00:00 2001 From: Myned Date: Thu, 3 Jan 2019 18:03:56 -0500 Subject: [PATCH] Add block command group --- src/cogs/owner.py | 49 ++++++++++++++++++++++++++++++++++++++++++++++ src/run.py | 8 +++++++- src/utils/utils.py | 1 + 3 files changed, 57 insertions(+), 1 deletion(-) diff --git a/src/cogs/owner.py b/src/cogs/owner.py index 7d6b5c0..c93f707 100644 --- a/src/cogs/owner.py +++ b/src/cogs/owner.py @@ -78,6 +78,55 @@ class Bot: for page in paginator.pages: await ctx.send(f'**Guilds:**\n{page}') + @cmds.group(name=',block', aliases=[',bl', ',b']) + @cmds.is_owner() + async def block(self, ctx): + pass + + @block.group(name='list', aliases=['l']) + async def block_list(self, ctx): + pass + + @block_list.command(name='guilds', aliases=['g']) + async def block_list_guilds(self, ctx): + await formatter.paginate(ctx, u.block['guild_ids']) + + @block.command(name='user', aliases=['u']) + async def block_user(self, ctx, *users: d.User): + for user in users: + u.block['user_ids'].append(user.id) + + u.dump(u.block, 'cogs/block.json', json=True) + + @block.command(name='guild', aliases=['g']) + async def block_guild(self, ctx, *guilds): + for guild in guilds: + u.block['guild_ids'].append(guild) + + u.dump(u.block, 'cogs/block.json', json=True) + + @cmds.group(name=',unblock', aliases=[',unbl', ',unb']) + @cmds.is_owner() + async def unblock(self, ctx): + pass + + @unblock.command(name='user', aliases=['u']) + async def unblock_user(self, ctx, *users: d.User): + for user in users: + u.block['user_ids'].remove(user.id) + + u.dump(u.block, 'cogs/block.json', json=True) + + await ctx.send('\N{WHITE HEAVY CHECK MARK} **Unblocked users**') + + @unblock.command(name='guild', aliases=['g']) + async def unblock_guild(self, ctx, *guilds): + for guild in guilds: + u.block['guild_ids'].remove(guild) + + u.dump(u.block, 'cogs/block.json', json=True) + + await ctx.send('\N{WHITE HEAVY CHECK MARK} **Unblocked guilds**') @cmds.command(name=',permissions', aliases=[',permission', ',perms', ',perm']) @cmds.is_owner() async def permissions(self, ctx, *args: d.Member): diff --git a/src/run.py b/src/run.py index a680b45..bbe7e22 100644 --- a/src/run.py +++ b/src/run.py @@ -127,7 +127,7 @@ async def on_ready(): @bot.event async def on_message(message): if not u.config['selfbot']: - if message.author is not bot.user and not message.author.bot: + if message.author is not bot.user and not message.author.bot and message.author.id not in u.block['user_ids']: await bot.process_commands(message) else: if not message.author.bot: @@ -213,6 +213,12 @@ async def on_command_completion(ctx): u.last_commands[ctx.author.id] = ctx +@bot.event +async def on_guild_join(guild): + if str(guild.id) in u.block['guild_ids']: + print(f'LEAVING : {guild.name}') + await guild.leave() + @bot.event async def on_guild_remove(guild): print(f'LEFT : {guild.name}') diff --git a/src/utils/utils.py b/src/utils/utils.py index 77306f9..ef157be 100644 --- a/src/utils/utils.py +++ b/src/utils/utils.py @@ -85,6 +85,7 @@ def dump(obj, filename, *, json=False): settings = setdefault('misc/settings.pkl', default={'del_ctx': [], 'del_resp': [], 'prefixes': {}}) tasks = setdefault('cogs/tasks.pkl', default={'auto_del': [], 'auto_hrt': [], 'auto_rev': []}) temp = setdefault('temp/temp.pkl', default={'startup': ()}) +block = setdefault('cogs/block.json', default={'guild_ids': [], 'user_ids': []}, json=True) cogs = {} color = d.Color(0x1A1A1A)