Kaynağa Gözat

feat: add plugin_trigger_prefix option

master
lanvent 1 yıl önce
ebeveyn
işleme
62e3baba20
6 değiştirilmiş dosya ile 31 ekleme ve 18 silme
  1. +2
    -0
      config.py
  2. +7
    -5
      plugins/dungeon/dungeon.py
  3. +3
    -1
      plugins/finish/finish.py
  4. +3
    -0
      plugins/godcmd/godcmd.py
  5. +11
    -8
      plugins/role/role.py
  6. +5
    -4
      plugins/tool/tool.py

+ 2
- 0
config.py Dosyayı Görüntüle

@@ -88,6 +88,8 @@ available_setting = {

"debug": False, # 是否开启debug模式,开启后会打印更多日志

# 插件配置
"plugin_trigger_prefix": "$", # 规范插件提供聊天相关指令的前缀,建议不要和管理员指令前缀"#"冲突
}




+ 7
- 5
plugins/dungeon/dungeon.py Dosyayı Görüntüle

@@ -59,15 +59,16 @@ 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] == "$停止冒险":
trigger_prefix = conf().get('plugin_trigger_prefix', "$")
if clist[0] == f"{trigger_prefix}停止冒险":
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] == f"{trigger_prefix}开始冒险" or sessionid in self.games:
if sessionid not in self.games or clist[0] == f"{trigger_prefix}开始冒险":
if len(clist)>1 :
story = clist[1]
else:
@@ -85,7 +86,8 @@ class Dungeon(Plugin):
help_text = "可以和机器人一起玩文字冒险游戏。\n"
if kwargs.get('verbose') != True:
return help_text
help_text = "$开始冒险 {背景故事}: 开始一个基于{背景故事}的文字冒险,之后你的所有消息会协助完善这个故事。\n$停止冒险: 结束游戏。\n"
trigger_prefix = conf().get('plugin_trigger_prefix', "$")
help_text = f"{trigger_prefix}开始冒险 "+"{背景故事}: 开始一个基于{背景故事}的文字冒险,之后你的所有消息会协助完善这个故事。\n"+f"{trigger_prefix}停止冒险: 结束游戏。\n"
if kwargs.get('verbose') == True:
help_text += "\n命令例子: '$开始冒险 你在树林里冒险,指不定会从哪里蹦出来一些奇怪的东西,你握紧手上的手枪,希望这次冒险能够找到一些值钱的东西,你往树林深处走去。'"
help_text += f"\n命令例子: '{trigger_prefix}开始冒险 你在树林里冒险,指不定会从哪里蹦出来一些奇怪的东西,你握紧手上的手枪,希望这次冒险能够找到一些值钱的东西,你往树林深处走去。'"
return help_text

+ 3
- 1
plugins/finish/finish.py Dosyayı Görüntüle

@@ -2,6 +2,7 @@

from bridge.context import ContextType
from bridge.reply import Reply, ReplyType
from config import conf
import plugins
from plugins import *
from common.log import logger
@@ -21,7 +22,8 @@ class Finish(Plugin):

content = e_context['context'].content
logger.debug("[Finish] on_handle_context. content: %s" % content)
if content.startswith("$"):
trigger_prefix = conf().get('plugin_trigger_prefix',"$")
if content.startswith(trigger_prefix):
reply = Reply()
reply.type = ReplyType.ERROR
reply.content = "未知插件命令\n查看插件命令列表请输入#help {插件名}\n"


+ 3
- 0
plugins/godcmd/godcmd.py Dosyayı Görüntüle

@@ -312,6 +312,9 @@ class Godcmd(Plugin):
else:
ok, result = False, "需要管理员权限才能执行该指令"
else:
trigger_prefix = conf().get('plugin_trigger_prefix',"$")
if trigger_prefix == "#": # 跟插件聊天指令前缀相同,继续递交
return
ok, result = False, f"未知指令:{cmd}\n查看指令列表请输入#help \n"
reply = Reply()


