2022-05-28 12:31:44 +00:00
|
|
|
|
from telegram import Update
|
2022-05-30 08:08:56 +00:00
|
|
|
|
from telegram.constants import ChatAction
|
2022-05-30 14:29:03 +00:00
|
|
|
|
from telegram.error import BadRequest
|
2022-07-07 01:36:34 +00:00
|
|
|
|
from telegram.ext import CommandHandler
|
2022-05-28 12:31:44 +00:00
|
|
|
|
|
|
|
|
|
from config import config
|
|
|
|
|
from logger import Log
|
2022-07-07 01:36:34 +00:00
|
|
|
|
from manager import listener_plugins_class
|
2022-06-24 11:48:19 +00:00
|
|
|
|
from plugins.base import restricts
|
|
|
|
|
from utils.base import PaimonContext
|
2022-05-28 12:31:44 +00:00
|
|
|
|
|
|
|
|
|
|
2022-07-07 01:36:34 +00:00
|
|
|
|
@listener_plugins_class()
|
2022-06-24 11:48:19 +00:00
|
|
|
|
class Help:
|
2022-06-09 12:52:59 +00:00
|
|
|
|
"""
|
|
|
|
|
帮助
|
|
|
|
|
"""
|
|
|
|
|
|
2022-06-24 11:48:19 +00:00
|
|
|
|
def __init__(self):
|
2022-05-28 12:31:44 +00:00
|
|
|
|
self.help_png = None
|
2022-05-28 12:53:54 +00:00
|
|
|
|
self.file_id = None
|
2022-05-28 12:31:44 +00:00
|
|
|
|
|
2022-07-07 01:36:34 +00:00
|
|
|
|
@classmethod
|
|
|
|
|
def create_handlers(cls) -> list:
|
|
|
|
|
_help = cls()
|
|
|
|
|
return [
|
|
|
|
|
CommandHandler("help", _help.command_start, block=False),
|
|
|
|
|
]
|
|
|
|
|
|
2022-06-22 13:33:07 +00:00
|
|
|
|
@restricts()
|
2022-06-24 11:48:19 +00:00
|
|
|
|
async def command_start(self, update: Update, context: PaimonContext) -> None:
|
2022-05-28 12:31:44 +00:00
|
|
|
|
message = update.message
|
|
|
|
|
user = update.effective_user
|
2022-06-24 11:48:19 +00:00
|
|
|
|
service = context.service
|
2022-05-30 08:08:56 +00:00
|
|
|
|
Log.info(f"用户 {user.full_name}[{user.id}] 发出help命令")
|
2022-05-28 12:53:54 +00:00
|
|
|
|
if self.file_id is None or config.DEBUG:
|
2022-05-30 08:08:56 +00:00
|
|
|
|
await message.reply_chat_action(ChatAction.TYPING)
|
2022-06-24 11:48:19 +00:00
|
|
|
|
help_png = await service.template.render('bot/help', "help.html", {}, {"width": 768, "height": 768})
|
2022-05-30 08:08:56 +00:00
|
|
|
|
await message.reply_chat_action(ChatAction.UPLOAD_PHOTO)
|
2022-05-28 17:03:13 +00:00
|
|
|
|
reply_photo = await message.reply_photo(help_png, filename="help.png", allow_sending_without_reply=True)
|
2022-05-28 12:53:54 +00:00
|
|
|
|
photo = reply_photo.photo[0]
|
|
|
|
|
self.file_id = photo.file_id
|
|
|
|
|
else:
|
2022-05-28 12:56:47 +00:00
|
|
|
|
try:
|
2022-05-30 08:08:56 +00:00
|
|
|
|
await message.reply_chat_action(ChatAction.UPLOAD_PHOTO)
|
2022-05-28 12:56:47 +00:00
|
|
|
|
await message.reply_photo(self.file_id, allow_sending_without_reply=True)
|
|
|
|
|
except BadRequest as error:
|
|
|
|
|
self.file_id = None
|
2022-06-10 08:47:32 +00:00
|
|
|
|
Log.error("发送图片失败,尝试清空已经保存的file_id,错误信息为", error)
|
2022-05-28 12:56:47 +00:00
|
|
|
|
await message.reply_text("发送图片失败", allow_sending_without_reply=True)
|