From babbc1c44c662a735495023e24d0685591c2273b Mon Sep 17 00:00:00 2001 From: Xtao_dada Date: Sun, 26 Dec 2021 14:34:20 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20sb=20cannot=20recognize=20?= =?UTF-8?q?formatted=20text=20and=20add=20support=20MessageMediaUnsupporte?= =?UTF-8?q?d=20for=20s.=20(#161)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🐛 修复 sb 无法识别格式化文本的问题 🐛 修复 s 遇到 MessageMediaUnsupported 时报错 --- pagermaid/modules/sb.py | 12 ++++++------ pagermaid/modules/sticker.py | 9 ++++++++- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/pagermaid/modules/sb.py b/pagermaid/modules/sb.py index 9b35cd6..1568a0c 100644 --- a/pagermaid/modules/sb.py +++ b/pagermaid/modules/sb.py @@ -6,7 +6,7 @@ from telethon.tl.functions.messages import GetCommonChatsRequest from telethon.tl.functions.users import GetFullUserRequest from telethon.tl.functions.channels import DeleteUserHistoryRequest, EditBannedRequest from telethon.tl.types import MessageEntityMentionName, ChannelParticipantsAdmins, MessageEntityPhone, PeerChannel, \ - ChatBannedRights + ChatBannedRights, MessageEntityCode from telethon.errors.rpcerrorlist import UserAdminInvalidError, ChatAdminRequiredError, FloodWaitError from asyncio import sleep from random import uniform @@ -68,22 +68,22 @@ async def span_ban(context): target_user = await context.client(GetFullUserRequest(user)) else: if len(context.parameter) == 1: - user = context.parameter[0] + user = context.parameter[0].strip("`") if user.isnumeric(): user = int(user) if user < 0: return await context.edit(lang('arg_error')) else: - await context.edit(lang('arg_error')) - return + return await context.edit(lang('arg_error')) if context.message.entities is not None: if isinstance(context.message.entities[0], MessageEntityMentionName): user = context.message.entities[0].user_id elif isinstance(context.message.entities[0], MessageEntityPhone): user = int(context.parameter[0]) + elif isinstance(context.message.entities[0], MessageEntityCode): + pass else: - await context.edit(f"{lang('error_prefix')}{lang('arg_error')}") - return + return await context.edit(f"{lang('error_prefix')}{lang('arg_error')}") try: user_object = await context.client.get_entity(user) target_user = await context.client(GetFullUserRequest(user_object.id)) diff --git a/pagermaid/modules/sticker.py b/pagermaid/modules/sticker.py index cc2d98b..89836cc 100644 --- a/pagermaid/modules/sticker.py +++ b/pagermaid/modules/sticker.py @@ -4,7 +4,8 @@ from bs4 import BeautifulSoup from asyncio import sleep from os import remove from io import BytesIO -from telethon.tl.types import DocumentAttributeFilename, MessageMediaPhoto, MessageMediaWebPage, MessageMediaDice +from telethon.tl.types import DocumentAttributeFilename, MessageMediaPhoto, MessageMediaWebPage, MessageMediaDice, \ + MessageMediaUnsupported from telethon.tl.functions.contacts import UnblockRequest from telethon.errors.common import AlreadyInConversationError from PIL import Image, ImageOps @@ -214,6 +215,12 @@ async def single_sticker(animated, context, custom_emoji, emoji, message, pic_ro except: pass return + elif isinstance(message.media, MessageMediaUnsupported): + try: + await context.edit(lang('sticker_type_not_support')) + except: + pass + return elif "image" in message.media.document.mime_type.split('/'): photo = BytesIO() try: