mirror of
https://github.com/PaiGramTeam/PaiGram.git
synced 2024-11-23 00:01:45 +00:00
f122e21092
* 增加 html to image 缓存 * 对 template_service.render 进行封装,管理缓存逻辑 * cache key 为 html 的 sha256 * cache value 为 reply_photo 后 telegram 返回的 file_id * 存入 redis,并设置合理的 ttl Co-authored-by: 洛水居室 <luoshuijs@outlook.com> Co-authored-by: xtaodada <xtao@xtaolink.cn>
31 lines
1.2 KiB
Python
31 lines
1.2 KiB
Python
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
|
|
from utils.decorators.error import error_callable
|
|
from utils.decorators.restricts import restricts
|
|
from utils.log import logger
|
|
|
|
|
|
class HelpPlugin(Plugin):
|
|
def __init__(self, template_service: TemplateService = None):
|
|
if template_service is None:
|
|
raise ModuleNotFoundError
|
|
self.template_service = template_service
|
|
|
|
@handler(CommandHandler, command="help", block=False)
|
|
@error_callable
|
|
@restricts()
|
|
async def start(self, update: Update, _: CallbackContext):
|
|
user = update.effective_user
|
|
message = update.effective_message
|
|
logger.info(f"用户 {user.full_name}[{user.id}] 发出help命令")
|
|
await message.reply_chat_action(ChatAction.TYPING)
|
|
render_result = await self.template_service.render(
|
|
"bot/help/help.html", {}, {"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)
|