Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Remove admin commands from help menu #92

Merged
merged 3 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading