|
| 1 | +from discord.ext import commands |
| 2 | +import discord |
| 3 | + |
| 4 | +from src.config import settings |
| 5 | + |
| 6 | +# constants |
| 7 | +GITHUB_URL = "https://github.com/ICEDTEACTF/CTFeed" |
| 8 | + |
| 9 | +# view |
| 10 | +class HelpMenu(discord.ui.View): |
| 11 | + def __init__(self, bot:commands.Bot): |
| 12 | + super().__init__(timeout=None) |
| 13 | + |
| 14 | + self.bot = bot |
| 15 | + self._build_view() |
| 16 | + |
| 17 | + |
| 18 | + def _build_view(self): |
| 19 | + # link buttons |
| 20 | + self.add_item(discord.ui.Button( |
| 21 | + style=discord.ButtonStyle.link, |
| 22 | + label="GitHub", |
| 23 | + url=GITHUB_URL |
| 24 | + )) |
| 25 | + self.add_item(discord.ui.Button( |
| 26 | + style=discord.ButtonStyle.link, |
| 27 | + label="Dashboard", |
| 28 | + url=settings.HTTP_FRONTEND_URL |
| 29 | + )) |
| 30 | + |
| 31 | + return |
| 32 | + |
| 33 | + |
| 34 | + async def build_embed_and_view(self) -> discord.Embed: |
| 35 | + # build embed |
| 36 | + bot_name = self.bot.user.name if self.bot.user is not None else "ICEDTEA CTF bot" |
| 37 | + description = ( |
| 38 | + "CTFeed is a Discord bot that tracks CTFTime events, " |
| 39 | + "manages event channels, and provides a simple dashboard." |
| 40 | + ) |
| 41 | + commands_info = [ |
| 42 | + "`/help` - Show this help message", |
| 43 | + "`/ctfmenu` - Browse and manage CTFTime events", |
| 44 | + "`/user` - View and update your user profile", |
| 45 | + "`/config` - Configure guild settings (admin only)" |
| 46 | + ] |
| 47 | + |
| 48 | + embed = discord.Embed( |
| 49 | + title=f"{bot_name} Help", |
| 50 | + description=description, |
| 51 | + color=discord.Color.green() |
| 52 | + ) |
| 53 | + embed.add_field( |
| 54 | + name="Commands", |
| 55 | + value="\n".join(commands_info), |
| 56 | + inline=False |
| 57 | + ) |
| 58 | + |
| 59 | + return embed |
| 60 | + |
| 61 | + |
| 62 | +# cog |
| 63 | +class Help(commands.Cog): |
| 64 | + def __init__(self, bot:commands.Bot): |
| 65 | + self.bot = bot |
| 66 | + |
| 67 | + |
| 68 | + @discord.slash_command(name="help", description="Help Panel") |
| 69 | + async def help_menu(self, ctx:discord.ApplicationContext): |
| 70 | + view = HelpMenu(self.bot) |
| 71 | + embed = await view.build_embed_and_view() |
| 72 | + await ctx.response.send_message(embed=embed, view=view, ephemeral=True) |
| 73 | + |
| 74 | + |
| 75 | +def setup(bot:commands.Bot): |
| 76 | + bot.add_cog(Help(bot)) |
0 commit comments