diff --git a/lightbulb/app.py b/lightbulb/app.py index 039447e2..1d0d486b 100644 --- a/lightbulb/app.py +++ b/lightbulb/app.py @@ -166,6 +166,8 @@ class BotApp(hikari.GatewayBot): as well as a prefix command. Defaults to ``False``. delete_unbound_commands (:obj:`bool`): Whether or not the bot should delete application commands that it cannot find an implementation for when the bot starts. Defaults to ``True``. + case_insensitive_prefixes (:obj:`bool`): Wheter or not command prefixes should be case-insensitive. + Defaults to ``False``. case_insensitive_prefix_commands (:obj:`bool`): Whether or not prefix command names should be case-insensitive. Defaults to ``False``. **kwargs (Any): Additional keyword arguments passed to the constructor of the :obj:`~hikari.impl.gateway_bot.GatewayBot` @@ -189,6 +191,7 @@ class BotApp(hikari.GatewayBot): "default_enabled_guilds", "_help_command", "_delete_unbound_commands", + "_case_insensitive_prefixes", "_case_insensitive_prefix_commands", "_running_tasks", ) @@ -203,6 +206,7 @@ def __init__( help_class: t.Optional[t.Type[help_command_.BaseHelpCommand]] = help_command_.DefaultHelpCommand, help_slash_command: bool = False, delete_unbound_commands: bool = True, + case_insensitive_prefixes: bool = False, case_insensitive_prefix_commands: bool = False, **kwargs: t.Any, ) -> None: @@ -220,6 +224,7 @@ def __init__( ] = prefix self._delete_unbound_commands = delete_unbound_commands + self._case_insensitive_prefixes = case_insensitive_prefixes self._case_insensitive_prefix_commands = case_insensitive_prefix_commands self.ignore_bots: bool = ignore_bots @@ -964,12 +969,18 @@ async def get_prefix_context( prefixes = t.cast(t.Sequence[str], prefixes) if isinstance(prefixes, str): - prefixes = [prefixes] + prefixes = (prefixes,) + + message = event.message.content + if self._case_insensitive_prefixes: + message = message.lower() + prefixes = tuple(map(str.lower, prefixes)) + prefixes = sorted(prefixes, key=len, reverse=True) invoked_prefix = None for prefix in prefixes: - if event.message.content.startswith(prefix): + if message.startswith(prefix): invoked_prefix = prefix break