Skip to content
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
66 changes: 66 additions & 0 deletions src/commands/help.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
from __future__ import annotations

from typing import TYPE_CHECKING

from discord import Color, Embed, Interaction, app_commands
from discord.ext import commands

if TYPE_CHECKING:
from src.main import AeBot


class HelpCog(commands.Cog):
def __init__(self, bot: AeBot):
self.bot = bot

@app_commands.command(
name="help",
description=(
"Affiche la liste des commandes avec"
" leurs sous-commandes et leurs description"
),
)
async def help(self, interaction: Interaction):
embed = Embed(title="Aide du bot", color=Color.blue())

pres_commande = ["remove_member", "add_member"]
admin_commande = ["passation", "arret", "create"]

roles = interaction.user.roles
n = len(roles)
i = 0
loop = True
grade = 2 # 0 for admin 1 for presidence of clubs and 2 for member
while i < n and loop:
if roles[i].name == "Présidence AE":
grade = 0
loop = False
elif roles[i].name.startswith("Responsable"):
grade = 1
loop = False
else:
pass
i += 1

for command in self.bot.tree.get_commands():
if isinstance(command, app_commands.Group) and command.commands:
for sub in command.commands:
if not (
(sub.name in pres_commande and grade > 1)
or (sub.name in admin_commande and grade != 0)
):
subcommands = f" {sub.description}\n"
embed.add_field(
name=f"/{command.name} {sub.name}",
value=subcommands,
inline=False,
)

elif command.name != "role":
embed.add_field(
name=f"/{command.name}",
value=command.description or "",
inline=False,
)

await interaction.response.send_message(embed=embed, ephemeral=True)
4 changes: 3 additions & 1 deletion src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from src.client import SithClient
from src.commands.admin import AdminCog
from src.commands.club import ClubCog
from src.commands.help import HelpCog
from src.commands.misc import MiscCog
from src.commands.news import NewsCog
from src.commands.role import RoleCog
Expand Down Expand Up @@ -40,11 +41,12 @@ async def setup_hook(self):
await self.add_cog(AdminCog(self))
await self.add_cog(MiscCog())
await self.add_cog(RoleCog(self))
await self.add_cog(HelpCog(self))

async def on_ready(self):
await self.wait_until_ready()
self.watched_guild = self.get_guild(self.settings.guild.id)
await self.change_presence(activity=Game(name="/help"))
await self.change_presence(activity=Game(name="/help help"))
self.logger.info(f"Bot ready to act on {self.watched_guild.name}")

async def on_command(self, ctx: Context):
Expand Down