mirror of
https://github.com/cdryzun/tg_bot_collections.git
synced 2025-04-29 00:27:09 +08:00
add some comments
Signed-off-by: Frost Ming <me@frostming.com>
This commit is contained in:
parent
7a46a22262
commit
7af312834c
@ -22,14 +22,14 @@ def extract_prompt(message: str, bot_name: str) -> str:
|
|||||||
"""
|
"""
|
||||||
# remove '@bot_name' as it is considered part of the command when in a group chat.
|
# remove '@bot_name' as it is considered part of the command when in a group chat.
|
||||||
message = re.sub(re.escape(f"@{bot_name}"), "", message).strip()
|
message = re.sub(re.escape(f"@{bot_name}"), "", message).strip()
|
||||||
# add a whitespace after the first colon to make sure it is separated from the prompt.
|
# add a whitespace after the first colon as we separate the prompt from the command by the first whitespace.
|
||||||
message = re.sub(":", ": ", message, count=1).strip()
|
message = re.sub(":", ": ", message, count=1).strip()
|
||||||
try:
|
try:
|
||||||
left, message = message.split(maxsplit=1)
|
left, message = message.split(maxsplit=1)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
return ""
|
return ""
|
||||||
if ":" not in left:
|
if ":" not in left:
|
||||||
# restore the added space
|
# the replacement happens in the right part, restore it.
|
||||||
message = message.replace(": ", ":", 1)
|
message = message.replace(": ", ":", 1)
|
||||||
return message.strip()
|
return message.strip()
|
||||||
|
|
||||||
@ -70,6 +70,7 @@ def load_handlers(bot: TeleBot) -> None:
|
|||||||
all_commands: list[BotCommand] = []
|
all_commands: list[BotCommand] = []
|
||||||
for handler in bot.message_handlers:
|
for handler in bot.message_handlers:
|
||||||
help_text = getattr(handler["function"], "__doc__", "")
|
help_text = getattr(handler["function"], "__doc__", "")
|
||||||
|
# Add pre-processing and error handling to all callbacks
|
||||||
handler["function"] = wrap_handler(handler["function"], bot)
|
handler["function"] = wrap_handler(handler["function"], bot)
|
||||||
for command in handler["filters"].get("commands", []):
|
for command in handler["filters"].get("commands", []):
|
||||||
all_commands.append(BotCommand(command, help_text))
|
all_commands.append(BotCommand(command, help_text))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user