From a2656d2df7ea79be37f80d1124274399d9fa7500 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B4=9B=E6=B0=B4=E5=B1=85=E5=AE=A4?= Date: Mon, 28 Nov 2022 16:38:49 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Use=20`create=5Fdeep=5Flinked=5Furl?= =?UTF-8?q?`=20to=20create=20url?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/genshin/abyss.py | 3 ++- plugins/genshin/abyss_team.py | 3 ++- plugins/genshin/avatar_list.py | 5 +++-- plugins/genshin/daily_note.py | 3 ++- plugins/genshin/gacha/gacha_log.py | 15 ++++++++------- plugins/genshin/ledger.py | 3 ++- plugins/genshin/map/map.py | 3 ++- plugins/genshin/player_cards.py | 3 ++- plugins/genshin/sign.py | 6 +++--- plugins/genshin/userstats.py | 3 ++- utils/decorators/error.py | 5 +++-- 11 files changed, 31 insertions(+), 21 deletions(-) diff --git a/plugins/genshin/abyss.py b/plugins/genshin/abyss.py index cd84273..4273e8d 100644 --- a/plugins/genshin/abyss.py +++ b/plugins/genshin/abyss.py @@ -12,6 +12,7 @@ from pytz import timezone from telegram import InlineKeyboardButton, InlineKeyboardMarkup, Message, Update from telegram.constants import ChatAction, ParseMode from telegram.ext import CallbackContext, filters +from telegram.helpers import create_deep_linked_url from core.base.assets import AssetsService from core.baseplugin import BasePlugin @@ -135,7 +136,7 @@ class Abyss(Plugin, BasePlugin): except CookiesNotFoundError: client, uid = await get_public_genshin_client(user.id) except UserNotFoundError: # 若未找到账号 - buttons = [[InlineKeyboardButton("点我绑定账号", url=f"https://t.me/{context.bot.username}?start=set_uid")]] + buttons = [[InlineKeyboardButton("点我绑定账号", url=create_deep_linked_url(context.bot.username, "set_uid"))]] if filters.ChatType.GROUPS.filter(message): reply_message = await message.reply_text( "未查询到您所绑定的账号信息,请先私聊派蒙绑定账号", reply_markup=InlineKeyboardMarkup(buttons) diff --git a/plugins/genshin/abyss_team.py b/plugins/genshin/abyss_team.py index ba038f6..495f5c6 100644 --- a/plugins/genshin/abyss_team.py +++ b/plugins/genshin/abyss_team.py @@ -1,6 +1,7 @@ from telegram import Update, InlineKeyboardMarkup, InlineKeyboardButton from telegram.constants import ChatAction from telegram.ext import CallbackContext, CommandHandler, MessageHandler, filters +from telegram.helpers import create_deep_linked_url from core.base.assets import AssetsService from core.baseplugin import BasePlugin @@ -40,7 +41,7 @@ class AbyssTeam(Plugin, BasePlugin): try: client = await get_genshin_client(user.id) except (CookiesNotFoundError, UserNotFoundError): - buttons = [[InlineKeyboardButton("点我绑定账号", url=f"https://t.me/{context.bot.username}?start=set_cookie")]] + buttons = [[InlineKeyboardButton("点我绑定账号", url=create_deep_linked_url(context.bot.username, "set_cookie"))]] if filters.ChatType.GROUPS.filter(message): reply_message = await message.reply_text( "未查询到您所绑定的账号信息,请先私聊派蒙绑定账号", reply_markup=InlineKeyboardMarkup(buttons) diff --git a/plugins/genshin/avatar_list.py b/plugins/genshin/avatar_list.py index cd2f2d5..cc1e42c 100644 --- a/plugins/genshin/avatar_list.py +++ b/plugins/genshin/avatar_list.py @@ -9,6 +9,7 @@ from genshin.models import CalculatorCharacterDetails, CalculatorTalent, Charact from telegram import InlineKeyboardButton, InlineKeyboardMarkup, Message, Update, User from telegram.constants import ChatAction, ParseMode from telegram.ext import CallbackContext, filters +from telegram.helpers import create_deep_linked_url from core.base.assets import AssetsService from core.baseplugin import BasePlugin @@ -41,7 +42,7 @@ class AvatarListPlugin(Plugin, BasePlugin): try: return await get_genshin_client(user.id) except UserNotFoundError: # 若未找到账号 - buttons = [[InlineKeyboardButton("点我绑定账号", url=f"https://t.me/{context.bot.username}?start=set_cookie")]] + buttons = [[InlineKeyboardButton("点我绑定账号", url=create_deep_linked_url(context.bot.username, "set_cookie"))]] if filters.ChatType.GROUPS.filter(message): reply_message = await message.reply_text( "未查询到您所绑定的账号信息,请先私聊派蒙绑定账号", reply_markup=InlineKeyboardMarkup(buttons) @@ -52,7 +53,7 @@ class AvatarListPlugin(Plugin, BasePlugin): else: await message.reply_text("未查询到您所绑定的账号信息,请先绑定账号", reply_markup=InlineKeyboardMarkup(buttons)) except CookiesNotFoundError: - buttons = [[InlineKeyboardButton("点我绑定账号", url=f"https://t.me/{context.bot.username}?start=set_cookie")]] + buttons = [[InlineKeyboardButton("点我绑定账号", url=create_deep_linked_url(context.bot.username, "set_cookie"))]] if filters.ChatType.GROUPS.filter(message): reply_msg = await message.reply_text( "此功能需要绑定cookie后使用,请先私聊派蒙绑定账号", diff --git a/plugins/genshin/daily_note.py b/plugins/genshin/daily_note.py index 95f43a5..e88cd16 100644 --- a/plugins/genshin/daily_note.py +++ b/plugins/genshin/daily_note.py @@ -6,6 +6,7 @@ from genshin import DataNotPublic from telegram import Update, InlineKeyboardButton, InlineKeyboardMarkup from telegram.constants import ChatAction from telegram.ext import CommandHandler, MessageHandler, ConversationHandler, filters, CallbackContext +from telegram.helpers import create_deep_linked_url from core.baseplugin import BasePlugin from core.cookies.error import CookiesNotFoundError @@ -102,7 +103,7 @@ class DailyNote(Plugin, BasePlugin): client = await get_genshin_client(user.id) render_result = await self._get_daily_note(client) except (UserNotFoundError, CookiesNotFoundError): - buttons = [[InlineKeyboardButton("点我绑定账号", url=f"https://t.me/{context.bot.username}?start=set_cookie")]] + buttons = [[InlineKeyboardButton("点我绑定账号", url=create_deep_linked_url(context.bot.username, "set_cookie"))]] if filters.ChatType.GROUPS.filter(message): reply_message = await message.reply_text( "未查询到您所绑定的账号信息,请先私聊派蒙绑定账号", reply_markup=InlineKeyboardMarkup(buttons) diff --git a/plugins/genshin/gacha/gacha_log.py b/plugins/genshin/gacha/gacha_log.py index a4a6eae..6f5abdb 100644 --- a/plugins/genshin/gacha/gacha_log.py +++ b/plugins/genshin/gacha/gacha_log.py @@ -7,6 +7,7 @@ from genshin.models import BannerType from telegram import Update, User, Message, Document, InlineKeyboardButton, InlineKeyboardMarkup from telegram.constants import ChatAction from telegram.ext import CallbackContext, CommandHandler, MessageHandler, filters, ConversationHandler +from telegram.helpers import create_deep_linked_url from core.base.assets import AssetsService from core.baseplugin import BasePlugin @@ -232,7 +233,7 @@ class GachaLogPlugin(Plugin.Conversation, BasePlugin.Conversation): context.chat_data["uid"] = client.uid except UserNotFoundError: logger.info(f"未查询到用户({user.full_name} {user.id}) 所绑定的账号信息") - buttons = [[InlineKeyboardButton("点我绑定账号", url=f"https://t.me/{context.bot.username}?start=set_uid")]] + buttons = [[InlineKeyboardButton("点我绑定账号", url=create_deep_linked_url(context.bot.username, "set_uid"))]] if filters.ChatType.GROUPS.filter(message): reply_message = await message.reply_text( "未查询到您所绑定的账号信息,请先私聊派蒙绑定账号", reply_markup=InlineKeyboardMarkup(buttons) @@ -306,7 +307,7 @@ class GachaLogPlugin(Plugin.Conversation, BasePlugin.Conversation): await message.reply_document(document=open(path, "rb+"), caption="抽卡记录导出文件 - UIGF V2.2") except GachaLogNotFound: buttons = [ - [InlineKeyboardButton("点我导入", url=f"https://t.me/{context.bot.username}?start=gacha_log_import")] + [InlineKeyboardButton("点我导入", url=create_deep_linked_url(context.bot.username, "gacha_log_import"))] ] await message.reply_text("派蒙没有找到你的抽卡记录,快来私聊派蒙导入吧~", reply_markup=InlineKeyboardMarkup(buttons)) except GachaLogAccountNotFound: @@ -315,7 +316,7 @@ class GachaLogPlugin(Plugin.Conversation, BasePlugin.Conversation): await message.reply_text("导入失败,数据格式错误") except UserNotFoundError: logger.info(f"未查询到用户({user.full_name} {user.id}) 所绑定的账号信息") - buttons = [[InlineKeyboardButton("点我绑定账号", url=f"https://t.me/{context.bot.username}?start=set_uid")]] + buttons = [[InlineKeyboardButton("点我绑定账号", url=create_deep_linked_url(context.bot.username, "set_uid"))]] if filters.ChatType.GROUPS.filter(message): reply_message = await message.reply_text( "未查询到您所绑定的账号信息,请先私聊派蒙绑定账号", reply_markup=InlineKeyboardMarkup(buttons) @@ -357,12 +358,12 @@ class GachaLogPlugin(Plugin.Conversation, BasePlugin.Conversation): await png_data.reply_photo(message) except GachaLogNotFound: buttons = [ - [InlineKeyboardButton("点我导入", url=f"https://t.me/{context.bot.username}?start=gacha_log_import")] + [InlineKeyboardButton("点我导入", url=create_deep_linked_url(context.bot.username, "gacha_log_import"))] ] await message.reply_text("派蒙没有找到你的抽卡记录,快来点击按钮私聊派蒙导入吧~", reply_markup=InlineKeyboardMarkup(buttons)) except UserNotFoundError: logger.info(f"未查询到用户({user.full_name} {user.id}) 所绑定的账号信息") - buttons = [[InlineKeyboardButton("点我绑定账号", url=f"https://t.me/{context.bot.username}?start=set_uid")]] + buttons = [[InlineKeyboardButton("点我绑定账号", url=create_deep_linked_url(context.bot.username, "set_uid"))]] if filters.ChatType.GROUPS.filter(message): reply_message = await message.reply_text( "未查询到您所绑定的账号信息,请先私聊派蒙绑定账号", reply_markup=InlineKeyboardMarkup(buttons) @@ -422,12 +423,12 @@ class GachaLogPlugin(Plugin.Conversation, BasePlugin.Conversation): await png_data.reply_photo(message) except GachaLogNotFound: buttons = [ - [InlineKeyboardButton("点我导入", url=f"https://t.me/{context.bot.username}?start=gacha_log_import")] + [InlineKeyboardButton("点我导入", url=create_deep_linked_url(context.bot.username, "gacha_log_import"))] ] await message.reply_text("派蒙没有找到你的抽卡记录,快来私聊派蒙导入吧~", reply_markup=InlineKeyboardMarkup(buttons)) except (UserNotFoundError): logger.info(f"未查询到用户({user.full_name} {user.id}) 所绑定的账号信息") - buttons = [[InlineKeyboardButton("点我绑定账号", url=f"https://t.me/{context.bot.username}?start=set_uid")]] + buttons = [[InlineKeyboardButton("点我绑定账号", url=create_deep_linked_url(context.bot.username, "set_uid"))]] if filters.ChatType.GROUPS.filter(message): reply_message = await message.reply_text( "未查询到您所绑定的账号信息,请先私聊派蒙绑定账号", reply_markup=InlineKeyboardMarkup(buttons) diff --git a/plugins/genshin/ledger.py b/plugins/genshin/ledger.py index 2d70bfa..6af80c4 100644 --- a/plugins/genshin/ledger.py +++ b/plugins/genshin/ledger.py @@ -6,6 +6,7 @@ from genshin import GenshinException, DataNotPublic from telegram import Update, InlineKeyboardMarkup, InlineKeyboardButton from telegram.constants import ChatAction from telegram.ext import CallbackContext, CommandHandler, MessageHandler, filters +from telegram.helpers import create_deep_linked_url from core.baseplugin import BasePlugin from core.cookies.error import CookiesNotFoundError @@ -124,7 +125,7 @@ class Ledger(Plugin, BasePlugin): client = await get_genshin_client(user.id) render_result = await self._start_get_ledger(client, month) except (UserNotFoundError, CookiesNotFoundError): - buttons = [[InlineKeyboardButton("点我绑定账号", url=f"https://t.me/{context.bot.username}?start=set_cookie")]] + buttons = [[InlineKeyboardButton("点我绑定账号", url=create_deep_linked_url(context.bot.username, "set_cookie"))]] if filters.ChatType.GROUPS.filter(message): reply_message = await message.reply_text( "未查询到您所绑定的账号信息,请先私聊派蒙绑定账号", reply_markup=InlineKeyboardMarkup(buttons) diff --git a/plugins/genshin/map/map.py b/plugins/genshin/map/map.py index fbdc63b..56a8f74 100644 --- a/plugins/genshin/map/map.py +++ b/plugins/genshin/map/map.py @@ -4,6 +4,7 @@ from PIL import Image from telegram import Update, InlineKeyboardButton, InlineKeyboardMarkup from telegram.constants import ChatAction from telegram.ext import CommandHandler, MessageHandler, filters, CallbackContext +from telegram.helpers import create_deep_linked_url from core.baseplugin import BasePlugin from core.plugin import handler, Plugin @@ -45,7 +46,7 @@ class Map(Plugin, BasePlugin): return if resource_name in ("list", "列表"): if filters.ChatType.GROUPS.filter(message): - buttons = [[InlineKeyboardButton("点我私聊", url=f"https://t.me/{context.bot.username}")]] + buttons = [[InlineKeyboardButton("点我私聊", url=create_deep_linked_url(context.bot.username))]] reply_message = await message.reply_text("请私聊派蒙使用该命令", reply_markup=InlineKeyboardMarkup(buttons)) self._add_delete_message_job(context, reply_message.chat_id, reply_message.message_id, 300) self._add_delete_message_job(context, message.chat_id, message.message_id, 300) diff --git a/plugins/genshin/player_cards.py b/plugins/genshin/player_cards.py index f18c9cd..481e195 100644 --- a/plugins/genshin/player_cards.py +++ b/plugins/genshin/player_cards.py @@ -20,6 +20,7 @@ from pydantic import BaseModel from telegram import InlineKeyboardButton, InlineKeyboardMarkup, Update from telegram.constants import ChatAction from telegram.ext import CallbackContext, CallbackQueryHandler, CommandHandler, MessageHandler, filters +from telegram.helpers import create_deep_linked_url from core.base.assets import DEFAULT_EnkaAssets from core.baseplugin import BasePlugin @@ -76,7 +77,7 @@ class PlayerCards(Plugin, BasePlugin): else: uid = user_info.genshin_uid except UserNotFoundError: - buttons = [[InlineKeyboardButton("点我绑定账号", url=f"https://t.me/{context.bot.username}?start=set_uid")]] + buttons = [[InlineKeyboardButton("点我绑定账号", url=create_deep_linked_url(context.bot.username, "set_uid"))]] if filters.ChatType.GROUPS.filter(message): reply_message = await message.reply_text( "未查询到您所绑定的账号信息,请先私聊派蒙绑定账号", reply_markup=InlineKeyboardMarkup(buttons) diff --git a/plugins/genshin/sign.py b/plugins/genshin/sign.py index 1c03406..4167047 100644 --- a/plugins/genshin/sign.py +++ b/plugins/genshin/sign.py @@ -12,6 +12,7 @@ from telegram import Update, InlineKeyboardButton, InlineKeyboardMarkup from telegram.constants import ChatAction from telegram.ext import CommandHandler, CallbackContext, CallbackQueryHandler from telegram.ext import MessageHandler, filters +from telegram.helpers import create_deep_linked_url from core.admin.services import BotAdminService from core.base.redisdb import RedisDB @@ -387,7 +388,7 @@ class Sign(Plugin, BasePlugin): if filters.ChatType.GROUPS.filter(reply_message): self._add_delete_message_job(context, reply_message.chat_id, reply_message.message_id) except (UserNotFoundError, CookiesNotFoundError): - buttons = [[InlineKeyboardButton("点我绑定账号", url=f"https://t.me/{context.bot.username}?start=set_cookie")]] + buttons = [[InlineKeyboardButton("点我绑定账号", url=create_deep_linked_url(context.bot.username, "set_cookie"))]] if filters.ChatType.GROUPS.filter(message): reply_message = await message.reply_text( "未查询到您所绑定的账号信息,请先私聊派蒙绑定账号", reply_markup=InlineKeyboardMarkup(buttons) @@ -429,5 +430,4 @@ class Sign(Plugin, BasePlugin): if not challenge: await callback_query.answer(text="验证请求已经过期,请重新发起签到!", show_alert=True) return - url = f"t.me/{bot.app.bot.username}?start=sign" - await callback_query.answer(url=url) + await callback_query.answer(url=create_deep_linked_url(bot.app.bot.username, "sign")) diff --git a/plugins/genshin/userstats.py b/plugins/genshin/userstats.py index 61ac31f..f6c1c52 100644 --- a/plugins/genshin/userstats.py +++ b/plugins/genshin/userstats.py @@ -11,6 +11,7 @@ from telegram.ext import ( MessageHandler, filters, ) +from telegram.helpers import create_deep_linked_url from core.baseplugin import BasePlugin from core.cookies.error import CookiesNotFoundError, TooManyRequestPublicCookies @@ -54,7 +55,7 @@ class UserStatsPlugins(Plugin, BasePlugin): client, uid = await get_public_genshin_client(user.id) render_result = await self.render(client, uid) except UserNotFoundError: - buttons = [[InlineKeyboardButton("点我绑定账号", url=f"https://t.me/{context.bot.username}?start=set_uid")]] + buttons = [[InlineKeyboardButton("点我绑定账号", url=create_deep_linked_url(context.bot.username, "set_uid"))]] if filters.ChatType.GROUPS.filter(message): reply_message = await message.reply_text( "未查询到您所绑定的账号信息,请先私聊派蒙绑定账号", reply_markup=InlineKeyboardMarkup(buttons) diff --git a/utils/decorators/error.py b/utils/decorators/error.py index 4333ef7..376a3f3 100644 --- a/utils/decorators/error.py +++ b/utils/decorators/error.py @@ -8,6 +8,7 @@ from httpx import ConnectTimeout from telegram import Update, ReplyKeyboardRemove, InlineKeyboardButton, InlineKeyboardMarkup, Message from telegram.error import BadRequest, TimedOut, Forbidden from telegram.ext import CallbackContext, ConversationHandler, filters +from telegram.helpers import create_deep_linked_url from core.baseplugin import add_delete_message_job from modules.apihelper.error import APIHelperException, ReturnCodeError, APIHelperTimedOut, ResponseException @@ -23,11 +24,11 @@ async def send_user_notification(update: Update, context: CallbackContext, text: return None if "重新绑定" in text: buttons = InlineKeyboardMarkup( - [[InlineKeyboardButton("点我重新绑定", url=f"https://t.me/{context.bot.username}?start=set_cookie")]] + [[InlineKeyboardButton("点我重新绑定", url=create_deep_linked_url(context.bot.username, "set_cookie"))]] ) elif "通过验证" in text: buttons = InlineKeyboardMarkup( - [[InlineKeyboardButton("点我通过验证", url=f"https://t.me/{context.bot.username}?start=verify_verification")]] + [[InlineKeyboardButton("点我通过验证", url=create_deep_linked_url(context.bot.username, "verify_verification"))]] ) else: buttons = ReplyKeyboardRemove()