Add the ability to ignore channels/members
This commit is contained in:
parent
e531d0ab4d
commit
38133ad8bb
49
cogs/mod.py
49
cogs/mod.py
|
@ -108,6 +108,55 @@ class Mod:
|
||||||
except discord.HTTPException:
|
except discord.HTTPException:
|
||||||
await ctx.send("Sorry, I failed to ban that user!")
|
await ctx.send("Sorry, I failed to ban that user!")
|
||||||
|
|
||||||
|
@commands.command()
|
||||||
|
@commands.guild_only()
|
||||||
|
@utils.custom_perms(manage_guild=True)
|
||||||
|
async def ignore(self, ctx, member_or_channel):
|
||||||
|
"""This command can be used to have Bonfire ignore certain members/channels
|
||||||
|
|
||||||
|
EXAMPLE: !ignore #general
|
||||||
|
RESULT: Bonfire will 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) in ignored['members']:
|
||||||
|
await ctx.send("I am already ignoring {}!".format(member.display_name))
|
||||||
|
return
|
||||||
|
elif member.guild_permissions >= ctx.message.author.guild_permissions:
|
||||||
|
await ctx.send("You cannot make me ignore someone at equal or higher rank than you!")
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
ignored['members'].append(str(member.id))
|
||||||
|
fmt = "Ignoring {}".format(member.display_name)
|
||||||
|
elif channel:
|
||||||
|
if str(channel.id) in ignored['channels']:
|
||||||
|
await ctx.send("I am already ignoring {}!".format(channel.mention))
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
ignored['channels'].append(str(channel.id))
|
||||||
|
fmt = "Ignoring {}".format(channel.mention)
|
||||||
|
|
||||||
|
update = {'ignored': ignored}
|
||||||
|
await utils.update_content('server_settings', update, key)
|
||||||
|
await ctx.send(fmt)
|
||||||
|
|
||||||
@commands.command(aliases=['alerts'])
|
@commands.command(aliases=['alerts'])
|
||||||
@commands.guild_only()
|
@commands.guild_only()
|
||||||
@utils.custom_perms(kick_members=True)
|
@utils.custom_perms(kick_members=True)
|
||||||
|
|
|
@ -65,6 +65,14 @@ async def db_check():
|
||||||
def is_owner(ctx):
|
def is_owner(ctx):
|
||||||
return ctx.message.author.id in config.owner_ids
|
return ctx.message.author.id in config.owner_ids
|
||||||
|
|
||||||
|
def should_ignore(ctx):
|
||||||
|
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']
|
||||||
|
except (TypeError, IndexError, KeyError):
|
||||||
|
return False
|
||||||
|
|
||||||
def custom_perms(**perms):
|
def custom_perms(**perms):
|
||||||
def predicate(ctx):
|
def predicate(ctx):
|
||||||
|
@ -72,6 +80,10 @@ def custom_perms(**perms):
|
||||||
if type(ctx.message.channel) is discord.DMChannel:
|
if type(ctx.message.channel) is discord.DMChannel:
|
||||||
return True
|
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
|
# Get the member permissions so that we can compare
|
||||||
member_perms = ctx.message.author.permissions_in(ctx.message.channel)
|
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
|
# Next, set the default permissions if one is not used, based on what was passed
|
||||||
|
|
Loading…
Reference in a new issue