mirror of
https://github.com/turtlebasket/comrade-bot.git
synced 2026-03-04 11:34:29 -08:00
check user permissions before moderation votes
This commit is contained in:
19
bot.py
19
bot.py
@@ -1,8 +1,8 @@
|
|||||||
"""
|
"""
|
||||||
_____ __ ___ __
|
_____ __
|
||||||
/ ___/__ __ _ _______ ____/ /__ / _ )___ / /_
|
/ ___/__ __ _ _______ ____/ /__
|
||||||
/ /__/ _ \/ ' \/ __/ _ `/ _ / -_) / _ / _ \/ __/
|
/ /__/ _ \/ ' \/ __/ _ `/ _ / -_)
|
||||||
\___/\___/_/_/_/_/ \_,_/\_,_/\__/ /____/\___/\__/
|
\___/\___/_/_/_/_/ \_,_/\_,_/\__/
|
||||||
|
|
||||||
A bot by turtlebasket
|
A bot by turtlebasket
|
||||||
"""
|
"""
|
||||||
@@ -213,6 +213,8 @@ async def ping(ctx):
|
|||||||
@bot.command()
|
@bot.command()
|
||||||
async def mute(ctx, target_user:discord.User):
|
async def mute(ctx, target_user:discord.User):
|
||||||
|
|
||||||
|
await require_lower_permissions(ctx, target_user, bot)
|
||||||
|
|
||||||
if target_user in muting_users:
|
if target_user in muting_users:
|
||||||
await ctx.send("There is already a mute vote on `{}`!".format(target_user))
|
await ctx.send("There is already a mute vote on `{}`!".format(target_user))
|
||||||
return
|
return
|
||||||
@@ -251,6 +253,8 @@ async def mute(ctx, target_user:discord.User):
|
|||||||
@bot.command()
|
@bot.command()
|
||||||
async def kick(ctx, target_user:discord.User):
|
async def kick(ctx, target_user:discord.User):
|
||||||
|
|
||||||
|
await require_lower_permissions(ctx, target_user, bot)
|
||||||
|
|
||||||
if target_user in kicking_users:
|
if target_user in kicking_users:
|
||||||
await ctx.send("There is already a kick vote on `{}`!".format(target_user))
|
await ctx.send("There is already a kick vote on `{}`!".format(target_user))
|
||||||
return
|
return
|
||||||
@@ -269,6 +273,8 @@ async def kick(ctx, target_user:discord.User):
|
|||||||
@bot.command(aliases=['exile'])
|
@bot.command(aliases=['exile'])
|
||||||
async def ban(ctx, target_user:discord.User):
|
async def ban(ctx, target_user:discord.User):
|
||||||
|
|
||||||
|
await require_lower_permissions(ctx, target_user, bot)
|
||||||
|
|
||||||
if target_user in banning_users:
|
if target_user in banning_users:
|
||||||
await ctx.send("There is already a ban vote on `{}`!".format(target_user))
|
await ctx.send("There is already a ban vote on `{}`!".format(target_user))
|
||||||
return
|
return
|
||||||
@@ -284,4 +290,9 @@ async def ban(ctx, target_user:discord.User):
|
|||||||
|
|
||||||
banning_users.remove(target_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"])
|
bot.run(tokens["bot_token"])
|
||||||
|
|||||||
20
bot_utils.py
20
bot_utils.py
@@ -56,8 +56,24 @@ async def take_vote(ctx, question:str, vote_time, min_voters):
|
|||||||
))
|
))
|
||||||
return passed
|
return passed
|
||||||
|
|
||||||
async def improper_usage(ctx):
|
class CommandBreakerException(Exception):
|
||||||
await ctx.send("Improper command usage! See `>>help` for more.")
|
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):
|
def imgfun(msg:str, img_url:str):
|
||||||
return discord.Embed(
|
return discord.Embed(
|
||||||
|
|||||||
Reference in New Issue
Block a user