2022-07-26 10:07:31 +00:00
|
|
|
from telegram import Update
|
|
|
|
from telegram.constants import ChatAction
|
2023-12-24 13:26:36 +00:00
|
|
|
from telegram.ext import CallbackContext, filters
|
2022-07-26 10:07:31 +00:00
|
|
|
|
2022-09-08 01:08:37 +00:00
|
|
|
from core.plugin import Plugin, handler
|
2023-03-14 01:27:22 +00:00
|
|
|
from core.services.template.services import TemplateService
|
2022-09-08 01:08:37 +00:00
|
|
|
from utils.log import logger
|
2022-07-26 10:07:31 +00:00
|
|
|
|
2023-03-14 01:27:22 +00:00
|
|
|
__all__ = ("HelpPlugin",)
|
|
|
|
|
2022-07-26 10:07:31 +00:00
|
|
|
|
2022-09-08 01:08:37 +00:00
|
|
|
class HelpPlugin(Plugin):
|
2022-09-02 08:27:54 +00:00
|
|
|
def __init__(self, template_service: TemplateService = None):
|
2022-09-08 01:08:37 +00:00
|
|
|
if template_service is None:
|
|
|
|
raise ModuleNotFoundError
|
|
|
|
self.template_service = template_service
|
2022-07-26 10:07:31 +00:00
|
|
|
|
2023-03-14 01:27:22 +00:00
|
|
|
@handler.command(command="help", block=False)
|
2023-12-24 13:26:36 +00:00
|
|
|
@handler.command(command="start", filters=filters.Regex("inline_message$"), block=False)
|
2023-03-14 01:27:22 +00:00
|
|
|
async def start(self, update: Update, _: CallbackContext):
|
2022-09-08 01:08:37 +00:00
|
|
|
message = update.effective_message
|
2024-03-10 12:40:26 +00:00
|
|
|
self.log_user(update, logger.info, "发出help命令")
|
2022-10-22 07:03:59 +00:00
|
|
|
await message.reply_chat_action(ChatAction.TYPING)
|
|
|
|
render_result = await self.template_service.render(
|
2023-05-09 11:01:45 +00:00
|
|
|
"bot/help/help.jinja2",
|
2023-03-14 01:27:22 +00:00
|
|
|
{"bot_username": self.application.bot.username},
|
2023-01-05 08:40:46 +00:00
|
|
|
{"width": 1280, "height": 900},
|
|
|
|
ttl=30 * 24 * 60 * 60,
|
2022-10-22 07:03:59 +00:00
|
|
|
)
|
|
|
|
await message.reply_chat_action(ChatAction.UPLOAD_PHOTO)
|
2024-06-10 16:58:39 +00:00
|
|
|
await render_result.reply_photo(message, filename="help.png")
|