From dbf85f32b4f451bd429c8c6cecad2113a85540ac Mon Sep 17 00:00:00 2001 From: xtaodada Date: Wed, 15 Dec 2021 13:10:56 +0800 Subject: [PATCH] =?UTF-8?q?netease=20rape=20vip=20yvlu=20=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- list.json | 6 +++--- neteasedown.py | 4 ++-- rape.py | 30 ++++++++++++++++++++++-------- vip.py | 6 +++++- yvlu.py | 6 +++++- 5 files changed, 37 insertions(+), 15 deletions(-) diff --git a/list.json b/list.json index 747a49a..749e475 100644 --- a/list.json +++ b/list.json @@ -272,7 +272,7 @@ }, { "name": "neteasedown", - "version": "1.223", + "version": "1.224", "section": "daily", "maintainer": "xtaodada", "size": "11.4 kb", @@ -472,7 +472,7 @@ }, { "name": "rape", - "version": "1.032", + "version": "1.033", "section": "chat", "maintainer": "Pentacene", "size": "4.0 kb", @@ -682,7 +682,7 @@ }, { "name": "yvlu", - "version": "1.21", + "version": "1.211", "section": "chat", "maintainer": "xtaodada", "size": "10.4 kb", diff --git a/neteasedown.py b/neteasedown.py index d7c5050..7b886f2 100644 --- a/neteasedown.py +++ b/neteasedown.py @@ -219,12 +219,12 @@ async def ned(context): song_id = int(song_id) else: search_data = apis.cloudsearch.GetSearchResult(song_id, CloudSearchType(1), 1) - if search_data["result"]["songCount"] >= 1: + if search_data.get("result", {}).get("songCount", 0) >= 1: song_id = search_data["result"]["songs"][0]["id"] else: await context.edit(f"**没有找到歌曲**,请检查歌曲名称是否正确。") return - # 获取歌曲信息小于等于 320k HQ + # 获取歌曲质量是否大于 320k HQ track_info = apis.track.GetTrackAudio([song_id], bitrate=3200 * 1000 if flac_mode else 320000) # 获取歌曲详情 song_info = apis.track.GetTrackDetail([song_id]) diff --git a/rape.py b/rape.py index 91e7efc..82c2ef9 100644 --- a/rape.py +++ b/rape.py @@ -20,10 +20,17 @@ async def rape(context): reply = await context.get_reply_message() if context.is_group: if reply: - if reply.sender.last_name is None: - reply_last_name = '' - else: - reply_last_name = reply.sender.last_name + try: + if reply.sender.last_name is None: + reply_last_name = '' + else: + reply_last_name = reply.sender.last_name + except AttributeError: + try: + await context.edit('无法获取所回复的用户。') + except: + pass + return if context.sender.last_name is None: context_last_name = '' else: @@ -68,10 +75,17 @@ async def rape(context): except: pass else: - if context.sender.last_name is None: - context_last_name = '' - else: - context_last_name = context.sender.last_name + try: + if context.sender.last_name is None: + context_last_name = '' + else: + context_last_name = context.sender.last_name + except AttributeError: + try: + await context.edit('无法获取所回复的用户。') + except: + pass + return if context.arguments == '': return else: diff --git a/vip.py b/vip.py index 302aa87..adf7599 100644 --- a/vip.py +++ b/vip.py @@ -3,6 +3,7 @@ from redis.exceptions import ConnectionError from requests import get from os import remove from telethon.tl.types import MessageMediaPhoto +from asyncio.exceptions import TimeoutError from pagermaid import bot, redis, redis_status from pagermaid.listener import listener from pagermaid.utils import obtain_message, alias_command @@ -314,7 +315,10 @@ async def az_tts(context, mode): return async with bot.conversation('PagerMaid_Modify_bot') as conversation: await conversation.send_message('/tts ' + message + mode) - chat_response = await conversation.get_response() + try: + chat_response = await conversation.get_response() + except TimeoutError: + return await context.edit("未收到服务器回应。") await bot.send_read_acknowledge(conversation.chat_id) if reply: await context.respond(chat_response, reply_to=reply) diff --git a/yvlu.py b/yvlu.py index 53a5151..c9c7c83 100644 --- a/yvlu.py +++ b/yvlu.py @@ -8,6 +8,7 @@ from telethon.errors import YouBlockedUserError, ForbiddenError, FloodWaitError, from telethon.tl.functions.contacts import UnblockRequest from telethon.tl.functions.users import GetFullUserRequest from telethon.tl.types import MessageMediaPhoto, MessageMediaWebPage +from asyncio.exceptions import TimeoutError from pagermaid import bot from pagermaid.listener import listener from pagermaid.utils import alias_command @@ -138,7 +139,10 @@ async def yv_lu(context): return await context.edit("无权限转发消息。") except: return await context.edit("未知错误。") - chat_response = await conversation.get_response(message=send_for.id) + try: + chat_response = await conversation.get_response(message=send_for.id) + except TimeoutError: + return await context.edit("未收到服务器回应。") await bot.send_read_acknowledge(conversation.chat_id) await bot.send_message(context.chat_id, chat_response, reply_to=context.message.reply_to_msg_id) await context.delete()