-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
admin: strip descriptions when going above limit
- Loading branch information
Showing
2 changed files
with
37 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = "2.11.0" | ||
__version__ = "2.11.1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |