Check if a message should be ignored
This commit is contained in:
parent
38133ad8bb
commit
ac8689881d
4
bot.py
4
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)
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue