Skip to content

Commit

Permalink
Merge pull request #1346 from befantasy/patch-1
Browse files Browse the repository at this point in the history
Update keyword.py 增加返回图片的功能
  • Loading branch information
zhayujie authored Jul 31, 2023
2 parents 39dd99b + d6e1699 commit e05bc54
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions plugins/keyword/keyword.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,18 @@ def on_handle_context(self, e_context: EventContext):
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的默认逻辑

Expand Down

0 comments on commit e05bc54

Please sign in to comment.