From d6e16995e08498fda654da4f81dc6428a78ee88e Mon Sep 17 00:00:00 2001 From: befantasy <31535803+befantasy@users.noreply.github.com> Date: Sun, 30 Jul 2023 14:40:07 +0800 Subject: [PATCH] =?UTF-8?q?Update=20keyword.py=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E5=9B=BE=E7=89=87=E7=9A=84=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 增加返回图片的功能。以http/https开头,且以.jpg/.jpeg/.png/.gif结尾的内容,识别为URL,自动以图片发送。 --- plugins/keyword/keyword.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/plugins/keyword/keyword.py b/plugins/keyword/keyword.py index 97ebe26..2dc87ff 100644 --- a/plugins/keyword/keyword.py +++ b/plugins/keyword/keyword.py @@ -54,9 +54,18 @@ class Keyword(Plugin): logger.debug(f"[keyword] 匹配到关键字【{content}】") reply_text = self.keyword[content] - reply = Reply() - reply.type = ReplyType.TEXT - reply.content = reply_text + # 判断匹配内容的类型 + if (reply_text.startswith("http://") or reply_text.startswith("https://")) and any(reply_text.endswith(ext) for ext in [".jpg", ".jpeg", ".png", ".gif", ".webp"]): + # 如果是以 http:// 或 https:// 开头,且.jpg/.jpeg/.png/.gif结尾,则认为是图片 URL + reply = Reply() + reply.type = ReplyType.IMAGE_URL + reply.content = reply_text + else: + # 否则认为是普通文本 + reply = Reply() + reply.type = ReplyType.TEXT + reply.content = reply_text + e_context["reply"] = reply e_context.action = EventAction.BREAK_PASS # 事件结束,并跳过处理context的默认逻辑