Skip to content

Commit

Permalink
admin: strip descriptions when going above limit
Browse files Browse the repository at this point in the history
  • Loading branch information
laggron42 committed Nov 16, 2023
1 parent d98bfdd commit b18ab77
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
2 changes: 1 addition & 1 deletion ballsdex/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "2.11.0"
__version__ = "2.11.1"
37 changes: 36 additions & 1 deletion ballsdex/packages/admin/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,45 @@
import logging
from typing import TYPE_CHECKING

from discord import app_commands

from ballsdex.packages.admin.cog import Admin

if TYPE_CHECKING:
from ballsdex.core.bot import BallsDexBot

log = logging.getLogger("ballsdex.packages.admin")


def command_count(cog: Admin) -> int:
total = 0
for command in cog.walk_app_commands():
total += len(command.name) + len(command.description)
if isinstance(command, app_commands.Group):
continue
for param in command.parameters:
total += len(param.name) + len(param.description)
for choice in param.choices:
total += len(choice.name) + (
int(choice.value)
if isinstance(choice.value, int | float)
else len(choice.value)
)
return total


def strip_descriptions(cog: Admin):
for command in cog.walk_app_commands():
command.description = "."
if isinstance(command, app_commands.Group):
continue
for param in command.parameters:
param._Parameter__parent.description = "." # type: ignore


async def setup(bot: "BallsDexBot"):
await bot.add_cog(Admin(bot))
n = Admin(bot)
if command_count(n) > 3900:
strip_descriptions(n)
log.warn("/admin command too long, stripping descriptions")
await bot.add_cog(n)

0 comments on commit b18ab77

Please sign in to comment.