Skip to content

Commit

Permalink
help.py: Workaround for cogs with more than 100 commands
Browse files Browse the repository at this point in the history
  • Loading branch information
FrozenChen committed Oct 5, 2024
1 parent eac33db commit bf43b1c
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions utils/help.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import discord
import random
import math

from discord import Interaction
Expand Down Expand Up @@ -277,9 +278,15 @@ async def send_cog_help(self, cog: Cog):
# All my homies hate Assistance
# If there is >25 commands create multiple Selects and add a suffix indicating what commands are inside [A-C]
if len(commands) > SELECT_MAX_VALUES:
for i in range(0, len(commands), SELECT_MAX_VALUES - 1):
view.add_item(CommandSelect(cog, commands[i:i + SELECT_MAX_VALUES - 1], self.context,
suffix=f"[{commands[i].name[0].upper()}-{commands[i:i + SELECT_MAX_VALUES - 2][-1].name[0].upper()}]"))

if len(commands) > 100: # Workaround some cogs having way too many commands, let's go gambling
random.shuffle(commands)
commands = commands[:96]
commands.sort(key=lambda x: x.name)

for batch in batched(commands, SELECT_MAX_VALUES - 1):
view.add_item(CommandSelect(cog, list(batch), self.context,
suffix=f"[{batch[0].name[0].upper()}-{batch[-1].name[0].upper()}]"))
else:
view.add_item(CommandSelect(cog, commands, self.context))

Expand Down

0 comments on commit bf43b1c

Please sign in to comment.