Skip to content

Commit

Permalink
Implement and use check_bot_admin in backend_info
Browse files Browse the repository at this point in the history
Co-authored-by: Samyak Mishra <[email protected]>
  • Loading branch information
ankith26 and someyuck committed Jun 5, 2024
1 parent dc919a7 commit 5384095
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions bot/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- `get_users_from_discordid()`: Find users from DB given user ID
- `is_verified()`: If a user is present in DB or not
- `check_bot_admin()`: Check if a user is a bot admin or not
- `get_realname_from_discordid()`: Get a user's real name from their Discord ID.
- `send_link()`: Send link for reattempting authentication.
- `create_roles_if_missing()`: Adds missing roles to a server.
Expand All @@ -15,6 +16,7 @@
- `post_verification()`: Handle role add/delete and nickname set post-verification of given user.
- `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.
- `is_academic()`: Checks if server is for academic use.
- `query()`: Returns user details, uses Discord ID to find in DB.
- `query_error()`: Replies eror message if server is not academic.
Expand Down Expand Up @@ -91,6 +93,12 @@ def is_verified(user_id: int):
return True if get_users_from_discordid(user_id) else False


@commands.check
def check_bot_admin(ctx: commands.Context):
"""Checks if the user with the given discord ID is a bot admin or not."""
return ctx.author.id in BOT_ADMINS


def get_realname_from_discordid(user_id: int):
"""Returns the real name of the first user who matches the given ID."""
users = get_users_from_discordid(user_id)
Expand Down Expand Up @@ -223,6 +231,7 @@ async def verify_user(ctx: commands.Context):


@bot.hybrid_command(name="backend_info")
@check_bot_admin
async def backend_info(ctx: commands.Context):
"""For debugging server info; sends details of the server."""
uname = platform.uname()
Expand All @@ -237,6 +246,13 @@ async def backend_info(ctx: commands.Context):
)


@backend_info.error
async def backend_info_error(ctx: commands.Context, error: Exception):
"""If the author of the message is not a bot admin then reply accordingly."""
if isinstance(error, commands.CheckFailure):
await ctx.reply(f"{ctx.author.mention} is not a bot admin.", ephemeral=True)


def is_academic(ctx: commands.Context):
"""Checks if the server is an academic server."""
if ctx.guild is None:
Expand Down

0 comments on commit 5384095

Please sign in to comment.