Skip to content

Commit

Permalink
Reworked Help Command
Browse files Browse the repository at this point in the history
  • Loading branch information
dkoz committed Sep 28, 2024
1 parent af848db commit c8c3e94
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 40 deletions.
4 changes: 1 addition & 3 deletions cogs/gamedata.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,6 @@ def setup(bot):
bot.all_slash_commands = []
bot.all_slash_commands.extend(
[
cog.search,
cog.pal,
cog.item,
cog.search
]
)
33 changes: 22 additions & 11 deletions cogs/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from nextcord.ext import commands
from nextcord.ui import Button, View
import utils.constants as constants
import logging

class HelpView(View):
def __init__(self, bot):
Expand All @@ -20,17 +21,22 @@ async def generate_help_embed(self):
icon_url=constants.FOOTER_IMAGE,
)

commands = (
self.bot.all_slash_commands
if hasattr(self.bot, "all_slash_commands")
else []
)
commands_with_paths = []

for cmd in self.bot.all_slash_commands:
if hasattr(cmd, 'children') and cmd.children:
for subcmd in cmd.children.values():
commands_with_paths.append((f"{cmd.name} {subcmd.name}", subcmd))
elif not hasattr(cmd, 'children') or not cmd.children:
commands_with_paths.append((cmd.name, cmd))

commands_with_paths.sort(key=lambda x: x[0])
start = self.current_page * 9
end = min(start + 9, len(commands))
end = min(start + 9, len(commands_with_paths))

for command in commands[start:end]:
for cmd_path, command in commands_with_paths[start:end]:
embed.add_field(
name=f"`/{command.name}`",
name=f"/{cmd_path}",
value=command.description or "No description",
inline=True,
)
Expand Down Expand Up @@ -63,9 +69,14 @@ def __init__(self, bot):

@nextcord.slash_command(description="Shows a list of available commands.")
async def help(self, interaction: nextcord.Interaction):
view = HelpView(self.bot)
embed = await view.generate_help_embed()
await interaction.response.send_message(embed=embed, view=view, ephemeral=True)
try:
await interaction.response.defer(ephemeral=True)
view = HelpView(self.bot)
embed = await view.generate_help_embed()
await interaction.followup.send(embed=embed, view=view)
except Exception as e:
await interaction.followup.send(f"Error in help command: {e}")
logging.error(f"Error in help command: {e}")

# Please do not remove the about me section. I've spent a lot of time on this bot and I would appreciate it if you left it in.
@nextcord.slash_command(description="Information about the Palworld bot.")
Expand Down
10 changes: 1 addition & 9 deletions cogs/palcon.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,14 +320,6 @@ def setup(bot):
bot.all_slash_commands = []
bot.all_slash_commands.extend(
[
cog.command,
cog.showplayers,
cog.kickplayer,
cog.banplayer,
cog.unbanplayer,
cog.info,
cog.shutdown,
cog.save,
cog.broadcast,
cog.palcon,
]
)
13 changes: 1 addition & 12 deletions cogs/palguard.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,17 +502,6 @@ def setup(bot):
bot.all_slash_commands.extend(
[
cog.palguard,
cog.reloadcfg,
cog.givepal,
cog.giveitem,
cog.delitem,
cog.giveexp,
cog.giveegg,
cog.palguardhelp,
cog.giverelic,
cog.whitelist,
cog.whitelistadd,
cog.whitelistremove,
cog.whitelistget,
cog.whitelist
]
)
4 changes: 1 addition & 3 deletions cogs/playerlog.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,6 @@ def setup(bot):
bot.all_slash_commands = []
bot.all_slash_commands.extend(
[
cog.userdb,
cog.search,
cog.searchname,
cog.userdb
]
)
3 changes: 1 addition & 2 deletions cogs/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,6 @@ def setup(bot):
bot.all_slash_commands = []
bot.all_slash_commands.extend(
[
cog.querylogs,
cog.removequerylogs
cog.query
]
)

0 comments on commit c8c3e94

Please sign in to comment.