MibooGram/plugins/genshin/help.py

34 lines
1.3 KiB
Python
Raw Normal View History

2022-07-26 10:07:31 +00:00
from telegram import Update
from telegram.constants import ChatAction
from telegram.ext import CommandHandler, CallbackContext
from core.plugin import Plugin, handler
from core.template import TemplateService
2022-07-26 10:07:31 +00:00
from utils.decorators.error import error_callable
from utils.decorators.restricts import restricts
from utils.log import logger
2022-07-26 10:07:31 +00:00
class HelpPlugin(Plugin):
def __init__(self, template_service: TemplateService = None):
if template_service is None:
raise ModuleNotFoundError
self.template_service = template_service
2022-07-26 10:07:31 +00:00
@handler(CommandHandler, command="help", block=False)
2022-07-26 10:07:31 +00:00
@error_callable
@restricts()
2023-01-05 08:40:46 +00:00
async def start(self, update: Update, context: CallbackContext):
2022-07-26 10:07:31 +00:00
user = update.effective_user
message = update.effective_message
2023-01-05 08:40:46 +00:00
logger.info("用户 %s[%s] 发出help命令", user.full_name, user.id)
await message.reply_chat_action(ChatAction.TYPING)
render_result = await self.template_service.render(
2023-01-05 08:40:46 +00:00
"bot/help/help.html",
{"bot_username": context.bot.username},
{"width": 1280, "height": 900},
ttl=30 * 24 * 60 * 60,
)
await message.reply_chat_action(ChatAction.UPLOAD_PHOTO)
await render_result.reply_photo(message, filename="help.png", allow_sending_without_reply=True)