mirror of
https://github.com/zhayujie/chatgpt-on-wechat.git
synced 2026-04-22 08:55:39 +08:00
formatting code
This commit is contained in:
@@ -1,14 +1,21 @@
|
||||
# encoding:utf-8
|
||||
|
||||
import plugins
|
||||
from bridge.context import ContextType
|
||||
from bridge.reply import Reply, ReplyType
|
||||
from channel.chat_message import ChatMessage
|
||||
import plugins
|
||||
from plugins import *
|
||||
from common.log import logger
|
||||
from plugins import *
|
||||
|
||||
|
||||
@plugins.register(name="Hello", desire_priority=-1, hidden=True, desc="A simple plugin that says hello", version="0.1", author="lanvent")
|
||||
@plugins.register(
|
||||
name="Hello",
|
||||
desire_priority=-1,
|
||||
hidden=True,
|
||||
desc="A simple plugin that says hello",
|
||||
version="0.1",
|
||||
author="lanvent",
|
||||
)
|
||||
class Hello(Plugin):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
@@ -16,33 +23,34 @@ class Hello(Plugin):
|
||||
logger.info("[Hello] inited")
|
||||
|
||||
def on_handle_context(self, e_context: EventContext):
|
||||
|
||||
if e_context['context'].type != ContextType.TEXT:
|
||||
if e_context["context"].type != ContextType.TEXT:
|
||||
return
|
||||
|
||||
content = e_context['context'].content
|
||||
|
||||
content = e_context["context"].content
|
||||
logger.debug("[Hello] on_handle_context. content: %s" % content)
|
||||
if content == "Hello":
|
||||
reply = Reply()
|
||||
reply.type = ReplyType.TEXT
|
||||
msg:ChatMessage = e_context['context']['msg']
|
||||
if e_context['context']['isgroup']:
|
||||
reply.content = f"Hello, {msg.actual_user_nickname} from {msg.from_user_nickname}"
|
||||
msg: ChatMessage = e_context["context"]["msg"]
|
||||
if e_context["context"]["isgroup"]:
|
||||
reply.content = (
|
||||
f"Hello, {msg.actual_user_nickname} from {msg.from_user_nickname}"
|
||||
)
|
||||
else:
|
||||
reply.content = f"Hello, {msg.from_user_nickname}"
|
||||
e_context['reply'] = reply
|
||||
e_context.action = EventAction.BREAK_PASS # 事件结束,并跳过处理context的默认逻辑
|
||||
e_context["reply"] = reply
|
||||
e_context.action = EventAction.BREAK_PASS # 事件结束,并跳过处理context的默认逻辑
|
||||
|
||||
if content == "Hi":
|
||||
reply = Reply()
|
||||
reply.type = ReplyType.TEXT
|
||||
reply.content = "Hi"
|
||||
e_context['reply'] = reply
|
||||
e_context["reply"] = reply
|
||||
e_context.action = EventAction.BREAK # 事件结束,进入默认处理逻辑,一般会覆写reply
|
||||
|
||||
if content == "End":
|
||||
# 如果是文本消息"End",将请求转换成"IMAGE_CREATE",并将content设置为"The World"
|
||||
e_context['context'].type = ContextType.IMAGE_CREATE
|
||||
e_context["context"].type = ContextType.IMAGE_CREATE
|
||||
content = "The World"
|
||||
e_context.action = EventAction.CONTINUE # 事件继续,交付给下个插件或默认逻辑
|
||||
|
||||
|
||||
Reference in New Issue
Block a user