mirror of
https://github.com/cdryzun/tg_bot_collections.git
synced 2025-04-29 00:27:09 +08:00
Merge pull request #44 from F4ria/load_priority
This commit is contained in:
commit
23ad429cd2
@ -22,6 +22,8 @@ markdown_symbol.link = "🔗" # If you want, Customizing the link symbol
|
|||||||
|
|
||||||
T = TypeVar("T", bound=Callable)
|
T = TypeVar("T", bound=Callable)
|
||||||
|
|
||||||
|
DEFAULT_LOAD_PRIORITY = 10
|
||||||
|
|
||||||
BOT_MESSAGE_LENGTH = 4000
|
BOT_MESSAGE_LENGTH = 4000
|
||||||
|
|
||||||
REPLY_MESSAGE_CACHE = ExpiringDict(max_len=1000, max_age_seconds=300)
|
REPLY_MESSAGE_CACHE = ExpiringDict(max_len=1000, max_age_seconds=300)
|
||||||
@ -146,12 +148,18 @@ def wrap_handler(handler: T, bot: TeleBot) -> T:
|
|||||||
|
|
||||||
def load_handlers(bot: TeleBot, disable_commands: list[str]) -> None:
|
def load_handlers(bot: TeleBot, disable_commands: list[str]) -> None:
|
||||||
# import all submodules
|
# import all submodules
|
||||||
|
modules_with_priority = []
|
||||||
for name in list_available_commands():
|
for name in list_available_commands():
|
||||||
if name in disable_commands:
|
if name in disable_commands:
|
||||||
continue
|
continue
|
||||||
module = importlib.import_module(f".{name}", __package__)
|
module = importlib.import_module(f".{name}", __package__)
|
||||||
|
load_priority = getattr(module, "load_priority", DEFAULT_LOAD_PRIORITY)
|
||||||
|
modules_with_priority.append((module, name, load_priority))
|
||||||
|
|
||||||
|
modules_with_priority.sort(key=lambda x: x[-1])
|
||||||
|
for module, name, priority in modules_with_priority:
|
||||||
if hasattr(module, "register"):
|
if hasattr(module, "register"):
|
||||||
print(f"Loading {name} handlers.")
|
print(f"Loading {name} handlers with priority {priority}.")
|
||||||
module.register(bot)
|
module.register(bot)
|
||||||
print("Loading handlers done.")
|
print("Loading handlers done.")
|
||||||
|
|
||||||
|
@ -13,6 +13,9 @@ from . import *
|
|||||||
|
|
||||||
from telegramify_markdown.customize import markdown_symbol
|
from telegramify_markdown.customize import markdown_symbol
|
||||||
|
|
||||||
|
# Define the load priority, lower numbers have higher priority
|
||||||
|
load_priority = 1000
|
||||||
|
|
||||||
# If you want, Customizing the head level 1 symbol
|
# If you want, Customizing the head level 1 symbol
|
||||||
markdown_symbol.head_level_1 = "📌"
|
markdown_symbol.head_level_1 = "📌"
|
||||||
markdown_symbol.link = "🔗" # If you want, Customizing the link symbol
|
markdown_symbol.link = "🔗" # If you want, Customizing the link symbol
|
||||||
@ -196,7 +199,7 @@ def latest_handle_messages(message: Message, bot: TeleBot):
|
|||||||
elif message.text.startswith(
|
elif message.text.startswith(
|
||||||
(
|
(
|
||||||
"md",
|
"md",
|
||||||
"chatgpt",
|
"gpt",
|
||||||
"gemini",
|
"gemini",
|
||||||
"qwen",
|
"qwen",
|
||||||
"map",
|
"map",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user