Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Case insensitive prefix #351

Merged
merged 4 commits into from
Nov 27, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion lightbulb/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -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",
)
Expand All @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -965,9 +970,14 @@ async def get_prefix_context(
prefixes = [prefixes]
prefixes = sorted(prefixes, key=len, reverse=True)

message = event.message.content
if self._case_insensitive_prefixes:
message = message.lower()
prefixes = [x.lower() for x in prefixes]
luanalatte marked this conversation as resolved.
Show resolved Hide resolved

invoked_prefix = None
for prefix in prefixes:
if event.message.content.startswith(prefix):
if message.startswith(prefix):
invoked_prefix = prefix
break

Expand Down
Loading