From 46e28b81a1e2af72b3f3701db7ad47e8bb36468d Mon Sep 17 00:00:00 2001 From: Phxntxm Date: Thu, 13 Apr 2017 18:30:14 -0500 Subject: [PATCH] Update to check if a message should be ignored --- bot.py | 2 +- cogs/mod.py | 47 ++++++++++++++++++++++++++++++++++++++++++++ cogs/utils/checks.py | 10 +++------- 3 files changed, 51 insertions(+), 8 deletions(-) diff --git a/bot.py b/bot.py index 9212158..8581b77 100644 --- a/bot.py +++ b/bot.py @@ -33,7 +33,7 @@ async def on_ready(): @bot.event async def on_message(message): - if message.author.bot: + if message.author.bot or utils.should_ignore(message): return await bot.process_commands(message) diff --git a/cogs/mod.py b/cogs/mod.py index 79a5bcc..263ead0 100644 --- a/cogs/mod.py +++ b/cogs/mod.py @@ -157,6 +157,53 @@ class Mod: await utils.update_content('server_settings', update, key) await ctx.send(fmt) + + @commands.command() + @commands.guild_only() + @utils.custom_perms(manage_guild=True) + async def unignore(self, ctx, member_or_channel): + """This command can be used to have Bonfire stop ignoring certain members/channels + + EXAMPLE: !unignore #general + RESULT: Bonfire will no longer ignore commands sent in the general channel""" + key = str(ctx.message.guild.id) + + converter = commands.converter.MemberConverter() + converter.prepare(ctx, member_or_channel) + member = None + channel = None + try: + member = converter.convert() + except commands.converter.BadArgument: + converter = commands.converter.TextChannelConverter() + converter.prepare(ctx, member_or_channel) + try: + channel = converter.convert() + except commands.converter.BadArgument: + await ctx.send("{} does not appear to be a member or channel!".format(member_or_channel)) + return + + settings = await utils.get_content('server_settings', key) + ignored = settings.get('ignored', {'members': [], 'channels': []}) + if member: + if str(member.id) not in ignored['members']: + await ctx.send("I'm not even ignoring {}!".format(member.display_name)) + return + + ignored['members'].remove(str(member.id)) + fmt = "I am no longer ignoring {}".format(member.display_name) + elif channel: + if str(channel.id) not in ignored['channels']: + await ctx.send("I'm not even ignoring {}!".format(channel.mention)) + return + + ignored['channels'].remove(str(channel.id)) + fmt = "I am no longer ignoring {}".format(channel.mention) + + update = {'ignored': ignored} + await utils.update_content('server_settings', update, key) + await ctx.send(fmt) + @commands.command(aliases=['alerts']) @commands.guild_only() @utils.custom_perms(kick_members=True) diff --git a/cogs/utils/checks.py b/cogs/utils/checks.py index 1507695..073e959 100644 --- a/cogs/utils/checks.py +++ b/cogs/utils/checks.py @@ -65,12 +65,12 @@ async def db_check(): def is_owner(ctx): return ctx.message.author.id in config.owner_ids -def should_ignore(ctx): +def should_ignore(message): try: server_settings = config.cache.get('server_settings').values ignored = [x for x in server_settings if x['server_id'] == str( - ctx.message.guild.id)][0]['ignored'] - return str(ctx.message.author.id) in ignored['members'] or str(ctx.message.channel.id) in ignored['channels'] + message.guild.id)][0]['ignored'] + return str(message.author.id) in ignored['members'] or str(message.channel.id) in ignored['channels'] except (TypeError, IndexError, KeyError): return False @@ -80,10 +80,6 @@ def custom_perms(**perms): if type(ctx.message.channel) is discord.DMChannel: return True - # Now check if this channel/member should be ignored - if should_ignore(ctx): - return False - # Get the member permissions so that we can compare member_perms = ctx.message.author.permissions_in(ctx.message.channel) # Next, set the default permissions if one is not used, based on what was passed