Skip to content

Commit

Permalink
Small simplification
Browse files Browse the repository at this point in the history
  • Loading branch information
FasterSpeeding committed Jul 14, 2024
1 parent 7a0f75b commit 638e0d0
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions tanchan/components/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,10 +298,12 @@ def ctx_to_kwargs(self, ctx: typing.Union[yuyo.interactions.BaseContext[hikari.C


def reload(
client: tanjun.abc.Client,
static_index: yuyo.StaticPaginatorIndex,
help_config: config.HelpConfig,
_: typing.Optional[tanjun.abc.Component] = None,
/,
*,
client: alluka.Injected[tanjun.abc.Client],
static_index: alluka.Injected[yuyo.StaticPaginatorIndex],
help_config: alluka.Injected[config.HelpConfig] = _DEFAULT_CONFIG,
) -> None:
"""Rebuild the help command's index to account for changes."""
categories: dict[str, list[tuple[str, _internal.MaybeLocalised]]] = {}
Expand Down Expand Up @@ -379,16 +381,6 @@ def find_command(self, command_name: str, /) -> typing.Optional[_internal.MaybeL



async def on_component_change(
_: tanjun.abc.Component,
*,
client: alluka.Injected[tanjun.abc.Client],
static_index: alluka.Injected[yuyo.StaticPaginatorIndex],
help_config: alluka.Injected[config.HelpConfig] = _DEFAULT_CONFIG,
) -> None:
"""Event listener which handles component changes."""
return reload(client, static_index, help_config)


# TODO: this feels very inefficient
def _collect_msg_cmds(
Expand Down Expand Up @@ -552,8 +544,8 @@ def load_help(client: tanjun.abc.Client) -> None:

client.add_component(component)

client.add_client_callback(tanjun.ClientCallbackNames.COMPONENT_ADDED, on_component_change)
client.add_client_callback(tanjun.ClientCallbackNames.COMPONENT_REMOVED, on_component_change)
client.add_client_callback(tanjun.ClientCallbackNames.COMPONENT_ADDED, reload)
client.add_client_callback(tanjun.ClientCallbackNames.COMPONENT_REMOVED, reload)

component_client = _internal.get_or_set_dep(client.injector, yuyo.ComponentClient, yuyo.ComponentClient)
modal_client = _internal.get_or_set_dep(client.injector, yuyo.ModalClient, yuyo.ModalClient)
Expand All @@ -564,7 +556,7 @@ def load_help(client: tanjun.abc.Client) -> None:
except KeyError:
static_index = yuyo.StaticPaginatorIndex().add_to_clients(component_client, modal_client)

reload(client, static_index, help_config)
reload(client=client, static_index=static_index, help_config=help_config)


# TODO: better document help.py and eval.py
Expand Down

0 comments on commit 638e0d0

Please sign in to comment.