PamGram/plugins/starrail/help.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

56 lines
2.1 KiB
Python
Raw Normal View History

2024-06-18 17:33:28 +00:00
from typing import List, Optional, TYPE_CHECKING
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
from core.plugin import Plugin, handler
from core.services.template.services import TemplateService
2024-06-18 17:33:28 +00:00
from gram_core.plugin.methods.inline_use_data import IInlineUseData
from utils.log import logger
2022-07-26 10:07:31 +00:00
__all__ = ("HelpPlugin",)
2024-06-18 17:33:28 +00:00
if TYPE_CHECKING:
from gram_core.services.template.models import RenderResult
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
2024-06-18 17:33:28 +00:00
async def get_help_render(self) -> "RenderResult":
return await self.template_service.render(
"bot/help/help.html",
{"bot_username": self.application.bot.username},
{"width": 1280, "height": 900},
ttl=30 * 24 * 60 * 60,
)
@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)
async def start(self, update: Update, _: CallbackContext):
message = update.effective_message
2024-03-10 12:50:32 +00:00
self.log_user(update, logger.info, "发出help命令")
await message.reply_chat_action(ChatAction.TYPING)
2024-06-18 17:33:28 +00:00
render_result = await self.get_help_render()
await message.reply_chat_action(ChatAction.UPLOAD_PHOTO)
await render_result.reply_photo(message, filename="help.png")
2024-06-18 17:33:28 +00:00
async def start_use_by_inline(self, update: Update, _: CallbackContext):
callback_query = update.callback_query
self.log_user(update, logger.info, "发出help命令")
render_result = await self.get_help_render()
await render_result.edit_inline_media(callback_query)
async def get_inline_use_data(self) -> List[Optional[IInlineUseData]]:
return [
IInlineUseData(
text="帮助",
hash="help",
callback=self.start_use_by_inline,
)
]