🐛 Fix sb cannot recognize formatted text and add support MessageMediaUnsupported for s. (#161)

🐛 修复 sb 无法识别格式化文本的问题
🐛 修复 s 遇到 MessageMediaUnsupported 时报错
This commit is contained in:
Xtao_dada 2021-12-26 14:34:20 +08:00 committed by GitHub
parent 12320e2a59
commit babbc1c44c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 7 deletions

View File

@ -6,7 +6,7 @@ from telethon.tl.functions.messages import GetCommonChatsRequest
from telethon.tl.functions.users import GetFullUserRequest from telethon.tl.functions.users import GetFullUserRequest
from telethon.tl.functions.channels import DeleteUserHistoryRequest, EditBannedRequest from telethon.tl.functions.channels import DeleteUserHistoryRequest, EditBannedRequest
from telethon.tl.types import MessageEntityMentionName, ChannelParticipantsAdmins, MessageEntityPhone, PeerChannel, \ from telethon.tl.types import MessageEntityMentionName, ChannelParticipantsAdmins, MessageEntityPhone, PeerChannel, \
ChatBannedRights ChatBannedRights, MessageEntityCode
from telethon.errors.rpcerrorlist import UserAdminInvalidError, ChatAdminRequiredError, FloodWaitError from telethon.errors.rpcerrorlist import UserAdminInvalidError, ChatAdminRequiredError, FloodWaitError
from asyncio import sleep from asyncio import sleep
from random import uniform from random import uniform
@ -68,22 +68,22 @@ async def span_ban(context):
target_user = await context.client(GetFullUserRequest(user)) target_user = await context.client(GetFullUserRequest(user))
else: else:
if len(context.parameter) == 1: if len(context.parameter) == 1:
user = context.parameter[0] user = context.parameter[0].strip("`")
if user.isnumeric(): if user.isnumeric():
user = int(user) user = int(user)
if user < 0: if user < 0:
return await context.edit(lang('arg_error')) return await context.edit(lang('arg_error'))
else: else:
await context.edit(lang('arg_error')) return await context.edit(lang('arg_error'))
return
if context.message.entities is not None: if context.message.entities is not None:
if isinstance(context.message.entities[0], MessageEntityMentionName): if isinstance(context.message.entities[0], MessageEntityMentionName):
user = context.message.entities[0].user_id user = context.message.entities[0].user_id
elif isinstance(context.message.entities[0], MessageEntityPhone): elif isinstance(context.message.entities[0], MessageEntityPhone):
user = int(context.parameter[0]) user = int(context.parameter[0])
elif isinstance(context.message.entities[0], MessageEntityCode):
pass
else: else:
await context.edit(f"{lang('error_prefix')}{lang('arg_error')}") return await context.edit(f"{lang('error_prefix')}{lang('arg_error')}")
return
try: try:
user_object = await context.client.get_entity(user) user_object = await context.client.get_entity(user)
target_user = await context.client(GetFullUserRequest(user_object.id)) target_user = await context.client(GetFullUserRequest(user_object.id))

View File

@ -4,7 +4,8 @@ from bs4 import BeautifulSoup
from asyncio import sleep from asyncio import sleep
from os import remove from os import remove
from io import BytesIO 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.tl.functions.contacts import UnblockRequest
from telethon.errors.common import AlreadyInConversationError from telethon.errors.common import AlreadyInConversationError
from PIL import Image, ImageOps from PIL import Image, ImageOps
@ -214,6 +215,12 @@ async def single_sticker(animated, context, custom_emoji, emoji, message, pic_ro
except: except:
pass pass
return 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('/'): elif "image" in message.media.document.mime_type.split('/'):
photo = BytesIO() photo = BytesIO()
try: try: