1
Fork 0
mirror of https://github.com/wlinator/luminara.git synced 2024-10-02 20:43:12 +00:00
Lumi/lib/help.py

84 lines
3.2 KiB
Python
Raw Normal View History

2024-08-30 08:21:10 +00:00
import os
2024-08-29 14:02:50 +00:00
from collections.abc import Mapping
2024-08-30 08:21:10 +00:00
from pathlib import Path
2024-08-29 14:02:50 +00:00
from typing import Any
from discord.ext import commands
from lib.const import CONST
from lib.exceptions import LumiException
from ui.embeds import Builder
class LumiHelp(commands.HelpCommand):
def __init__(self, **options: Any) -> None:
super().__init__(**options)
self.verify_checks: bool = True
self.command_attrs: dict[str, list[str] | str | bool] = {
"aliases": ["h"],
"help": "Show a list of commands, or information about a specific command when an argument is passed.",
"name": "help",
"hidden": True,
}
def get_command_qualified_name(self, command: commands.Command[Any, Any, Any]) -> str:
return f"`{self.context.clean_prefix}{command.qualified_name}`"
async def send_bot_help(self, mapping: Mapping[commands.Cog | None, list[commands.Command[Any, ..., Any]]]) -> None:
embed = Builder.create_embed(
theme="success",
author_text="Help Command",
user_name=self.context.author.name,
hide_name_in_description=True,
)
2024-08-30 08:21:10 +00:00
modules_dir = Path(__file__).parent.parent / "modules"
module_names = [name for name in os.listdir(modules_dir) if Path(modules_dir / name).is_dir()]
2024-08-29 14:02:50 +00:00
2024-08-30 08:21:10 +00:00
for module_name in module_names:
module_commands: list[commands.Command[Any, ..., Any]] = []
for cog, lumi_commands in mapping.items():
if cog and cog.__module__.startswith(f"modules.{module_name}"):
filtered = await self.filter_commands(lumi_commands, sort=True)
module_commands.extend(filtered)
if module_commands:
command_signatures = [self.get_command_qualified_name(c) for c in module_commands]
unique_command_signatures = list(set(command_signatures))
2024-08-29 14:02:50 +00:00
embed.add_field(
2024-08-30 08:21:10 +00:00
name=module_name.capitalize(),
2024-08-29 14:02:50 +00:00
value=", ".join(sorted(unique_command_signatures)),
inline=False,
)
channel = self.get_destination()
await channel.send(embed=embed)
async def send_command_help(self, command: commands.Command[Any, Any, Any]) -> None:
embed = Builder.create_embed(
theme="success",
author_text=f"{self.context.clean_prefix}{command.qualified_name}",
description=command.description,
user_name=self.context.author.name,
hide_name_in_description=True,
)
usage_value: str = f"`{self.context.clean_prefix}{command.usage}`"
embed.add_field(name="Usage", value=usage_value, inline=False)
channel = self.get_destination()
await channel.send(embed=embed)
async def send_error_message(self, error: str) -> None:
raise LumiException(error)
async def send_group_help(self, group: commands.Group[Any, Any, Any]) -> None:
raise LumiException(
CONST.STRINGS["error_command_not_found"].format(group.qualified_name),
)
async def send_cog_help(self, cog: commands.Cog) -> None:
raise LumiException(
CONST.STRINGS["error_command_not_found"].format(cog.qualified_name),
)