From e26bc543dcab29697840c1871c0ca5a8b4a4ec11 Mon Sep 17 00:00:00 2001 From: xtaodada Date: Sat, 11 Dec 2021 23:36:26 +0800 Subject: [PATCH] =?UTF-8?q?yvlu=20=E6=94=AF=E6=8C=81=E6=9B=B4=E5=A5=BD?= =?UTF-8?q?=E7=9A=84=E7=94=9F=E6=88=90=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- list.json | 6 +++--- yvlu.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/list.json b/list.json index af215a2..8e4ad7a 100644 --- a/list.json +++ b/list.json @@ -682,13 +682,13 @@ }, { "name": "yvlu", - "version": "1.121", + "version": "1.2", "section": "chat", "maintainer": "xtaodada", - "size": "4.8 kb", + "size": "10.3 kb", "supported": true, "des-short": "将回复的消息转换成语录图片", - "des": "将回复的消息转换成语录图片。\n指令:-yvlu" + "des": "将回复的消息转换成语录图片。\n指令:-yvlu -yvlu_" }, { "name": "antichannelmsg", diff --git a/yvlu.py b/yvlu.py index 710c4e3..9413ed3 100644 --- a/yvlu.py +++ b/yvlu.py @@ -4,6 +4,8 @@ from os.path import exists from os import makedirs, remove from PIL import Image, ImageFont, ImageDraw from requests import get +from telethon.errors import YouBlockedUserError, ForbiddenError, FloodWaitError, AuthKeyError +from telethon.tl.functions.contacts import UnblockRequest from telethon.tl.functions.users import GetFullUserRequest from telethon.tl.types import MessageMediaPhoto, MessageMediaWebPage from pagermaid import bot @@ -112,6 +114,34 @@ async def yv_lu_process_sticker(name, photo, sticker, path): @listener(is_plugin=True, outgoing=True, command=alias_command("yvlu"), description="将回复的消息转换成语录") async def yv_lu(context): + reply = await context.get_reply_message() + if not reply: + return await context.edit('你需要回复一条消息。') + async with bot.conversation('QuotLyBot') as conversation: + try: + send_for = await reply.forward_to(conversation.chat_id) + except YouBlockedUserError: + if await context.client(UnblockRequest(id=conversation.chat_id)): + send_for = await reply.forward_to(conversation.chat_id) + else: + return await context.edit("请先解封 @QuotLyBot ") + except ForbiddenError: + return await context.edit("无权限转发消息。") + except FloodWaitError: + return await context.edit("触发转发 limit 限制") + except AuthKeyError: + return await context.edit("无权限转发消息。") + except: + return await context.edit("未知错误。") + chat_response = await conversation.get_response(message=send_for.id) + 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() + + +@listener(is_plugin=True, outgoing=True, command=alias_command("yvlu_"), + description="将回复的消息转换成语录") +async def yv_lu_(context): if not context.reply_to_msg_id: await context.edit('你需要回复一条消息。') return