From 9d119c6073695c9e4088a260d3771b647fef3f45 Mon Sep 17 00:00:00 2001 From: xtaodada Date: Mon, 19 Feb 2024 20:55:13 +0800 Subject: [PATCH] :sparkles: Add tasks button when query daily note --- plugins/starrail/daily_note.py | 18 +++++++++++++++--- plugins/starrail/daily_note_tasks.py | 1 + 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/plugins/starrail/daily_note.py b/plugins/starrail/daily_note.py index eeca164..77d5161 100644 --- a/plugins/starrail/daily_note.py +++ b/plugins/starrail/daily_note.py @@ -3,9 +3,10 @@ from datetime import datetime from typing import Optional, TYPE_CHECKING from simnet.errors import DataNotPublic -from telegram import Update +from telegram import Update, InlineKeyboardMarkup, InlineKeyboardButton from telegram.constants import ChatAction from telegram.ext import ConversationHandler, filters, CallbackContext +from telegram.helpers import create_deep_linked_url from core.plugin import Plugin, handler from core.services.template.models import RenderResult @@ -80,9 +81,15 @@ class DailyNotePlugin(Plugin): ) return render_result + @staticmethod + def get_task_button(bot_username: str) -> InlineKeyboardMarkup: + return InlineKeyboardMarkup( + [[InlineKeyboardButton(">> 设置状态提醒 <<", url=create_deep_linked_url(bot_username, "daily_note_tasks"))]] + ) + @handler.command("dailynote", block=False) @handler.message(filters.Regex("^当前状态(.*)"), block=False) - async def command_start(self, update: Update, _: CallbackContext) -> Optional[int]: + async def command_start(self, update: Update, context: CallbackContext) -> Optional[int]: message = update.effective_message user = update.effective_user logger.info("用户 %s[%s] 每日便签命令请求", user.full_name, user.id) @@ -98,4 +105,9 @@ class DailyNotePlugin(Plugin): return ConversationHandler.END await message.reply_chat_action(ChatAction.UPLOAD_PHOTO) - await render_result.reply_photo(message, filename=f"{client.player_id}.png", allow_sending_without_reply=True) + await render_result.reply_photo( + message, + filename=f"{client.player_id}.png", + allow_sending_without_reply=True, + reply_markup=self.get_task_button(context.bot.username), + ) diff --git a/plugins/starrail/daily_note_tasks.py b/plugins/starrail/daily_note_tasks.py index 17e8860..1ea80e8 100644 --- a/plugins/starrail/daily_note_tasks.py +++ b/plugins/starrail/daily_note_tasks.py @@ -44,6 +44,7 @@ class DailyNoteTasksPlugin(Plugin.Conversation): @conversation.entry_point @handler.command(command="daily_note_tasks", filters=filters.ChatType.PRIVATE, block=False) + @handler.command(command="start", filters=filters.Regex(r"daily_note_tasks$"), block=False) async def command_start(self, update: Update, _: CallbackContext) -> int: user = update.effective_user message = update.effective_message