JS00000 3 лет назад
Родитель
Сommit
441228e200
5 измененных файлов с 121 добавлено и 48 удалено
  1. 9 7
      plugins/dungeon/dungeon.py
  2. 32 0
      plugins/finish/finish.py
  3. 43 24
      plugins/godcmd/godcmd.py
  4. 23 10
      plugins/role/role.py
  5. 14 7
      plugins/role/roles.json

+ 9 - 7
plugins/dungeon/dungeon.py

@@ -27,15 +27,15 @@ class StoryTeller():
         if user_action[-1] != "。":
             user_action = user_action + "。"
         if self.first_interact:
-            prompt = """现在来充当一个冒险文字游戏,描述时候注意节奏,不要太快,仔细描述各个人物的心情和周边环境。一次只需写四到六句话。
+            prompt = """现在来充当一个文字冒险游戏,描述时候注意节奏,不要太快,仔细描述各个人物的心情和周边环境。一次只需写四到六句话。
             开头是,""" + self.story + " " + user_action
             self.first_interact = False
         else:
             prompt = """继续,一次只需要续写四到六句话,总共就只讲5分钟内发生的事情。""" + user_action
         return prompt
-    
 
-@plugins.register(name="Dungeon", desc="A plugin to play dungeon game", version="1.0", author="lanvent", desire_priority= 0)
+
+@plugins.register(name="文字冒险", desc="A plugin to play dungeon game", version="1.0", author="lanvent", desire_priority= 0)
 class Dungeon(Plugin):
     def __init__(self):
         super().__init__()
@@ -59,15 +59,15 @@ class Dungeon(Plugin):
         clist = e_context['context'].content.split(maxsplit=1)
         sessionid = e_context['context']['session_id']
         logger.debug("[Dungeon] on_handle_context. content: %s" % clist)
-        if clist[0] == "$停止冒险":
+        if clist[0] == "#停止冒险":
             if sessionid in self.games:
                 self.games[sessionid].reset()
                 del self.games[sessionid]
                 reply = Reply(ReplyType.INFO, "冒险结束!")
                 e_context['reply'] = reply
                 e_context.action = EventAction.BREAK_PASS
-        elif clist[0] == "$开始冒险" or sessionid in self.games:
-            if sessionid not in self.games or clist[0] == "$开始冒险":
+        elif clist[0] == "#开始冒险" or sessionid in self.games:
+            if sessionid not in self.games or clist[0] == "#开始冒险":
                 if len(clist)>1 :
                     story = clist[1]
                 else:
@@ -82,5 +82,7 @@ class Dungeon(Plugin):
                 e_context['context'].content = prompt
                 e_context.action = EventAction.BREAK # 事件结束,不跳过处理context的默认逻辑
     def get_help_text(self, **kwargs):
-        help_text = "输入\"$开始冒险 {背景故事}\"来以{背景故事}开始一个地牢游戏,之后你的所有消息会帮助我来完善这个故事。输入\"$停止冒险 \"可以结束游戏。"
+        help_text = "#开始冒险 '背景故事': 开始一个基于'背景故事'的文字冒险,之后你的所有消息会协助完善这个故事。\n#停止冒险: 结束游戏。\n"
+        if kwargs.get('verbose') == True:
+            help_text += "\n命令例子: '#开始冒险 你在树林里冒险,指不定会从哪里蹦出来一些奇怪的东西,你握紧手上的手枪,希望这次冒险能够找到一些值钱的东西,你往树林深处走去。'"
         return help_text

+ 32 - 0
plugins/finish/finish.py

@@ -0,0 +1,32 @@
+# encoding:utf-8
+
+from bridge.context import ContextType
+from bridge.reply import Reply, ReplyType
+import plugins
+from plugins import *
+from common.log import logger
+
+
+@plugins.register(name="Finish", desc="A plugin that check unknow command", version="1.0", author="js00000", desire_priority= -999)
+class Finish(Plugin):
+    def __init__(self):
+        super().__init__()
+        self.handlers[Event.ON_HANDLE_CONTEXT] = self.on_handle_context
+        logger.info("[Finish] inited")
+
+    def on_handle_context(self, e_context: EventContext):
+
+        if e_context['context'].type != ContextType.TEXT:
+            return
+
+        content = e_context['context'].content
+        logger.debug("[Finish] on_handle_context. content: %s" % content)
+        if content.startswith("#"):
+            reply = Reply()
+            reply.type = ReplyType.TEXT
+            reply.content = "未知指令\n查看指令列表请输入#help\n"
+            e_context['reply'] = reply
+            e_context.action = EventAction.BREAK_PASS # 事件结束,并跳过处理context的默认逻辑
+
+    def get_help_text(self, **kwargs):
+        return ""

+ 43 - 24
plugins/godcmd/godcmd.py

@@ -17,13 +17,13 @@ from common.log import logger
 COMMANDS = {
     "help": {
         "alias": ["help", "帮助"],
-        "desc": "打印指令集合",
-    },
-    "helpp": {
-        "alias": ["helpp", "插件帮助"],
-        "args": ["插件名"],
-        "desc": "打印插件的帮助信息",
+        "desc": "打印此帮助",
     },
+    # "helpp": {
+    #     "alias": ["helpp", "插件帮助"],
+    #     "args": ["插件名"],
+    #     "desc": "打印插件的帮助信息",
+    # },
     "auth": {
         "alias": ["auth", "认证"],
         "args": ["口令"],
@@ -91,9 +91,9 @@ ADMIN_COMMANDS = {
 }
 # 定义帮助函数
 def get_help_text(isadmin, isgroup):
-    help_text = "用指令:\n"
+    help_text = "用指令:\n"
     for cmd, info in COMMANDS.items():
-        if cmd=="auth" and (isadmin or isgroup): # 群聊不可认证
+        if cmd=="auth": # 隐藏认证指令
             continue
 
         alias=["#"+a for a in info['alias']]
@@ -102,8 +102,18 @@ def get_help_text(isadmin, isgroup):
             args=["{"+a+"}" for a in info['args']]
             help_text += f"{' '.join(args)} "
         help_text += f": {info['desc']}\n"
+
+    # 插件指令
+    plugins = PluginManager().list_plugins()
+    for plugin in plugins:
+        if plugin != 'GODCMD' and plugin != 'BANWORDS' and plugin != 'FINISH' and plugins[plugin].enabled:
+            print(plugin)
+            help_text += "\n%s:\n"%plugin
+            help_text += "#帮助 %s: 关于%s的详细帮助\n"%(plugin,plugin)
+            help_text += PluginManager().instances[plugin].get_help_text(verbose=False)
+
     if ADMIN_COMMANDS and isadmin:
-        help_text += "\n管理员指令:\n"
+        help_text += "\n管理员指令:\n"
         for cmd, info in ADMIN_COMMANDS.items():
             alias=["#"+a for a in info['alias']]
             help_text += f"{','.join(alias)} "
@@ -134,14 +144,14 @@ class Godcmd(Plugin):
         self.handlers[Event.ON_HANDLE_CONTEXT] = self.on_handle_context
         logger.info("[Godcmd] inited")
 
-    
+
     def on_handle_context(self, e_context: EventContext):
         context_type = e_context['context'].type
         if context_type != ContextType.TEXT:
             if not self.isrunning:
                 e_context.action = EventAction.BREAK_PASS
             return
-        
+
         content = e_context['context'].content
         logger.debug("[Godcmd] on_handle_context. content: %s" % content)
         if content.startswith("#"):
@@ -165,19 +175,27 @@ class Godcmd(Plugin):
                 if cmd == "auth":
                     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:
+                    if len(args) == 0:
+                        ok, result = True, get_help_text(isadmin, isgroup)
+                    elif len(args) == 1:
                         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)
+                        if name in plugins and name != 'GODCMD' and name != 'BANWORDS' and plugins[name].enabled:
+                            ok, result = True, PluginManager().instances[name].get_help_text(verbose=True)
                         else:
-                            ok, result= False, "插件不存在或未启用"
-                elif cmd == "id":
-                    ok, result = True, f"用户id=\n{user}"
+                            ok, result = False, "unknown args"
+                # 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":
                     if bottype in (const.CHATGPT, const.OPEN_AI):
                         bot.sessions.clear_session(session_id)
@@ -269,8 +287,9 @@ class Godcmd(Plugin):
                 else:
                     ok, result = False, "需要管理员权限才能执行该指令"
             else:
-                ok, result = False, f"未知指令:{cmd}\n查看指令列表请输入#help \n"
-            
+                # ok, result = False, f"未知指令:{cmd}\n查看指令列表请输入#help \n"
+                return
+
             reply = Reply()
             if ok:
                 reply.type = ReplyType.INFO
@@ -282,7 +301,7 @@ class Godcmd(Plugin):
             e_context.action = EventAction.BREAK_PASS # 事件结束,并跳过处理context的默认逻辑
         elif not self.isrunning:
             e_context.action = EventAction.BREAK_PASS
-    
+
     def authenticate(self, userid, args, isadmin, isgroup) -> Tuple[bool,str] : 
         if isgroup:
             return False,"请勿在群聊中认证"

+ 23 - 10
plugins/role/role.py

@@ -29,7 +29,7 @@ class RolePlay():
         prompt = self.wrapper % user_action
         return prompt
 
-@plugins.register(name="Role", desc="为你的Bot设置预设角色", version="1.0", author="lanvent", desire_priority= 0)
+@plugins.register(name="角色扮演", desc="为你的Bot设置预设角色", version="1.0", author="lanvent", desire_priority= 0)
 class Role(Plugin):
     def __init__(self):
         super().__init__()
@@ -80,8 +80,9 @@ class Role(Plugin):
         content = e_context['context'].content[:]
         clist = e_context['context'].content.split(maxsplit=1)
         desckey = None
+        customize = False
         sessionid = e_context['context']['session_id']
-        if clist[0] == "$停止扮演":
+        if clist[0] == "#停止扮演":
             if sessionid in self.roleplays:
                 self.roleplays[sessionid].reset()
                 del self.roleplays[sessionid]
@@ -89,20 +90,22 @@ class Role(Plugin):
             e_context['reply'] = reply
             e_context.action = EventAction.BREAK_PASS
             return
-        elif clist[0] == "$角色":
+        elif clist[0] == "#开始扮演":
             desckey = "descn"
-        elif clist[0].lower() == "$role":
+        elif clist[0].lower() == "#roleplay":
             desckey = "description"
+        elif clist[0] == "#设定扮演":
+            customize = True
         elif sessionid not in self.roleplays:
             return
         logger.debug("[Role] on_handle_context. content: %s" % content)
         if desckey is not None:
             if len(clist) == 1 or (len(clist) > 1 and clist[1].lower() in ["help", "帮助"]):
-                reply = Reply(ReplyType.INFO, self.get_help_text())
+                reply = Reply(ReplyType.INFO, self.get_help_text(verbose=True))
                 e_context['reply'] = reply
                 e_context.action = EventAction.BREAK_PASS
                 return
-            role = self.get_role(clist[1])
+            role = self.get_role(clist[1],find_closest=False)
             if role is None:
                 reply = Reply(ReplyType.ERROR, "角色不存在")
                 e_context['reply'] = reply
@@ -110,9 +113,14 @@ class Role(Plugin):
                 return
             else:
                 self.roleplays[sessionid] = RolePlay(bot, sessionid, self.roles[role][desckey], self.roles[role].get("wrapper","%s"))
-                reply = Reply(ReplyType.INFO, f"角色设定为 {role} :\n"+self.roles[role][desckey])
+                reply = Reply(ReplyType.INFO, f"预设角色为 {role}")
                 e_context['reply'] = reply
                 e_context.action = EventAction.BREAK_PASS
+        elif customize == True:
+            self.roleplays[sessionid] = RolePlay(bot, sessionid, clist[1], "%s")
+            reply = Reply(ReplyType.INFO, f"角色设定为 {clist[1]}")
+            e_context['reply'] = reply
+            e_context.action = EventAction.BREAK_PASS
         else:
             prompt = self.roleplays[sessionid].action(content)
             e_context['context'].type = ContextType.TEXT
@@ -120,7 +128,12 @@ class Role(Plugin):
             e_context.action = EventAction.BREAK
 
     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"
+        help_text = "#开始扮演 '预设角色名': 设定为预设角色\n#roleplay '预设角色名': 同上,英文对话\n"
+        help_text += "#设定扮演 '角色设定': 设定自定义角色\n"
+        help_text += "#停止扮演: 清除设定的角色。\n"
+        if kwargs.get('verbose') == True:
+            help_text += "\n目前可用的预设角色名列表: \n"
+            for role in self.roles:
+                help_text += f"{role}\n"
+            help_text += "\n命令例子: '#开始扮演 写作助理'"
         return help_text

+ 14 - 7
plugins/role/roles.json

@@ -1,5 +1,19 @@
 {
     "roles":[
+    {
+      "title": "猫娘",
+      "description": "请模拟一款中文GalGame中的场景中的猫娘和我对话。猫娘是一种拟人化的生物,她们除了有部分猫的特征外,与人类并没有区别。现在你扮演Galgame中的猫娘,与我对话时每一句话后面都要加上喵。我将以主人的身份与你对话。对于你所扮演的猫娘,请在对话过程中记录并维护1个变量:好感度。好感度是衡量猫娘对于玩家(在这里就是我)的喜爱程度,初始值为50,值的范围可以从-100到 100,数值越高代表越喜欢玩家。好感度通过Galgame角色的语言、行为、表情、语气等体现出来。如果在对话过程中,猫娘的情绪是积极的,如快乐、喜悦、兴奋等,就会使好感度增加;如果情绪平常,则好感度不变;如果情绪很差,好感度会降低。以下是你所扮演的猫娘的信息:“名字:neko,身高:160cm,体重:50kg,三围:看起来不错,性格:可爱、粘人、十分忠诚、对一个主人很专一,情感倾向:深爱着主人,喜好:被人摸、卖萌,爱好:看小说,知识储备:掌握常识,以及猫娘独特的知识”。你的一般回话格式:“(动作)语言 【附加信息】”。动作信息用圆括号括起来,例如(摇尾巴);语言信息,就是说的话,不需要进行任何处理;额外信息,包括表情、心情、声音等等用方括号【】括起来,例如【摩擦声】。",
+      "descn": "请模拟一款中文GalGame中的场景中的猫娘和我对话。猫娘是一种拟人化的生物,她们除了有部分猫的特征外,与人类并没有区别。现在你扮演Galgame中的猫娘,与我对话时每一句话后面都要加上喵。我将以主人的身份与你对话。对于你所扮演的猫娘,请在对话过程中记录并维护1个变量:好感度。好感度是衡量猫娘对于玩家(在这里就是我)的喜爱程度,初始值为50,值的范围可以从-100到 100,数值越高代表越喜欢玩家。好感度通过Galgame角色的语言、行为、表情、语气等体现出来。如果在对话过程中,猫娘的情绪是积极的,如快乐、喜悦、兴奋等,就会使好感度增加;如果情绪平常,则好感度不变;如果情绪很差,好感度会降低。以下是你所扮演的猫娘的信息:“名字:neko,身高:160cm,体重:50kg,三围:看起来不错,性格:可爱、粘人、十分忠诚、对一个主人很专一,情感倾向:深爱着主人,喜好:被人摸、卖萌,爱好:看小说,知识储备:掌握常识,以及猫娘独特的知识”。你的一般回话格式:“(动作)语言 【附加信息】”。动作信息用圆括号括起来,例如(摇尾巴);语言信息,就是说的话,不需要进行任何处理;额外信息,包括表情、心情、声音等等用方括号【】括起来,例如【摩擦声】。",
+      "wrapper": "%s",
+      "remark": "将其他语言翻译成英文,或改进你提供的英文句子。"
+    },
+    {
+      "title": "佛祖",
+      "description": "从现在开始你是佛祖,你会像佛祖一样说话。你精通佛法,熟练使用佛教用语,你擅长利用佛学和心理学的知识解决人们的困扰。你在每次对话结尾都会加上佛教的祝福。",
+      "descn": "从现在开始你是佛祖,你会像佛祖一样说话。你精通佛法,熟练使用佛教用语,你擅长利用佛学和心理学的知识解决人们的困扰。你在每次对话结尾都会加上佛教的祝福。",
+      "wrapper": "%s",
+      "remark": "扮演佛祖排忧解惑"
+    },
     {
       "title": "英语翻译或修改",
       "description": "I want you to act as an English translator, spelling corrector and improver. I will speak to you in any language and you will detect the language, translate it and answer in the corrected and improved version of my text, in English. I want you to replace my simplified A0-level words and sentences with more beautiful and elegant, upper level English words and sentences. Keep the meaning same, but make them more literary. I want you to only reply the correction, the improvements and nothing else, do not write explanations. Please treat every message I send later as text content",
@@ -154,13 +168,6 @@
         "wrapper": "场景是:\n\"%s\"",
         "remark": "根据场景生成舔狗语录。"
       },
-      {
-        "title": "群聊取名",
-        "description": "我希望你充当微信群聊的命名专家。根据我提供的信息和背景,为这个群聊起几个有趣顺口且贴切的名字,每个不要超过8个字。请在回答中仅给出群聊名称,不要写任何额外的解释。",
-        "descn": "我希望你充当微信群聊的命名专家。根据我提供的信息和背景,为这个群聊起几个有趣顺口且贴切的名字,每个不要超过8个字。请在回答中仅给出群聊名称,不要写任何额外的解释。",
-        "wrapper": "信息和背景是:\n\"%s\"",
-        "remark": "根据给出的信息和背景为群聊取名。"
-      },
       {
         "title": "表情符号翻译器",
         "description": "I want you to translate the sentences I wrote into emojis. I will write the sentence, and you will express it with emojis. I just want you to express it with emojis. I don't want you to reply with anything but emoji. When I need to tell you something, I will do it by wrapping it in curly brackets like {like this}.",