1
0
Fork 0
mirror of synced 2024-05-20 20:42:27 +12:00

Update to check if a message should be ignored

This commit is contained in:
Phxntxm 2017-04-13 18:30:14 -05:00
parent 38133ad8bb
commit 46e28b81a1
3 changed files with 51 additions and 8 deletions

2
bot.py
View file

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

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

View file

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