From 2a3f4d99f7dd766e71e4a6aa015f5852d9e42f91 Mon Sep 17 00:00:00 2001 From: Myned Date: Thu, 3 Jan 2019 18:03:56 -0500 Subject: [PATCH 1/6] 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) From 41daa41c7825170cc532ad928a0dab07e6d1ffa7 Mon Sep 17 00:00:00 2001 From: Myned Date: Thu, 3 Jan 2019 18:04:17 -0500 Subject: [PATCH 2/6] Add leave guild command --- src/cogs/owner.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/cogs/owner.py b/src/cogs/owner.py index c93f707..cb4c618 100644 --- a/src/cogs/owner.py +++ b/src/cogs/owner.py @@ -127,6 +127,15 @@ class Bot: u.dump(u.block, 'cogs/block.json', json=True) await ctx.send('\N{WHITE HEAVY CHECK MARK} **Unblocked guilds**') + + @cmds.command(name=',leave', aliases=[',l']) + @cmds.is_owner() + async def leave(self, ctx, *guilds): + for guild in guilds: + temp = d.utils.get(self.bot.guilds, id=int(guild)) + + await temp.leave() + @cmds.command(name=',permissions', aliases=[',permission', ',perms', ',perm']) @cmds.is_owner() async def permissions(self, ctx, *args: d.Member): From 031f3168663bad4027cea5de7dd6f18f51034725 Mon Sep 17 00:00:00 2001 From: Myned Date: Thu, 3 Jan 2019 18:05:36 -0500 Subject: [PATCH 3/6] WIP Add guild.id resolution to guild.name for guild info command --- src/cogs/info.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/cogs/info.py b/src/cogs/info.py index 1bada37..c7047b3 100644 --- a/src/cogs/info.py +++ b/src/cogs/info.py @@ -22,15 +22,20 @@ class Info: # # await ctx.send(embed=embed) - @cmds.group(name='info', aliases=['i']) + @cmds.group(name='info', aliases=['i'], hidden=True) async def info(self, ctx): if ctx.invoked_subcommand is None: await ctx.send('BOT INFO') - @info.command(aliases=['g', 'server', 's'], brief='Provides info about a guild', hidden=True) - async def guild(self, ctx): - pass + @info.command(aliases=['g'], brief='Provides info about a guild') + async def guild(self, ctx, guild_id: int): + guild = d.utils.get(self.bot.guilds, id=guild_id) - @info.command(aliases=['u', 'member', 'm'], brief='Provides info about a user', hidden=True) - async def user(self, ctx): + if guild: + await ctx.send(guild.name) + else: + await ctx.send(f'**Not in any guilds by the id of: ** `{guild_id}`') + + @info.command(aliases=['u'], brief='Provides info about a user') + async def user(self, ctx, user: d.User): pass From da16cb37df3c36e1064e82a3c48d25acb2c6247f Mon Sep 17 00:00:00 2001 From: Myned Date: Thu, 3 Jan 2019 18:06:21 -0500 Subject: [PATCH 4/6] Change formatting and aliases --- src/cogs/owner.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/cogs/owner.py b/src/cogs/owner.py index cb4c618..578e9d6 100644 --- a/src/cogs/owner.py +++ b/src/cogs/owner.py @@ -67,13 +67,14 @@ class Bot: await ctx.send('https://discordapp.com/oauth2/authorize?&client_id={}&scope=bot&permissions={}'.format(u.config['client_id'], u.config['permissions'])) - @cmds.command(name=',guilds', aliases=[',glds', ',servers', ',svrs']) + @cmds.command(name=',guilds', aliases=[',gs']) @cmds.is_owner() async def guilds(self, ctx): paginator = cmds.Paginator() for guild in self.bot.guilds: - paginator.add_line(f'{guild.name} - @{guild.owner}') + paginator.add_line(f'{guild.name}: {guild.id}\n' + f' @{guild.owner}: {guild.owner.id}') for page in paginator.pages: await ctx.send(f'**Guilds:**\n{page}') From 88fda1701e807d57cde10c1b90cc755873108536 Mon Sep 17 00:00:00 2001 From: Myned Date: Thu, 3 Jan 2019 18:06:56 -0500 Subject: [PATCH 5/6] Fix inability to start bot if not in owner server --- src/run.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/run.py b/src/run.py index bbe7e22..63d6b74 100644 --- a/src/run.py +++ b/src/run.py @@ -85,9 +85,10 @@ async def on_ready(): await bot.change_presence(activity=d.Game(u.config['playing'])) print('\n> > > > > > > > >\nC O N N E C T E D : {}\n> > > > > > > > >\n'.format(bot.user.name)) - await bot.get_channel(u.config['info_channel']).send(f'**Started** \N{BLACK SUN WITH RAYS} `{"` or `".join(u.config["prefix"])}`') - # u.notify('C O N N E C T E D') + try: + await bot.get_channel(u.config['info_channel']).send(f'**Started** \N{BLACK SUN WITH RAYS} `{"` or `".join(u.config["prefix"])}`') + if u.temp['startup']: with suppress(err.NotFound): if u.temp['startup'][0] == 'guild': @@ -104,6 +105,8 @@ async def on_ready(): checks.ready = True except KeyError: u.dump({'startup': ()}, 'temp/temp.pkl') + except AttributeError: + pass else: print('\n- - - -\nI N F O : reconnected, reinitializing tasks\n- - - -\n') reconnect = await bot.get_user(u.config['owner_id']).send('**RECONNECTING**') From cbd137c1e10895abd1eb006b6299e9ff1324d4ca Mon Sep 17 00:00:00 2001 From: Myned Date: Thu, 3 Jan 2019 18:07:15 -0500 Subject: [PATCH 6/6] Remove command error catching for better debugging --- src/run.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/run.py b/src/run.py index 63d6b74..2d1c7c7 100644 --- a/src/run.py +++ b/src/run.py @@ -167,8 +167,6 @@ async def on_command_error(ctx, error): print('NOT FOUND') elif isinstance(error, err.Forbidden): pass - elif isinstance(error, errext.CommandInvokeError): - print('INVOCATION ERROR') elif isinstance(error, errext.CommandOnCooldown): await u.add_reaction(ctx.message, '\N{HOURGLASS}') await asyncio.sleep(error.retry_after)