check user permissions before moderation votes

master
michael 2020-07-21 20:21:00 -07:00
parent 3eed22661f
commit f99c6df770
2 changed files with 33 additions and 6 deletions

19
bot.py
View File

@ -1,8 +1,8 @@
"""
_____ __ ___ __
/ ___/__ __ _ _______ ____/ /__ / _ )___ / /_
/ /__/ _ \/ ' \/ __/ _ `/ _ / -_) / _ / _ \/ __/
\___/\___/_/_/_/_/ \_,_/\_,_/\__/ /____/\___/\__/
_____ __
/ ___/__ __ _ _______ ____/ /__
/ /__/ _ \/ ' \/ __/ _ `/ _ / -_)
\___/\___/_/_/_/_/ \_,_/\_,_/\__/
A bot by turtlebasket
"""
@ -213,6 +213,8 @@ async def ping(ctx):
@bot.command()
async def mute(ctx, target_user:discord.User):
await require_lower_permissions(ctx, target_user, bot)
if target_user in muting_users:
await ctx.send("There is already a mute vote on `{}`!".format(target_user))
return
@ -251,6 +253,8 @@ async def mute(ctx, target_user:discord.User):
@bot.command()
async def kick(ctx, target_user:discord.User):
await require_lower_permissions(ctx, target_user, bot)
if target_user in kicking_users:
await ctx.send("There is already a kick vote on `{}`!".format(target_user))
return
@ -269,6 +273,8 @@ async def kick(ctx, target_user:discord.User):
@bot.command(aliases=['exile'])
async def ban(ctx, target_user:discord.User):
await require_lower_permissions(ctx, target_user, bot)
if target_user in banning_users:
await ctx.send("There is already a ban vote on `{}`!".format(target_user))
return
@ -284,4 +290,9 @@ async def ban(ctx, target_user:discord.User):
banning_users.remove(target_user)
@bot.command()
async def test(ctx, target_user:discord.User):
await require_lower_permissions(ctx, target_user, bot)
await ctx.send("success")
bot.run(tokens["bot_token"])

View File

@ -56,8 +56,24 @@ async def take_vote(ctx, question:str, vote_time, min_voters):
))
return passed
async def improper_usage(ctx):
await ctx.send("Improper command usage! See `>>help` for more.")
class CommandBreakerException(Exception):
pass
async def error_invalid_usage(ctx):
await ctx.send("⚠ `Invalid command usage! See `>>help` for more.`")
async def error_admin_targeted(ctx):
await ctx.send("⚠ `Cannot perform this action on adminstrators or users with a higher or equal role.`")
async def require_lower_permissions(ctx, user:discord.User, bot:discord.ext.commands.Bot):
memb = await ctx.guild.fetch_member(user.id)
bot_memb = await ctx.guild.fetch_member(bot.user.id)
is_admin = memb.permissions_in(ctx.channel).administrator
is_higher = memb.top_role.position >= bot_memb.top_role.position
if is_admin or is_higher:
await error_admin_targeted(ctx)
raise CommandBreakerException
def imgfun(msg:str, img_url:str):
return discord.Embed(