Skip to content

Commit

Permalink
Extend academic check to also check for mod perms
Browse files Browse the repository at this point in the history
  • Loading branch information
ankith26 committed Jun 5, 2024
1 parent 0da63bb commit 082ba89
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions bot/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
- `verify_user()`: Implements `.verify`.
- `backend_info()`: Logs server details for debug purposes
- `backend_info_error()`: If the author of the message is not a bot admin then reply accordingly.
- `check_is_academic()`: Checks if server is for academic use.
- `check_is_academic_mod()`: Checks if server is for academic use.
- `query()`: Returns user details, uses Discord ID to find in DB.
- `roll()`: Returns user details, uses roll number to find in DB.
- `roll_or_query_error()`: Replies eror message if server is not academic or author is not a bot admin.
Expand Down Expand Up @@ -253,19 +253,26 @@ async def backend_info_error(ctx: commands.Context, error: Exception):


@commands.check
def check_is_academic(ctx: commands.Context):
"""Checks if the server is an academic server."""
async def check_is_academic_mod(ctx: commands.Context):
"""
Checks if the server is an academic server, and that the invoker has moderation
permissions
"""
if ctx.guild is None:
return False

try:
return server_configs[ctx.guild.id]["is_academic"]
if server_configs[ctx.guild.id]["is_academic"]:
return await commands.has_permissions(moderate_members=True).predicate(ctx)

except KeyError:
return False
pass

return False


@bot.hybrid_command(name="query")
@commands.check_any(check_is_academic, check_bot_admin)
@commands.check_any(check_is_academic_mod, check_bot_admin)
async def query(
ctx: commands.Context,
identifier: discord.User,
Expand Down Expand Up @@ -297,7 +304,7 @@ async def query(


@bot.hybrid_command(name="roll")
@commands.check_any(check_is_academic, check_bot_admin)
@commands.check_any(check_is_academic_mod, check_bot_admin)
async def roll(
ctx: commands.Context,
identifier: int,
Expand Down

0 comments on commit 082ba89

Please sign in to comment.