Skip to content

Commit

Permalink
chore: Remove admin commands from help menu (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
AustinH-adl authored Jan 7, 2025
1 parent 3fb1ce8 commit 2fd2550
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
33 changes: 32 additions & 1 deletion src/commands/admin_commands.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging
import os

from discord import Embed, Interaction, app_commands
from discord import Color, Embed, Interaction, app_commands
from dotenv import load_dotenv

from models.databases.admin_settings_db import AdminSettingsDB
Expand All @@ -28,6 +28,8 @@ def __init__(self, gemini_bot):
self.add_command(self.reset)

async def check_admin(self, interaction: Interaction) -> bool:
"""Check if the user who called the admin command is an admin"""

user_name = interaction.user.name
logging.info(f"Checking admin status for user: {user_name}")

Expand All @@ -41,6 +43,35 @@ async def check_admin(self, interaction: Interaction) -> bool:
logging.warning(f"User {user_name} is not authorised.")
return False

@app_commands.command(
name="help", description="Display name and description of admin commands"
)
async def admin_help(self, interaction: Interaction):
"""Help command containing all admin commands and details"""
if not await self.check_admin(interaction):
return

embed = Embed(
title=self.name,
description=self.description,
color=Color.yellow(),
)
for subcommand in self.walk_commands():
if isinstance(subcommand, app_commands.Group):
for subsubcommand in subcommand.commands:
embed.add_field(
name=f"/{self.name} {subcommand.name} {subsubcommand.name}",
value=subsubcommand.description,
inline=True,
)
else:
embed.add_field(
name=f"/{self.name} {subcommand.name}",
value=subcommand.description,
inline=False,
)
await interaction.response.send_message(embed=embed, ephemeral=True)

@app_commands.command(
name="log-variables", description="Display all current environment variables."
)
Expand Down
2 changes: 2 additions & 0 deletions src/commands/help_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ def organise_commands(self):
"""Organise commands into groups and misc categories."""
for command in self.commands:
if isinstance(command, app_commands.Group):
if command.name == "admin": # TODO make a variable for ignore
continue
self.group_commands.append(command)
self.maxpages += 1
else:
Expand Down

0 comments on commit 2fd2550

Please sign in to comment.