Procházet zdrojové kódy

plugins: add helpp command for godcmd

lanvent před 3 roky
rodič
revize
30aedf04d7

+ 4 - 1
plugins/banwords/banwords.py

@@ -60,4 +60,7 @@ class Banwords(Plugin):
                 reply = Reply(ReplyType.INFO, "发言中包含敏感词,请重试: \n"+self.searchr.Replace(content))
                 e_context['reply'] = reply
                 e_context.action = EventAction.BREAK_PASS
-                return
+                return
+            
+    def get_help_text(self, **kwargs):
+        return Banwords.desc

+ 4 - 1
plugins/dungeon/dungeon.py

@@ -80,4 +80,7 @@ class Dungeon(Plugin):
                 prompt = self.games[sessionid].action(content)
                 e_context['context'].type = ContextType.TEXT
                 e_context['context'].content = prompt
-                e_context.action = EventAction.CONTINUE
+                e_context.action = EventAction.BREAK # 事件结束,不跳过处理context的默认逻辑
+    def get_help_text(self, **kwargs):
+        help_text = "输入\"$开始冒险 {背景故事}\"来以{背景故事}开始一个地牢游戏,之后你的所有消息会帮助我来完善这个故事。输入\"$停止冒险 \"可以结束游戏。"
+        return help_text

+ 17 - 0
plugins/godcmd/godcmd.py

@@ -19,6 +19,11 @@ COMMANDS = {
         "alias": ["help", "帮助"],
         "desc": "打印指令集合",
     },
+    "helpp": {
+        "alias": ["helpp", "插件帮助"],
+        "args": ["插件名"],
+        "desc": "打印插件的帮助信息",
+    },
     "auth": {
         "alias": ["auth", "认证"],
         "args": ["口令"],
@@ -161,6 +166,16 @@ class Godcmd(Plugin):
                     ok, result = self.authenticate(user, args, isadmin, isgroup)
                 elif cmd == "help":
                     ok, result = True, get_help_text(isadmin, isgroup)
+                elif cmd == "helpp":
+                    if len(args) != 1:
+                        ok, result = False, "请提供插件名"
+                    else:
+                        plugins = PluginManager().list_plugins()
+                        name = args[0].upper()
+                        if name in plugins and plugins[name].enabled:
+                            ok, result = True, PluginManager().instances[name].get_help_text(isgroup=isgroup, isadmin=isadmin)
+                        else:
+                            ok, result= False, "插件不存在或未启用"
                 elif cmd == "id":
                     ok, result = True, f"用户id=\n{user}"
                 elif cmd == "reset":
@@ -288,3 +303,5 @@ class Godcmd(Plugin):
         else:
             return False,"认证失败"
 
+    def get_help_text(self, isadmin = False, isgroup = False, **kwargs):
+        return get_help_text(isadmin, isgroup)

+ 4 - 0
plugins/hello/hello.py

@@ -44,3 +44,7 @@ class Hello(Plugin):
             e_context['context'].type = ContextType.IMAGE_CREATE
             content = "The World"
             e_context.action = EventAction.CONTINUE  # 事件继续,交付给下个插件或默认逻辑
+
+    def get_help_text(self, **kwargs):
+        help_text = "输入Hello,我会回复你的名字\n输入End,我会回复你世界的图片\n"
+        return help_text

+ 3 - 0
plugins/plugin.py

@@ -1,3 +1,6 @@
 class Plugin:
     def __init__(self):
         self.handlers = {}
+
+    def get_help_text(self, **kwargs):
+        return "暂无帮助信息"

+ 3 - 3
plugins/role/role.py

@@ -117,10 +117,10 @@ class Role(Plugin):
             prompt = self.roleplays[sessionid].action(content)
             e_context['context'].type = ContextType.TEXT
             e_context['context'].content = prompt
-            e_context.action = EventAction.CONTINUE
+            e_context.action = EventAction.BREAK
 
-    def get_help_text(self):
-        help_text = "输入\"$角色 (角色名)\"或\"$role (角色名)\"为我设定角色吧,\"$停止扮演 \" 可以清除设定的角色。\n\n目前可用角色列表:\n"
+    def get_help_text(self, **kwargs):
+        help_text = "输入\"$角色 {角色名}\"或\"$role {角色名}\"为我设定角色吧,\"$停止扮演 \" 可以清除设定的角色。\n\n目前可用角色列表:\n"
         for role in self.roles:
             help_text += f"[{role}]: {self.roles[role]['remark']}\n"
         return help_text

+ 1 - 1
plugins/sdwebui/sdwebui.py

@@ -97,7 +97,7 @@ class SDWebUI(Plugin):
         finally:
             e_context['reply'] = reply
 
-    def get_help_text(self):
+    def get_help_text(self, **kwargs):
         if not conf().get('image_create_prefix'):
             return "画图功能未启用"
         else: