Skip to content

Commit 6901c5b

Browse files
committed
Plugins: register function add namecn
1 parent 21a3b0d commit 6901c5b

File tree

8 files changed

+29
-34
lines changed

8 files changed

+29
-34
lines changed

plugins/banwords/banwords.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from .WordsSearch import WordsSearch
1111

1212

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

plugins/bdunit/bdunit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"""
1717

1818

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

plugins/dungeon/dungeon.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def action(self, user_action):
3535
return prompt
3636

3737

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

plugins/finish/finish.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from common.log import logger
88

99

10-
@plugins.register(name="Finish", desc="A plugin that check unknow command", version="1.0", author="js00000", desire_priority= -999)
10+
@plugins.register(name="Finish", desire_priority=-999, hidden=True, desc="A plugin that check unknow command", version="1.0", author="js00000")
1111
class Finish(Plugin):
1212
def __init__(self):
1313
super().__init__()

plugins/godcmd/godcmd.py

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103
def get_help_text(isadmin, isgroup):
104104
help_text = "通用指令:\n"
105105
for cmd, info in COMMANDS.items():
106-
if cmd=="auth": # 隐藏认证指令
106+
if cmd=="auth": #不提示认证指令
107107
continue
108108

109109
alias=["#"+a for a in info['alias']]
@@ -116,10 +116,11 @@ def get_help_text(isadmin, isgroup):
116116
# 插件指令
117117
plugins = PluginManager().list_plugins()
118118
for plugin in plugins:
119-
if plugin != 'GODCMD' and plugin != 'BANWORDS' and plugin != 'FINISH' and plugins[plugin].enabled:
120-
print(plugin)
121-
help_text += "\n%s:\n"%plugin
122-
help_text += "#帮助 %s: 关于%s的详细帮助\n"%(plugin,plugin)
119+
if plugins[plugin].enabled and not plugins[plugin].hidden:
120+
namecn = plugins[plugin].namecn
121+
print(namecn)
122+
help_text += "\n%s:\n"%namecn
123+
help_text += "#帮助 %s: 关于%s的详细帮助\n"%(namecn,namecn)
123124
help_text += PluginManager().instances[plugin].get_help_text(verbose=False)
124125

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

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

136137
def __init__(self):
@@ -188,12 +189,16 @@ def on_handle_context(self, e_context: EventContext):
188189
if len(args) == 0:
189190
ok, result = True, get_help_text(isadmin, isgroup)
190191
elif len(args) == 1:
192+
# This can replace the helpp command
191193
plugins = PluginManager().list_plugins()
192-
name = args[0].upper()
193-
if name in plugins and name != 'GODCMD' and name != 'BANWORDS' and plugins[name].enabled:
194-
ok, result = True, PluginManager().instances[name].get_help_text(verbose=True)
195-
else:
196-
ok, result = False, "unknown args"
194+
query_name = args[0].upper()
195+
# search name and namecn
196+
for name, plugincls in plugins.items():
197+
if query_name == name or query_name == plugincls.namecn:
198+
ok, result = True, PluginManager().instances[name].get_help_text(verbose=True)
199+
break
200+
if not ok:
201+
result = "unknown args"
197202
elif cmd == "set_openai_api_key":
198203
if len(args) == 1:
199204
user_data = conf().get_user_data(user)
@@ -208,18 +213,6 @@ def on_handle_context(self, e_context: EventContext):
208213
except Exception as e:
209214
ok, result = False, "你没有设置私有api_key"
210215
ok, result = True, "你的OpenAI私有api_key已清除"
211-
# elif cmd == "helpp":
212-
# if len(args) != 1:
213-
# ok, result = False, "请提供插件名"
214-
# else:
215-
# plugins = PluginManager().list_plugins()
216-
# name = args[0].upper()
217-
# if name in plugins and plugins[name].enabled:
218-
# ok, result = True, PluginManager().instances[name].get_help_text(isgroup=isgroup, isadmin=isadmin)
219-
# else:
220-
# ok, result= False, "插件不存在或未启用"
221-
# elif cmd == "id":
222-
# ok, result = True, f"用户id=\n{user}"
223216
elif cmd == "reset":
224217
if bottype in (const.CHATGPT, const.OPEN_AI):
225218
bot.sessions.clear_session(session_id)

plugins/hello/hello.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from common.log import logger
99

1010

11-
@plugins.register(name="Hello", desc="A simple plugin that says hello", version="0.1", author="lanvent", desire_priority= -1)
11+
@plugins.register(name="Hello", desire_priority=-1, hidden=True, desc="A simple plugin that says hello", version="0.1", author="lanvent")
1212
class Hello(Plugin):
1313
def __init__(self):
1414
super().__init__()

plugins/plugin_manager.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,18 @@ def __init__(self):
1818
self.instances = {}
1919
self.pconf = {}
2020

21-
def register(self, name: str, desc: str, version: str, author: str, desire_priority: int = 0):
21+
def register(self, name: str, desire_priority: int = 0, **kwargs):
2222
def wrapper(plugincls):
2323
plugincls.name = name
24-
plugincls.desc = desc
25-
plugincls.version = version
26-
plugincls.author = author
2724
plugincls.priority = desire_priority
25+
plugincls.desc = kwargs.get('desc')
26+
plugincls.author = kwargs.get('author')
27+
plugincls.version = kwargs.get('version') if kwargs.get('version') != None else "1.0"
28+
plugincls.namecn = kwargs.get('namecn') if kwargs.get('namecn') != None else name
29+
plugincls.hidden = kwargs.get('hidden') if kwargs.get('hidden') != None else False
2830
plugincls.enabled = True
2931
self.plugins[name.upper()] = plugincls
30-
logger.info("Plugin %s_v%s registered" % (name, version))
32+
logger.info("Plugin %s_v%s registered" % (name, plugincls.version))
3133
return plugincls
3234
return wrapper
3335

plugins/role/role.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def action(self, user_action):
2929
prompt = self.wrapper % user_action
3030
return prompt
3131

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

0 commit comments

Comments
 (0)