From ac8689881d410711b43d9f4bca659ecb1a8a6be0 Mon Sep 17 00:00:00 2001 From: phxntxm Date: Tue, 11 Apr 2017 00:22:11 -0500 Subject: [PATCH] Check if a message should be ignored --- bot.py | 4 ++-- cogs/utils/__init__.py | 2 +- cogs/utils/checks.py | 12 +++++------- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/bot.py b/bot.py index 9212158..5395c85 100644 --- a/bot.py +++ b/bot.py @@ -18,7 +18,7 @@ opts = {'command_prefix': utils.command_prefix, 'command_not_found': ''} bot = commands.AutoShardedBot(**opts) -logging.basicConfig(level=logging.WARNING, filename='bonfire.log') +logging.basicConfig(level=logging.INFO, filename='bonfire.log') @bot.event @@ -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/utils/__init__.py b/cogs/utils/__init__.py index 4200e2b..7a3867b 100644 --- a/cogs/utils/__init__.py +++ b/cogs/utils/__init__.py @@ -1,5 +1,5 @@ from .cards import Deck -from .checks import is_owner, custom_perms, db_check +from .checks import is_owner, custom_perms, db_check, should_ignore from .config import * from .utilities import * from .images import create_banner diff --git a/cogs/utils/checks.py b/cogs/utils/checks.py index 1507695..bbae7cb 100644 --- a/cogs/utils/checks.py +++ b/cogs/utils/checks.py @@ -65,25 +65,23 @@ 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 + def custom_perms(**perms): def predicate(ctx): # Return true if this is a private channel, we'll handle that in the registering of the command 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