1
0
Fork 0
mirror of synced 2024-05-17 19:12:33 +12:00

Check if a message should be ignored

This commit is contained in:
phxntxm 2017-04-11 00:22:11 -05:00
parent 38133ad8bb
commit ac8689881d
3 changed files with 8 additions and 10 deletions

4
bot.py
View file

@ -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)

View file

@ -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

View file

@ -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