Просмотр исходного кода

Plugins: register function add namecn

develop
JS00000 1 год назад
Родитель
Сommit
6901c5ba56
8 измененных файлов: 29 добавлений и 34 удалений
  1. +1
    -1
      plugins/banwords/banwords.py
  2. +1
    -1
      plugins/bdunit/bdunit.py
  3. +1
    -1
      plugins/dungeon/dungeon.py
  4. +1
    -1
      plugins/finish/finish.py
  5. +16
    -23
      plugins/godcmd/godcmd.py
  6. +1
    -1
      plugins/hello/hello.py
  7. +7
    -5
      plugins/plugin_manager.py
  8. +1
    -1
      plugins/role/role.py

+ 1
- 1
plugins/banwords/banwords.py Просмотреть файл

@@ -10,7 +10,7 @@ from common.log import logger
from .WordsSearch import WordsSearch


@plugins.register(name="Banwords", desc="判断消息中是否有敏感词、决定是否回复。", version="1.0", author="lanvent", desire_priority= 100)
@plugins.register(name="Banwords", desire_priority=100, hidden=True, desc="判断消息中是否有敏感词、决定是否回复。", version="1.0", author="lanvent")
class Banwords(Plugin):
def __init__(self):
super().__init__()


+ 1
- 1
plugins/bdunit/bdunit.py Просмотреть файл

@@ -16,7 +16,7 @@ from uuid import getnode as get_mac
"""


@plugins.register(name="BDunit", desc="Baidu unit bot system", version="0.1", author="jackson", desire_priority=0)
@plugins.register(name="BDunit", desire_priority=0, desc="Baidu unit bot system", version="0.1", author="jackson")
class BDunit(Plugin):
def __init__(self):
super().__init__()


+ 1
- 1
plugins/dungeon/dungeon.py Просмотреть файл

@@ -35,7 +35,7 @@ class StoryTeller():
return prompt


@plugins.register(name="文字冒险", desc="A plugin to play dungeon game", version="1.0", author="lanvent", desire_priority= 0)
@plugins.register(name="Dungeon", desire_priority=0, namecn="文字冒险", desc="A plugin to play dungeon game", version="1.0", author="lanvent")
class Dungeon(Plugin):
def __init__(self):
super().__init__()


+ 1
- 1
plugins/finish/finish.py Просмотреть файл

@@ -7,7 +7,7 @@ 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)
@plugins.register(name="Finish", desire_priority=-999, hidden=True, desc="A plugin that check unknow command", version="1.0", author="js00000")
class Finish(Plugin):
def __init__(self):
super().__init__()


+ 16
- 23
plugins/godcmd/godcmd.py Просмотреть файл

@@ -103,7 +103,7 @@ ADMIN_COMMANDS = {
def get_help_text(isadmin, isgroup):
help_text = "通用指令:\n"
for cmd, info in COMMANDS.items():
if cmd=="auth": # 隐藏认证指令
if cmd=="auth": #不提示认证指令
continue

alias=["#"+a for a in info['alias']]
@@ -116,10 +116,11 @@ def get_help_text(isadmin, isgroup):
# 插件指令
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)
if plugins[plugin].enabled and not plugins[plugin].hidden:
namecn = plugins[plugin].namecn
print(namecn)
help_text += "\n%s:\n"%namecn
help_text += "#帮助 %s: 关于%s的详细帮助\n"%(namecn,namecn)
help_text += PluginManager().instances[plugin].get_help_text(verbose=False)

if ADMIN_COMMANDS and isadmin:
@@ -130,7 +131,7 @@ def get_help_text(isadmin, isgroup):
help_text += f": {info['desc']}\n"
return help_text

@plugins.register(name="Godcmd", desc="为你的机器人添加指令集,有用户和管理员两种角色,加载顺序请放在首位,初次运行后插件目录会生成配置文件, 填充管理员密码后即可认证", version="1.0", author="lanvent", desire_priority= 999)
@plugins.register(name="Godcmd", desire_priority=999, hidden=True, desc="为你的机器人添加指令集,有用户和管理员两种角色,加载顺序请放在首位,初次运行后插件目录会生成配置文件, 填充管理员密码后即可认证", version="1.0", author="lanvent")
class Godcmd(Plugin):

def __init__(self):
@@ -188,12 +189,16 @@ class Godcmd(Plugin):
if len(args) == 0:
ok, result = True, get_help_text(isadmin, isgroup)
elif len(args) == 1:
# This can replace the helpp command
plugins = PluginManager().list_plugins()
name = args[0].upper()
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, "unknown args"
query_name = args[0].upper()
# search name and namecn
for name, plugincls in plugins.items():
if query_name == name or query_name == plugincls.namecn:
ok, result = True, PluginManager().instances[name].get_help_text(verbose=True)
break
if not ok:
result = "unknown args"
elif cmd == "set_openai_api_key":
if len(args) == 1:
user_data = conf().get_user_data(user)
@@ -208,18 +213,6 @@ class Godcmd(Plugin):
except Exception as e:
ok, result = False, "你没有设置私有api_key"
ok, result = True, "你的OpenAI私有api_key已清除"
# 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)


+ 1
- 1
plugins/hello/hello.py Просмотреть файл

@@ -8,7 +8,7 @@ from plugins import *
from common.log import logger


@plugins.register(name="Hello", desc="A simple plugin that says hello", version="0.1", author="lanvent", desire_priority= -1)
@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__()


+ 7
- 5
plugins/plugin_manager.py Просмотреть файл

@@ -18,16 +18,18 @@ class PluginManager:
self.instances = {}
self.pconf = {}

def register(self, name: str, desc: str, version: str, author: str, desire_priority: int = 0):
def register(self, name: str, desire_priority: int = 0, **kwargs):
def wrapper(plugincls):
plugincls.name = name
plugincls.desc = desc
plugincls.version = version
plugincls.author = author
plugincls.priority = desire_priority
plugincls.desc = kwargs.get('desc')
plugincls.author = kwargs.get('author')
plugincls.version = kwargs.get('version') if kwargs.get('version') != None else "1.0"
plugincls.namecn = kwargs.get('namecn') if kwargs.get('namecn') != None else name
plugincls.hidden = kwargs.get('hidden') if kwargs.get('hidden') != None else False
plugincls.enabled = True
self.plugins[name.upper()] = plugincls
logger.info("Plugin %s_v%s registered" % (name, version))
logger.info("Plugin %s_v%s registered" % (name, plugincls.version))
return plugincls
return wrapper



+ 1
- 1
plugins/role/role.py Просмотреть файл

@@ -29,7 +29,7 @@ class RolePlay():
prompt = self.wrapper % user_action
return prompt

@plugins.register(name="角色扮演", desc="为你的Bot设置预设角色", version="1.0", author="lanvent", desire_priority= 0)
@plugins.register(name="Role", desire_priority=0, namecn="角色扮演", desc="为你的Bot设置预设角色", version="1.0", author="lanvent")
class Role(Plugin):
def __init__(self):
super().__init__()


Загрузка…
Отмена
Сохранить