mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-08-19 08:50:58 +00:00
Merge pull request #372 from RockChinQ/363-bug-helpmessage-creditapi
[Fix] help_message问题、额度检测接口问题
This commit is contained in:
+1
-1
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,
|
||||||
|
|||||||
@@ -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
|
||||||
|
|
||||||
@@ -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 = []
|
return True, 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
|
|
||||||
@@ -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]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user