mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-06-09 15:26:03 +00:00
Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
48c7f659f9 | ||
|
|
b33333f4aa | ||
|
|
9edb32b081 | ||
|
|
c9b25fe806 | ||
|
|
b6ee3939be | ||
|
|
e5485cddd0 | ||
|
|
ac81597236 | ||
|
|
58d991df0a | ||
|
|
3f8e380da4 | ||
|
|
ae831a2654 | ||
|
|
ae72cf2283 |
Submodule QChatGPT.wiki updated: 1e3c599c03...d0dd0c1ad3
@@ -19,6 +19,7 @@
|
|||||||
"prompt": 1,
|
"prompt": 1,
|
||||||
"resend": 1,
|
"resend": 1,
|
||||||
"reset": 1,
|
"reset": 1,
|
||||||
|
"cmd": 1,
|
||||||
"help": 1,
|
"help": 1,
|
||||||
"reload": 2,
|
"reload": 2,
|
||||||
"update": 2,
|
"update": 2,
|
||||||
|
|||||||
@@ -1,2 +1 @@
|
|||||||
"""OpenAI 接口处理及会话管理相关
|
"""OpenAI 接口处理及会话管理相关"""
|
||||||
"""
|
|
||||||
|
|||||||
@@ -11,8 +11,7 @@ class KeysManager:
|
|||||||
"""所有api-key"""
|
"""所有api-key"""
|
||||||
|
|
||||||
using_key = ""
|
using_key = ""
|
||||||
"""当前使用的api-key
|
"""当前使用的api-key"""
|
||||||
"""
|
|
||||||
|
|
||||||
alerted = []
|
alerted = []
|
||||||
"""已提示过超额的key
|
"""已提示过超额的key
|
||||||
@@ -48,7 +47,7 @@ class KeysManager:
|
|||||||
|
|
||||||
self.auto_switch()
|
self.auto_switch()
|
||||||
|
|
||||||
def auto_switch(self) -> (bool, str):
|
def auto_switch(self) -> tuple[bool, str]:
|
||||||
"""尝试切换api-key
|
"""尝试切换api-key
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
@@ -79,8 +78,7 @@ class KeysManager:
|
|||||||
self.api_key[key_name] = key
|
self.api_key[key_name] = key
|
||||||
|
|
||||||
def set_current_exceeded(self):
|
def set_current_exceeded(self):
|
||||||
"""设置当前使用的api-key使用量超限
|
"""设置当前使用的api-key使用量超限"""
|
||||||
"""
|
|
||||||
self.exceeded.append(self.using_key)
|
self.exceeded.append(self.using_key)
|
||||||
|
|
||||||
def get_key_name(self, api_key):
|
def get_key_name(self, api_key):
|
||||||
|
|||||||
@@ -15,8 +15,7 @@ import pkg.plugin.settings as settings
|
|||||||
from mirai import Mirai
|
from mirai import Mirai
|
||||||
|
|
||||||
__plugins__ = {}
|
__plugins__ = {}
|
||||||
"""
|
"""插件列表
|
||||||
插件列表
|
|
||||||
|
|
||||||
示例:
|
示例:
|
||||||
{
|
{
|
||||||
@@ -35,7 +34,8 @@ __plugins__ = {}
|
|||||||
},
|
},
|
||||||
"instance": None
|
"instance": None
|
||||||
}
|
}
|
||||||
}"""
|
}
|
||||||
|
"""
|
||||||
|
|
||||||
__plugins_order__ = []
|
__plugins_order__ = []
|
||||||
"""插件顺序"""
|
"""插件顺序"""
|
||||||
@@ -117,8 +117,7 @@ def initialize_plugins():
|
|||||||
|
|
||||||
|
|
||||||
def unload_plugins():
|
def unload_plugins():
|
||||||
""" 卸载插件
|
"""卸载插件"""
|
||||||
"""
|
|
||||||
# 不再显式卸载插件,因为当程序结束时,插件的析构函数会被系统执行
|
# 不再显式卸载插件,因为当程序结束时,插件的析构函数会被系统执行
|
||||||
# for plugin in __plugins__.values():
|
# for plugin in __plugins__.values():
|
||||||
# if plugin['enabled'] and plugin['instance'] is not None:
|
# if plugin['enabled'] and plugin['instance'] is not None:
|
||||||
|
|||||||
@@ -98,6 +98,7 @@ class PluginUpdateCommand(AbstractCommandNode):
|
|||||||
|
|
||||||
reply = []
|
reply = []
|
||||||
def closure():
|
def closure():
|
||||||
|
try:
|
||||||
import pkg.utils.context
|
import pkg.utils.context
|
||||||
updated = []
|
updated = []
|
||||||
for key in plugin_list:
|
for key in plugin_list:
|
||||||
@@ -120,6 +121,10 @@ class PluginUpdateCommand(AbstractCommandNode):
|
|||||||
main.reset_logging()
|
main.reset_logging()
|
||||||
|
|
||||||
pkg.utils.context.get_qqbot_manager().notify_admin("已更新插件: {}".format(", ".join(updated)))
|
pkg.utils.context.get_qqbot_manager().notify_admin("已更新插件: {}".format(", ".join(updated)))
|
||||||
|
except Exception as e:
|
||||||
|
logging.error("插件更新失败:{}".format(e))
|
||||||
|
pkg.utils.context.get_qqbot_manager().notify_admin("插件更新失败:{} 请尝试手动更新插件".format(e))
|
||||||
|
|
||||||
|
|
||||||
threading.Thread(target=closure).start()
|
threading.Thread(target=closure).start()
|
||||||
reply = ["[bot]正在更新所有插件,请勿重复发起..."]
|
reply = ["[bot]正在更新所有插件,请勿重复发起..."]
|
||||||
|
|||||||
39
pkg/qqbot/cmds/system/cmd.py
Normal file
39
pkg/qqbot/cmds/system/cmd.py
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
from ..mgr import AbstractCommandNode, Context, __command_list__
|
||||||
|
|
||||||
|
|
||||||
|
@AbstractCommandNode.register(
|
||||||
|
parent=None,
|
||||||
|
name="cmd",
|
||||||
|
description="显示指令列表",
|
||||||
|
usage="!cmd\n!cmd <指令名称>",
|
||||||
|
aliases=[],
|
||||||
|
privilege=1
|
||||||
|
)
|
||||||
|
class CmdCommand(AbstractCommandNode):
|
||||||
|
@classmethod
|
||||||
|
def process(cls, ctx: Context) -> tuple[bool, list]:
|
||||||
|
command_list = __command_list__
|
||||||
|
|
||||||
|
reply = []
|
||||||
|
|
||||||
|
if len(ctx.params) == 0:
|
||||||
|
reply_str = "[bot]当前所有指令:\n\n"
|
||||||
|
|
||||||
|
# 遍历顶级指令
|
||||||
|
for key in command_list:
|
||||||
|
command = command_list[key]
|
||||||
|
if command['parent'] is None:
|
||||||
|
reply_str += "!{} - {}\n".format(key, command['description'])
|
||||||
|
|
||||||
|
reply_str += "\n请使用 !cmd <指令名称> 来查看指令的详细信息"
|
||||||
|
|
||||||
|
reply = [reply_str]
|
||||||
|
else:
|
||||||
|
command_name = ctx.params[0]
|
||||||
|
if command_name in command_list:
|
||||||
|
reply = [command_list[command_name]['cls'].help()]
|
||||||
|
else:
|
||||||
|
reply = ["[bot]指令 {} 不存在".format(command_name)]
|
||||||
|
|
||||||
|
return True, reply
|
||||||
|
|
||||||
39
pkg/qqbot/cmds/system/cmds.py
Normal file
39
pkg/qqbot/cmds/system/cmds.py
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
from ..mgr import AbstractCommandNode, Context, __command_list__
|
||||||
|
|
||||||
|
|
||||||
|
@AbstractCommandNode.register(
|
||||||
|
parent=None,
|
||||||
|
name="cmd",
|
||||||
|
description="显示指令列表",
|
||||||
|
usage="!help\n!help <指令名称>",
|
||||||
|
aliases=[],
|
||||||
|
privilege=1
|
||||||
|
)
|
||||||
|
class CmdCommand(AbstractCommandNode):
|
||||||
|
@classmethod
|
||||||
|
def process(cls, ctx: Context) -> tuple[bool, list]:
|
||||||
|
command_list = __command_list__
|
||||||
|
|
||||||
|
reply = []
|
||||||
|
|
||||||
|
if len(ctx.params) == 0:
|
||||||
|
reply_str = "[bot]当前所有指令:\n\n"
|
||||||
|
|
||||||
|
# 遍历顶级指令
|
||||||
|
for key in command_list:
|
||||||
|
command = command_list[key]
|
||||||
|
if command['parent'] is None:
|
||||||
|
reply_str += "!{} - {}\n".format(key, command['description'])
|
||||||
|
|
||||||
|
reply_str += "\n请使用 !cmd <指令名称> 来查看指令的详细信息"
|
||||||
|
|
||||||
|
reply = [reply_str]
|
||||||
|
else:
|
||||||
|
command_name = ctx.params[0]
|
||||||
|
if command_name in command_list:
|
||||||
|
reply = [command_list[command_name]['cls'].help()]
|
||||||
|
else:
|
||||||
|
reply = ["[bot]指令 {} 不存在".format(command_name)]
|
||||||
|
|
||||||
|
return True, reply
|
||||||
|
|
||||||
@@ -1,38 +1,19 @@
|
|||||||
from ..mgr import AbstractCommandNode, Context, __command_list__
|
from ..mgr import AbstractCommandNode, Context
|
||||||
|
|
||||||
|
|
||||||
@AbstractCommandNode.register(
|
@AbstractCommandNode.register(
|
||||||
parent=None,
|
parent=None,
|
||||||
name="help",
|
name="help",
|
||||||
description="显示帮助信息",
|
description="显示自定义的帮助信息",
|
||||||
usage="!help\n!help <指令名称>",
|
usage="!help",
|
||||||
aliases=[],
|
aliases=[],
|
||||||
privilege=1
|
privilege=1
|
||||||
)
|
)
|
||||||
class HelpCommand(AbstractCommandNode):
|
class HelpCommand(AbstractCommandNode):
|
||||||
@classmethod
|
@classmethod
|
||||||
def process(cls, ctx: Context) -> tuple[bool, list]:
|
def process(cls, ctx: Context) -> tuple[bool, list]:
|
||||||
command_list = __command_list__
|
import config
|
||||||
|
reply = [(config.help_message if hasattr(config, 'help_message') else "") + "\n请输入 !cmds 查看指令列表"]
|
||||||
reply = []
|
|
||||||
|
|
||||||
if len(ctx.params) == 0:
|
|
||||||
reply_str = "[bot]当前所有指令:\n\n"
|
|
||||||
|
|
||||||
# 遍历顶级指令
|
|
||||||
for key in command_list:
|
|
||||||
command = command_list[key]
|
|
||||||
if command['parent'] is None:
|
|
||||||
reply_str += "!{} - {}\n".format(key, command['description'])
|
|
||||||
|
|
||||||
reply_str += "\n请使用 !help <指令名称> 来查看指令的详细信息"
|
|
||||||
|
|
||||||
reply = [reply_str]
|
|
||||||
else:
|
|
||||||
command_name = ctx.params[0]
|
|
||||||
if command_name in command_list:
|
|
||||||
reply = [command_list[command_name]['cls'].help()]
|
|
||||||
else:
|
|
||||||
reply = ["[bot]指令 {} 不存在".format(command_name)]
|
|
||||||
|
|
||||||
return True, reply
|
return True, reply
|
||||||
|
|
||||||
@@ -29,13 +29,6 @@ class UsageCommand(AbstractCommandNode):
|
|||||||
.get_image_count_of_key(api_keys[key_name])
|
.get_image_count_of_key(api_keys[key_name])
|
||||||
reply_str += "{}:\n - 文本长度:{}\n - 图片数量:{}\n".format(key_name, int(text_length),
|
reply_str += "{}:\n - 文本长度:{}\n - 图片数量:{}\n".format(key_name, int(text_length),
|
||||||
int(image_count))
|
int(image_count))
|
||||||
# 获取此key的额度
|
|
||||||
try:
|
|
||||||
http_proxy = config.openai_config["http_proxy"] if "http_proxy" in config.openai_config else None
|
|
||||||
credit_data = credit.fetch_credit_data(api_keys[key_name], http_proxy)
|
|
||||||
reply_str += " - 使用额度:{:.2f}/{:.2f}\n".format(credit_data['total_used'],credit_data['total_granted'])
|
|
||||||
except Exception as e:
|
|
||||||
logging.warning("获取额度失败:{}".format(e))
|
|
||||||
|
|
||||||
reply = [reply_str]
|
reply = [reply_str]
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -4,9 +4,7 @@ from concurrent.futures import ThreadPoolExecutor
|
|||||||
|
|
||||||
|
|
||||||
class Pool:
|
class Pool:
|
||||||
'''
|
"""线程池结构"""
|
||||||
线程池结构
|
|
||||||
'''
|
|
||||||
pool_num:int = None
|
pool_num:int = None
|
||||||
ctl:ThreadPoolExecutor = None
|
ctl:ThreadPoolExecutor = None
|
||||||
task_list:list = None
|
task_list:list = None
|
||||||
@@ -33,12 +31,11 @@ class Pool:
|
|||||||
|
|
||||||
class ThreadCtl:
|
class ThreadCtl:
|
||||||
def __init__(self, sys_pool_num, admin_pool_num, user_pool_num):
|
def __init__(self, sys_pool_num, admin_pool_num, user_pool_num):
|
||||||
'''
|
"""线程池控制类
|
||||||
线程池控制类
|
|
||||||
sys_pool_num:分配系统使用的线程池数量(>=8)
|
sys_pool_num:分配系统使用的线程池数量(>=8)
|
||||||
admin_pool_num:用于处理管理员消息的线程池数量(>=1)
|
admin_pool_num:用于处理管理员消息的线程池数量(>=1)
|
||||||
user_pool_num:分配用于处理用户消息的线程池的数量(>=1)
|
user_pool_num:分配用于处理用户消息的线程池的数量(>=1)
|
||||||
'''
|
"""
|
||||||
if sys_pool_num < 5:
|
if sys_pool_num < 5:
|
||||||
raise Exception("Too few system threads(sys_pool_num needs >= 8, but received {})".format(sys_pool_num))
|
raise Exception("Too few system threads(sys_pool_num needs >= 8, but received {})".format(sys_pool_num))
|
||||||
if admin_pool_num < 1:
|
if admin_pool_num < 1:
|
||||||
|
|||||||
Reference in New Issue
Block a user