From 131af7f0c1ec7d51a320dbbe3f9f1592f65f2395 Mon Sep 17 00:00:00 2001 From: omg-xtao <100690902+omg-xtao@users.noreply.github.com> Date: Tue, 11 Oct 2022 20:20:11 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20=E4=BF=AE=E5=A4=8D=E5=AF=B9?= =?UTF-8?q?=E8=AF=9D=E4=B8=AD=20cancel=20=E5=91=BD=E4=BB=A4=E5=A4=B1?= =?UTF-8?q?=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/plugin.py | 7 ++++++- plugins/other/post.py | 8 ++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/core/plugin.py b/core/plugin.py index 599cb71..76e4630 100644 --- a/core/plugin.py +++ b/core/plugin.py @@ -1,3 +1,4 @@ +import copy import datetime import re from importlib import import_module @@ -133,8 +134,12 @@ class _Conversation(_Plugin): and isinstance(func := getattr(self, attr), Callable) and (handler_datas := getattr(func, _NORMAL_HANDLER_ATTR_NAME, None)) ): + conversation_data = getattr(func, _CONVERSATION_HANDLER_ATTR_NAME, None) + if attr == "cancel": + handler_datas = copy.deepcopy(handler_datas) + conversation_data = copy.deepcopy(conversation_data) _handlers = self._make_handler(handler_datas) - if conversation_data := getattr(func, _CONVERSATION_HANDLER_ATTR_NAME, None): + if conversation_data: if (_type := conversation_data.pop("type")) == "entry": entry_points.extend(_handlers) elif _type == "state": diff --git a/plugins/other/post.py b/plugins/other/post.py index f9bb277..410c0f6 100644 --- a/plugins/other/post.py +++ b/plugins/other/post.py @@ -31,7 +31,7 @@ CHECK_POST, SEND_POST, CHECK_COMMAND, GTE_DELETE_PHOTO = range(10900, 10904) GET_POST_CHANNEL, GET_TAGS, GET_TEXT = range(10904, 10907) -class Post(Plugin.Conversation, BasePlugin): +class Post(Plugin.Conversation, BasePlugin.Conversation): """文章推送""" MENU_KEYBOARD = ReplyKeyboardMarkup([["推送频道", "添加TAG"], ["编辑文字", "删除图片"], ["退出"]], True, True) @@ -83,14 +83,14 @@ class Post(Plugin.Conversation, BasePlugin): post_text += f"[source](https://bbs.mihoyo.com/ys/article/{post_id})" if len(post_text) >= MessageLimit.CAPTION_LENGTH: await message.reply_markdown_v2(post_text) - post_text = post_text[0 : MessageLimit.CAPTION_LENGTH] + post_text = post_text[:MessageLimit.CAPTION_LENGTH] await message.reply_text(f"警告!图片字符描述已经超过 {MessageLimit.CAPTION_LENGTH} 个字,已经切割并发送原文本") try: if len(post_images) > 1: media = [InputMediaPhoto(img_info.data) for img_info in post_images] media[0] = InputMediaPhoto(post_images[0].data, caption=post_text, parse_mode=ParseMode.MARKDOWN_V2) if len(media) > 10: - media = media[0:10] + media = media[:10] await message.reply_text("获取到的图片已经超过10张,为了保证发送成功,已经删除一部分图片") await message.reply_media_group(media) elif len(post_images) == 1: @@ -273,7 +273,7 @@ class Post(Plugin.Conversation, BasePlugin): await context.bot.send_photo( channel_id, photo=image.data, caption=post_text, parse_mode=ParseMode.MARKDOWN_V2 ) - elif len(post_images) == 0: + elif not post_images: await context.bot.send_message(channel_id, post_text, parse_mode=ParseMode.MARKDOWN_V2) else: await message.reply_text("图片获取错误", reply_markup=ReplyKeyboardRemove()) # excuse?