+ 11
- 8
plugins/role/role.py Dosyayı Görüntüle

@@ -6,6 +6,7 @@ from bridge.bridge import Bridge
from bridge.context import ContextType
from bridge.reply import Reply, ReplyType
from common import const
from config import conf
import plugins
from plugins import *
from common.log import logger
@@ -82,7 +83,8 @@ class Role(Plugin):
desckey = None
customize = False
sessionid = e_context['context']['session_id']
if clist[0] == "$停止扮演":
trigger_prefix = conf().get('plugin_trigger_prefix', "$")
if clist[0] == f"{trigger_prefix}停止扮演":
if sessionid in self.roleplays:
self.roleplays[sessionid].reset()
del self.roleplays[sessionid]
@@ -90,11 +92,11 @@ class Role(Plugin):
e_context['reply'] = reply
e_context.action = EventAction.BREAK_PASS
return
elif clist[0] == "$角色":
elif clist[0] == f"{trigger_prefix}角色":
desckey = "descn"
elif clist[0].lower() == "$role":
elif clist[0].lower() == f"{trigger_prefix}role":
desckey = "description"
elif clist[0] == "$设定扮演":
elif clist[0] == f"{trigger_prefix}设定扮演":
customize = True
elif sessionid not in self.roleplays:
return
@@ -131,11 +133,12 @@ class Role(Plugin):
help_text = "让机器人扮演不同的角色。\n"
if not verbose:
return help_text
help_text = "使用方法:\n$角色 {预设角色名}: 设定为预设角色\n$role {预设角色名}: 同上,但使用英文设定\n"
help_text += "$设定扮演 {角色设定}: 设定自定义角色人设\n"
help_text += "$停止扮演: 清除设定的角色。\n"
trigger_prefix = conf().get('plugin_trigger_prefix', "$")
help_text = f"使用方法:\n{trigger_prefix}角色"+" {预设角色名}: 设定为预设角色。\n"+f"{trigger_prefix}role"+" {预设角色名}: 同上,但使用英文设定。\n"
help_text += f"{trigger_prefix}设定扮演"+" {角色设定}: 设定自定义角色人设。\n"
help_text += f"{trigger_prefix}停止扮演: 清除设定的角色。\n"
help_text += "\n目前可用的预设角色名列表: \n"
for role in self.roles:
help_text += f"{role}: {self.roles[role]['remark']}\n"
help_text += "\n命令例子: '$角色 写作助理'"
help_text += f"\n命令例子: '{trigger_prefix}角色 写作助理'"
return help_text

+ 5
- 4
plugins/tool/tool.py Dosyayı Görüntüle

@@ -30,9 +30,10 @@ class Tool(Plugin):
help_text = "这是一个能让chatgpt联网,搜索,数字运算的插件,将赋予强大且丰富的扩展能力。"
if not verbose:
return help_text
trigger_prefix = conf().get('plugin_trigger_prefix', "$")
help_text += "使用说明:\n"
help_text += "$tool {命令}: chatgpt会根据你的{命令}使用一些可用工具为你返回结果\n"
help_text += "$tool reset: 重置工具\n"
help_text += f"{trigger_prefix}tool "+"{命令}: 根据给出的命令使用一些可用工具尽力为你得到结果。\n"
help_text += f"{trigger_prefix}tool reset: 重置工具。\n"
return help_text

def on_handle_context(self, e_context: EventContext):
@@ -53,9 +54,9 @@ class Tool(Plugin):
logger.debug("[tool] on_handle_context. content: %s" % content)
reply = Reply()
reply.type = ReplyType.TEXT
trigger_prefix = conf().get('plugin_trigger_prefix', "$")
# todo: 有些工具必须要api-key,需要修改config文件,所以这里没有实现query增删tool的功能
if content.startswith("$tool"):
if content.startswith(f"{trigger_prefix}tool"):
if len(content_list) == 1:
logger.debug("[tool]: get help")
reply.content = self.get_help_text()


Yükleniyor…
İptal
Kaydet