From 0218ac7648782c899b1ba632701882d2f3c17a9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B4=9B=E6=B0=B4=E5=B1=85=E5=AE=A4?= Date: Sun, 25 Dec 2022 15:49:36 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20Use=20`html.escape`=20to=20Escap?= =?UTF-8?q?e=20Special=20Characters?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/system/get_chat.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/plugins/system/get_chat.py b/plugins/system/get_chat.py index ac4265a..9b734d7 100644 --- a/plugins/system/get_chat.py +++ b/plugins/system/get_chat.py @@ -1,4 +1,5 @@ import contextlib +import html from typing import List from telegram import Update, Chat, ChatMember, ChatMemberOwner, ChatMemberAdministrator @@ -32,17 +33,17 @@ class GetChat(Plugin): self.gacha_log = GachaLog() async def parse_group_chat(self, chat: Chat, admins: List[ChatMember]) -> str: - text = f"群 ID:{chat.id}\n" f"群名称:{chat.title}\n" + text = f"群 ID:{chat.id}\n群名称:{chat.title}\n" if chat.username: text += f"群用户名:@{chat.username}\n" sign_info = await self.sign_service.get_by_chat_id(chat.id) if sign_info: text += f"自动签到推送人数:{len(sign_info)}\n" if chat.description: - text += f"群简介:{chat.description}\n" + text += f"群简介:{html.escape(chat.description)}\n" if admins: for admin in admins: - text += f'{admin.user.full_name} ' + text += f'{html.escape(admin.user.full_name)} ' if isinstance(admin, ChatMemberAdministrator): text += "C" if admin.can_change_info else "_" text += "D" if admin.can_delete_messages else "_" @@ -82,7 +83,7 @@ class GetChat(Plugin): await get_genshin_client(chat.id) except CookiesNotFoundError: temp = "UID 绑定" - text += f"{temp}\n" f"游戏 ID:{uid}" + text += f"{temp}\n游戏 ID:{uid}" sign_info = await self.sign_service.get_by_user_id(chat.id) if sign_info is not None: text += ( @@ -109,7 +110,7 @@ class GetChat(Plugin): @bot_admins_rights_check async def get_chat(self, update: Update, context: CallbackContext): user = update.effective_user - logger.info(f"用户 {user.full_name}[{user.id}] get_chat 命令请求") + logger.info("用户 %s[%s] get_chat 命令请求", user.full_name, user.id) message = update.effective_message args = get_args(context) if not args: @@ -129,5 +130,4 @@ class GetChat(Plugin): text = await self.parse_private_chat(chat) await message.reply_text(text, parse_mode="HTML") except (BadRequest, Forbidden) as exc: - await message.reply_text(f"通过 id 获取会话信息失败,API 返回:{exc}") - return + await message.reply_text(f"通过 id 获取会话信息失败,API 返回:{exc.message}")