2023-03-01 09:10:45 +00:00
|
|
|
import re
|
2022-08-27 16:17:01 +00:00
|
|
|
import traceback
|
|
|
|
|
2023-02-05 14:33:33 +00:00
|
|
|
from core.builtins import Image, Plain, Bot
|
2023-03-04 08:51:56 +00:00
|
|
|
from core.component import module
|
2023-05-02 14:31:41 +00:00
|
|
|
from config import Config
|
2022-08-27 16:17:01 +00:00
|
|
|
from core.exceptions import InvalidHelpDocTypeError
|
|
|
|
from core.loader import ModulesManager
|
|
|
|
from core.parser.command import CommandParser
|
2023-02-07 17:55:45 +00:00
|
|
|
from core.utils.image_table import ImageTable, image_table_render
|
2022-08-27 16:17:01 +00:00
|
|
|
from database import BotDBUtil
|
|
|
|
|
2023-03-04 08:51:56 +00:00
|
|
|
m = module('module',
|
|
|
|
base=True,
|
|
|
|
alias={'enable': 'module enable',
|
|
|
|
'disable': 'module disable',
|
|
|
|
'reload': 'module reload'},
|
|
|
|
developers=['OasisAkari', 'Light-Beacon'],
|
|
|
|
required_admin=True
|
|
|
|
)
|
2022-08-27 16:17:01 +00:00
|
|
|
|
|
|
|
|
2023-05-19 04:46:29 +00:00
|
|
|
@m.command(['enable <module>... {{core.help.module.enable}}',
|
|
|
|
'enable all {{core.help.module.enable_all}}',
|
|
|
|
'disable <module>... {{core.help.module.disable}}',
|
|
|
|
'disable all {{core.help.module.disable_all}}',
|
|
|
|
'reload <module> ... {{core.help.module.reload}}',
|
|
|
|
'list {{core.help.module.list}}'], exclude_from=['QQ|Guild'])
|
2023-02-05 14:33:33 +00:00
|
|
|
async def _(msg: Bot.MessageSession):
|
2022-08-27 16:17:01 +00:00
|
|
|
if msg.parsed_msg.get('list', False):
|
|
|
|
await modules_help(msg)
|
|
|
|
await config_modules(msg)
|
|
|
|
|
|
|
|
|
2023-05-19 04:46:29 +00:00
|
|
|
@m.command(['enable <module>... {{core.help.module.enable}}',
|
|
|
|
'enable all {{core.help.module.enable_all}}',
|
|
|
|
'disable <module>... {{core.help.module.disable}}',
|
|
|
|
'disable all {{core.help.module.disable_all}}',
|
|
|
|
'reload <module> ... {{core.help.module.reload}}',
|
2023-05-21 03:48:33 +00:00
|
|
|
'list {{core.help.module.list}}'], options_desc={'-g': '{core.help.option.tion.tion.tion.tion.module.g}'},
|
2023-03-04 08:51:56 +00:00
|
|
|
available_for=['QQ|Guild'])
|
2023-02-05 14:33:33 +00:00
|
|
|
async def _(msg: Bot.MessageSession):
|
2022-08-27 16:17:01 +00:00
|
|
|
if msg.parsed_msg.get('list', False):
|
|
|
|
await modules_help(msg)
|
|
|
|
await config_modules(msg)
|
|
|
|
|
|
|
|
|
2023-02-05 14:33:33 +00:00
|
|
|
async def config_modules(msg: Bot.MessageSession):
|
2023-04-19 08:29:46 +00:00
|
|
|
alias = ModulesManager.modules_aliases
|
2023-04-19 08:38:23 +00:00
|
|
|
modules_ = ModulesManager.return_modules_list(
|
2023-01-22 05:40:53 +00:00
|
|
|
targetFrom=msg.target.targetFrom)
|
2022-08-27 16:17:01 +00:00
|
|
|
enabled_modules_list = BotDBUtil.TargetInfo(msg).enabled_modules
|
2023-01-22 05:40:53 +00:00
|
|
|
wait_config = [msg.parsed_msg.get(
|
|
|
|
'<module>')] + msg.parsed_msg.get('...', [])
|
2022-08-27 16:17:01 +00:00
|
|
|
wait_config_list = []
|
|
|
|
for module_ in wait_config:
|
|
|
|
if module_ not in wait_config_list:
|
|
|
|
if module_ in alias:
|
|
|
|
wait_config_list.append(alias[module_])
|
|
|
|
else:
|
|
|
|
wait_config_list.append(module_)
|
|
|
|
msglist = []
|
|
|
|
recommend_modules_list = []
|
|
|
|
recommend_modules_help_doc_list = []
|
|
|
|
if msg.parsed_msg.get('enable', False):
|
|
|
|
enable_list = []
|
|
|
|
if msg.parsed_msg.get('all', False):
|
|
|
|
for function in modules_:
|
|
|
|
if function[0] == '_':
|
|
|
|
continue
|
2023-03-04 08:51:56 +00:00
|
|
|
if modules_[function].base or modules_[function].required_superuser:
|
2022-08-27 16:17:01 +00:00
|
|
|
continue
|
|
|
|
enable_list.append(function)
|
|
|
|
else:
|
|
|
|
for module_ in wait_config_list:
|
|
|
|
if module_ not in modules_:
|
2023-05-19 04:46:29 +00:00
|
|
|
msglist.append(msg.locale.t("core.message.module.enable.not_found", module=module_))
|
2022-08-27 16:17:01 +00:00
|
|
|
else:
|
|
|
|
if modules_[module_].required_superuser and not msg.checkSuperUser():
|
2023-05-19 04:46:29 +00:00
|
|
|
msglist.append(msg.locale.t("core.message.module.enable.perimission.denied",
|
2023-03-08 11:40:16 +00:00
|
|
|
module=module_))
|
2023-03-04 08:51:56 +00:00
|
|
|
elif modules_[module_].base:
|
2023-05-19 04:46:29 +00:00
|
|
|
msglist.append(msg.locale.t("core.message.module.enable.base", module=module_))
|
2022-08-27 16:17:01 +00:00
|
|
|
else:
|
|
|
|
enable_list.append(module_)
|
|
|
|
recommend = modules_[module_].recommend_modules
|
|
|
|
if recommend is not None:
|
|
|
|
for r in recommend:
|
|
|
|
if r not in enable_list and r not in enabled_modules_list:
|
|
|
|
recommend_modules_list.append(r)
|
|
|
|
if '-g' in msg.parsed_msg and msg.parsed_msg['-g']:
|
|
|
|
get_all_channel = await msg.get_text_channel_list()
|
|
|
|
for x in get_all_channel:
|
|
|
|
query = BotDBUtil.TargetInfo(f'{msg.target.targetFrom}|{x}')
|
|
|
|
query.enable(enable_list)
|
|
|
|
for x in enable_list:
|
2023-05-19 04:46:29 +00:00
|
|
|
msglist.append(msg.locale.t("core.message.module.enable.qq_channel_global.success", module=x))
|
2022-08-27 16:17:01 +00:00
|
|
|
else:
|
|
|
|
if msg.data.enable(enable_list):
|
|
|
|
for x in enable_list:
|
|
|
|
if x in enabled_modules_list:
|
2023-05-19 04:46:29 +00:00
|
|
|
msglist.append(msg.locale.t("core.message.module.enable.already", module=x))
|
2022-08-27 16:17:01 +00:00
|
|
|
else:
|
2023-05-19 04:46:29 +00:00
|
|
|
msglist.append(msg.locale.t("core.message.module.enable.success", module=x))
|
2023-04-05 05:36:11 +00:00
|
|
|
support_lang = modules_[x].support_languages
|
|
|
|
if support_lang is not None:
|
|
|
|
if msg.locale.locale not in support_lang:
|
2023-05-19 04:46:29 +00:00
|
|
|
msglist.append(msg.locale.t("core.message.module.unsupported_language",
|
2023-04-05 05:36:11 +00:00
|
|
|
module=x))
|
2022-08-27 16:17:01 +00:00
|
|
|
if recommend_modules_list:
|
|
|
|
for m in recommend_modules_list:
|
|
|
|
try:
|
2023-05-19 04:46:29 +00:00
|
|
|
recommend_modules_help_doc_list.append(msg.locale.t("core.message.module.module.help", module=m
|
2023-03-08 11:40:16 +00:00
|
|
|
))
|
2022-08-27 16:17:01 +00:00
|
|
|
|
|
|
|
if modules_[m].desc is not None:
|
2023-03-09 14:18:57 +00:00
|
|
|
d_ = modules_[m].desc
|
|
|
|
if locale_str := re.findall(r'\{(.*)}', d_):
|
|
|
|
for l in locale_str:
|
2023-03-14 10:14:05 +00:00
|
|
|
d_ = d_.replace(f'{{{l}}}', msg.locale.t(l, fallback_failed_prompt=False))
|
2023-03-09 14:18:57 +00:00
|
|
|
recommend_modules_help_doc_list.append(d_)
|
2023-03-04 08:51:56 +00:00
|
|
|
hdoc = CommandParser(modules_[m], msg=msg, bind_prefix=modules_[m].bind_prefix,
|
|
|
|
command_prefixes=msg.prefixes).return_formatted_help_doc()
|
|
|
|
if hdoc == '':
|
2023-03-04 10:08:40 +00:00
|
|
|
hdoc = msg.locale.t('core.help.none')
|
2023-03-04 08:51:56 +00:00
|
|
|
recommend_modules_help_doc_list.append(hdoc)
|
2022-08-27 16:17:01 +00:00
|
|
|
except InvalidHelpDocTypeError:
|
|
|
|
pass
|
|
|
|
elif msg.parsed_msg.get('disable', False):
|
|
|
|
disable_list = []
|
|
|
|
if msg.parsed_msg.get('all', False):
|
|
|
|
for function in modules_:
|
|
|
|
if function[0] == '_':
|
|
|
|
continue
|
2023-03-04 08:51:56 +00:00
|
|
|
if modules_[function].base or modules_[function].required_superuser:
|
2022-08-27 16:17:01 +00:00
|
|
|
continue
|
|
|
|
disable_list.append(function)
|
|
|
|
else:
|
|
|
|
for module_ in wait_config_list:
|
|
|
|
if module_ not in modules_:
|
2023-05-19 04:46:29 +00:00
|
|
|
msglist.append(msg.locale.t("core.message.module.disable.not_found", module=module_))
|
2022-08-27 16:17:01 +00:00
|
|
|
else:
|
|
|
|
if modules_[module_].required_superuser and not msg.checkSuperUser():
|
2023-05-19 04:46:29 +00:00
|
|
|
msglist.append(msg.locale.t("core.message.module.disable.permission.denied",
|
2023-03-08 11:40:16 +00:00
|
|
|
module=module_))
|
2023-03-04 08:51:56 +00:00
|
|
|
elif modules_[module_].base:
|
2023-05-19 04:46:29 +00:00
|
|
|
msglist.append(msg.locale.t("core.message.module.disable.base", module=module_))
|
2022-08-27 16:17:01 +00:00
|
|
|
else:
|
|
|
|
disable_list.append(module_)
|
|
|
|
if '-g' in msg.parsed_msg and msg.parsed_msg['-g']:
|
|
|
|
get_all_channel = await msg.get_text_channel_list()
|
|
|
|
for x in get_all_channel:
|
|
|
|
query = BotDBUtil.TargetInfo(f'{msg.target.targetFrom}|{x}')
|
|
|
|
query.disable(disable_list)
|
|
|
|
for x in disable_list:
|
2023-05-19 04:46:29 +00:00
|
|
|
msglist.append(msg.locale.t("core.message.module.disable.qqchannel_global.success", module=x))
|
2022-08-27 16:17:01 +00:00
|
|
|
else:
|
|
|
|
if msg.data.disable(disable_list):
|
|
|
|
for x in disable_list:
|
|
|
|
if x not in enabled_modules_list:
|
2023-05-19 04:46:29 +00:00
|
|
|
msglist.append(msg.locale.t("core.message.module.disable.already", module=x))
|
2022-08-27 16:17:01 +00:00
|
|
|
else:
|
2023-05-19 04:46:29 +00:00
|
|
|
msglist.append(msg.locale.t("core.message.module.disable.success", module=x))
|
2023-01-26 07:31:13 +00:00
|
|
|
elif msg.parsed_msg.get('reload', False):
|
2023-01-26 07:49:44 +00:00
|
|
|
if msg.checkSuperUser():
|
2023-03-08 11:40:16 +00:00
|
|
|
def module_reload(module, extra_modules):
|
|
|
|
reloadCnt = ModulesManager.reload_module(module)
|
|
|
|
if reloadCnt > 1:
|
2023-05-19 04:46:29 +00:00
|
|
|
return f'{msg.locale.t("core.message.module.reload.success", module=module)}' + ' '.join(
|
|
|
|
extra_modules) + msg.locale.t("core.message.module.reload.with", reloadCnt=reloadCnt - 1)
|
2023-03-08 11:40:16 +00:00
|
|
|
elif reloadCnt == 1:
|
2023-05-19 04:46:29 +00:00
|
|
|
return f'{msg.locale.t("core.message.module.reload.success", module=module)}' + \
|
|
|
|
' '.join(extra_modules) + msg.locale.t("core.message.module.reload.no_more")
|
2023-03-08 11:40:16 +00:00
|
|
|
else:
|
2023-05-19 04:46:29 +00:00
|
|
|
return f'{msg.locale.t("core.message.module.reload.failed")}'
|
2023-03-14 10:14:05 +00:00
|
|
|
|
2023-01-26 07:49:44 +00:00
|
|
|
if '-f' in msg.parsed_msg and msg.parsed_msg['-f']:
|
|
|
|
msglist.append(module_reload(module_))
|
|
|
|
elif module_ not in modules_:
|
2023-05-19 04:46:29 +00:00
|
|
|
msglist.append(msg.locale.t("core.message.module.reload.unbound", module=module_))
|
2023-01-26 07:31:13 +00:00
|
|
|
else:
|
2023-03-04 08:51:56 +00:00
|
|
|
if modules_[module_].base:
|
2023-05-19 04:46:29 +00:00
|
|
|
msglist.append(msg.locale.t("core.message.module.reload.base", module=module_))
|
2023-01-26 07:31:13 +00:00
|
|
|
else:
|
2023-01-28 05:53:11 +00:00
|
|
|
extra_reload_modules = ModulesManager.search_related_module(module_, False)
|
2023-01-26 13:21:46 +00:00
|
|
|
if len(extra_reload_modules):
|
2023-05-19 04:46:29 +00:00
|
|
|
confirm = await msg.waitConfirm(msg.locale.t("core.message.module.reload.confirm",
|
2023-03-08 11:40:16 +00:00
|
|
|
modules='\n'.join(extra_reload_modules)))
|
2023-01-26 13:21:46 +00:00
|
|
|
if not confirm:
|
2023-01-27 09:26:05 +00:00
|
|
|
await msg.finish()
|
2023-01-26 13:21:46 +00:00
|
|
|
return
|
2023-01-28 05:53:11 +00:00
|
|
|
msglist.append(module_reload(module_, extra_reload_modules))
|
2023-01-26 07:49:44 +00:00
|
|
|
else:
|
2023-05-19 04:46:29 +00:00
|
|
|
msglist.append(msg.locale.t("core.message.module.reload.permission.denied"))
|
2022-08-27 16:17:01 +00:00
|
|
|
if msglist is not None:
|
|
|
|
if not recommend_modules_help_doc_list:
|
|
|
|
await msg.finish('\n'.join(msglist))
|
|
|
|
else:
|
|
|
|
await msg.sendMessage('\n'.join(msglist))
|
|
|
|
if recommend_modules_help_doc_list and ('-g' not in msg.parsed_msg or not msg.parsed_msg['-g']):
|
2023-05-19 04:46:29 +00:00
|
|
|
confirm = await msg.waitConfirm(msg.locale.t("core.message.module.recommends",
|
2023-04-30 03:30:59 +00:00
|
|
|
msgs='\n'.join(recommend_modules_list) + '\n\n' +
|
2023-03-08 11:40:16 +00:00
|
|
|
'\n'.join(recommend_modules_help_doc_list)))
|
2022-08-27 16:17:01 +00:00
|
|
|
if confirm:
|
|
|
|
if msg.data.enable(recommend_modules_list):
|
|
|
|
msglist = []
|
|
|
|
for x in recommend_modules_list:
|
2023-05-19 04:46:29 +00:00
|
|
|
msglist.append(msg.locale.t("core.message.module.enable.success", module=x))
|
2022-08-27 16:17:01 +00:00
|
|
|
await msg.finish('\n'.join(msglist))
|
|
|
|
else:
|
|
|
|
await msg.finish()
|
|
|
|
|
|
|
|
|
2023-03-04 08:51:56 +00:00
|
|
|
hlp = module('help',
|
|
|
|
base=True,
|
|
|
|
developers=['OasisAkari', 'Dianliang233'],
|
|
|
|
)
|
2022-08-27 16:17:01 +00:00
|
|
|
|
|
|
|
|
2023-05-19 04:46:29 +00:00
|
|
|
@hlp.command('<module> {{core.help.module.help.detail}}')
|
2023-02-05 14:33:33 +00:00
|
|
|
async def bot_help(msg: Bot.MessageSession):
|
2023-04-19 08:38:23 +00:00
|
|
|
module_list = ModulesManager.return_modules_list(
|
2023-01-22 05:40:53 +00:00
|
|
|
targetFrom=msg.target.targetFrom)
|
2023-04-19 08:29:46 +00:00
|
|
|
alias = ModulesManager.modules_aliases
|
2022-08-27 16:17:01 +00:00
|
|
|
if msg.parsed_msg is not None:
|
|
|
|
msgs = []
|
|
|
|
help_name = msg.parsed_msg['<module>']
|
|
|
|
if help_name in alias:
|
|
|
|
help_name = alias[help_name]
|
|
|
|
if help_name in module_list:
|
|
|
|
module_ = module_list[help_name]
|
|
|
|
if module_.desc is not None:
|
2023-03-01 09:10:45 +00:00
|
|
|
desc = module_.desc
|
|
|
|
if locale_str := re.match(r'\{(.*)}', desc):
|
|
|
|
if locale_str:
|
2023-03-04 10:08:40 +00:00
|
|
|
desc = msg.locale.t(locale_str.group(1))
|
2023-03-01 09:10:45 +00:00
|
|
|
msgs.append(desc)
|
2023-03-04 08:51:56 +00:00
|
|
|
help_ = CommandParser(module_list[help_name], msg=msg, bind_prefix=module_list[help_name].bind_prefix,
|
|
|
|
command_prefixes=msg.prefixes)
|
|
|
|
if help_.args:
|
|
|
|
msgs.append(help_.return_formatted_help_doc())
|
|
|
|
|
2022-08-27 16:17:01 +00:00
|
|
|
doc = '\n'.join(msgs)
|
2023-03-04 08:51:56 +00:00
|
|
|
if module_.regex_list.set:
|
2023-05-19 04:46:29 +00:00
|
|
|
doc += '\n' + msg.locale.t("core.message.module.help.support_regex")
|
2023-03-04 08:51:56 +00:00
|
|
|
for regex in module_.regex_list.set:
|
|
|
|
pattern = None
|
|
|
|
if isinstance(regex.pattern, str):
|
|
|
|
pattern = regex.pattern
|
|
|
|
elif isinstance(regex.pattern, re.Pattern):
|
|
|
|
pattern = regex.pattern.pattern
|
|
|
|
if pattern:
|
2023-03-09 14:18:57 +00:00
|
|
|
desc = regex.desc
|
|
|
|
if desc:
|
2023-03-11 11:27:26 +00:00
|
|
|
if locale_str := re.findall(r'\{(.*)}', desc):
|
2023-03-09 14:18:57 +00:00
|
|
|
for l in locale_str:
|
2023-03-14 10:14:05 +00:00
|
|
|
desc = desc.replace(f'{{{l}}}', msg.locale.t(l, fallback_failed_prompt=False))
|
2023-05-19 04:46:29 +00:00
|
|
|
doc += f'\n{pattern} ' + msg.locale.t("core.message.module.help.regex.detail",
|
2023-03-09 14:18:57 +00:00
|
|
|
msg=desc)
|
|
|
|
else:
|
2023-05-19 04:46:29 +00:00
|
|
|
doc += f'\n{pattern} ' + msg.locale.t("core.message.module.help.regex.no_information")
|
2023-03-04 08:51:56 +00:00
|
|
|
module_alias = module_.alias
|
2022-08-27 16:17:01 +00:00
|
|
|
malias = []
|
2023-03-04 08:51:56 +00:00
|
|
|
if module_alias:
|
|
|
|
for a in module_alias:
|
|
|
|
malias.append(f'{a} -> {module_alias[a]}')
|
|
|
|
if module_.developers is not None:
|
2023-03-08 11:40:16 +00:00
|
|
|
devs = '、'.join(module_.developers)
|
2022-08-27 16:17:01 +00:00
|
|
|
else:
|
|
|
|
devs = ''
|
2023-05-19 04:46:29 +00:00
|
|
|
devs_msg = '\n' + msg.locale.t("core.message.module.help.author.type1") + devs
|
|
|
|
wiki_msg = '\n' + msg.locale.t("core.message.module.help.helpdoc.address",
|
2023-05-12 18:20:52 +00:00
|
|
|
help_url=Config('help_url')) + '/' + help_name
|
2023-03-23 08:17:57 +00:00
|
|
|
if len(doc) > 500 and msg.Feature.image:
|
|
|
|
try:
|
2023-03-27 10:44:52 +00:00
|
|
|
tables = [ImageTable([[doc, '\n'.join(malias), devs]],
|
2023-05-19 04:46:29 +00:00
|
|
|
[msg.locale.t("core.message.module.help.table.header.help"),
|
|
|
|
msg.locale.t("core.message.module.help.table.header.alias"),
|
|
|
|
msg.locale.t("core.message.module.help.author.type2")])]
|
2023-03-23 08:17:57 +00:00
|
|
|
render = await image_table_render(tables)
|
|
|
|
if render:
|
|
|
|
await msg.finish([Image(render),
|
2023-03-23 08:20:46 +00:00
|
|
|
Plain(wiki_msg)])
|
2023-03-23 08:17:57 +00:00
|
|
|
except Exception:
|
|
|
|
traceback.print_exc()
|
|
|
|
if malias:
|
|
|
|
doc += f'\n{msg.locale.t("core.help.alias")}\n' + '\n'.join(malias)
|
2023-03-04 08:51:56 +00:00
|
|
|
await msg.finish(doc + devs_msg + wiki_msg)
|
2022-08-27 16:17:01 +00:00
|
|
|
else:
|
2023-05-19 04:46:29 +00:00
|
|
|
await msg.finish(msg.locale.t("core.message.module.help.not_found"))
|
2022-08-27 16:17:01 +00:00
|
|
|
|
|
|
|
|
2023-05-19 04:46:29 +00:00
|
|
|
@hlp.command('{{core.help.module.help}}')
|
2023-02-05 14:33:33 +00:00
|
|
|
async def _(msg: Bot.MessageSession):
|
2023-04-19 08:38:23 +00:00
|
|
|
module_list = ModulesManager.return_modules_list(
|
2023-01-22 05:40:53 +00:00
|
|
|
targetFrom=msg.target.targetFrom)
|
2022-08-27 16:17:01 +00:00
|
|
|
target_enabled_list = msg.enabled_modules
|
|
|
|
legacy_help = True
|
2023-02-07 17:55:45 +00:00
|
|
|
if msg.Feature.image:
|
2022-08-27 16:17:01 +00:00
|
|
|
try:
|
|
|
|
tables = []
|
|
|
|
essential = []
|
|
|
|
m = []
|
|
|
|
for x in module_list:
|
|
|
|
module_ = module_list[x]
|
|
|
|
appends = [module_.bind_prefix]
|
|
|
|
doc_ = []
|
2023-03-04 08:51:56 +00:00
|
|
|
help_ = CommandParser(module_, msg=msg, bind_prefix=module_.bind_prefix,
|
|
|
|
command_prefixes=msg.prefixes)
|
2022-08-27 16:17:01 +00:00
|
|
|
|
2023-03-04 08:51:56 +00:00
|
|
|
if module_.desc is not None:
|
2023-03-09 14:18:57 +00:00
|
|
|
d_ = module_.desc
|
|
|
|
if locale_str := re.findall(r'\{(.*)}', d_):
|
|
|
|
for l in locale_str:
|
2023-03-14 10:14:05 +00:00
|
|
|
d_ = d_.replace(f'{{{l}}}', msg.locale.t(l, fallback_failed_prompt=False))
|
2023-03-09 14:18:57 +00:00
|
|
|
doc_.append(d_)
|
2023-03-04 08:51:56 +00:00
|
|
|
if help_.args:
|
|
|
|
doc_.append(help_.return_formatted_help_doc())
|
2022-08-27 16:17:01 +00:00
|
|
|
doc = '\n'.join(doc_)
|
2023-03-04 08:51:56 +00:00
|
|
|
if module_.regex_list.set:
|
2023-05-19 04:46:29 +00:00
|
|
|
doc += '\n' + msg.locale.t("core.message.module.help.support_regex")
|
2023-03-04 08:51:56 +00:00
|
|
|
for regex in module_.regex_list.set:
|
|
|
|
pattern = None
|
|
|
|
if isinstance(regex.pattern, str):
|
|
|
|
pattern = regex.pattern
|
|
|
|
elif isinstance(regex.pattern, re.Pattern):
|
|
|
|
pattern = regex.pattern.pattern
|
|
|
|
if pattern:
|
2023-03-08 11:40:16 +00:00
|
|
|
desc = regex.desc
|
|
|
|
if desc:
|
2023-05-12 18:24:05 +00:00
|
|
|
if locale_str := re.findall(r'\{(.*)}', desc):
|
2023-03-08 11:40:16 +00:00
|
|
|
for l in locale_str:
|
2023-05-12 18:24:05 +00:00
|
|
|
desc = desc.replace(f'{{{l}}}', msg.locale.t(l, fallback_failed_prompt=False))
|
2023-05-19 04:46:29 +00:00
|
|
|
doc += f'\n{pattern} ' + msg.locale.t("core.message.module.help.regex.detail",
|
2023-03-08 11:40:16 +00:00
|
|
|
msg=desc)
|
|
|
|
else:
|
2023-05-19 04:46:29 +00:00
|
|
|
doc += f'\n{pattern} ' + msg.locale.t("core.message.module.help.regex.no_information")
|
2022-08-27 16:17:01 +00:00
|
|
|
appends.append(doc)
|
2023-03-04 08:51:56 +00:00
|
|
|
module_alias = module_.alias
|
2022-08-27 16:17:01 +00:00
|
|
|
malias = []
|
2023-03-04 08:51:56 +00:00
|
|
|
if module_alias:
|
|
|
|
for a in module_alias:
|
|
|
|
malias.append(f'{a} -> {module_alias[a]}')
|
2022-08-27 16:17:01 +00:00
|
|
|
appends.append('\n'.join(malias) if malias else '')
|
2023-03-04 08:51:56 +00:00
|
|
|
if module_.developers:
|
|
|
|
appends.append('、'.join(module_.developers))
|
|
|
|
if module_.base:
|
2022-08-27 16:17:01 +00:00
|
|
|
essential.append(appends)
|
|
|
|
if x in target_enabled_list:
|
|
|
|
m.append(appends)
|
|
|
|
if essential:
|
2023-01-22 05:40:53 +00:00
|
|
|
tables.append(ImageTable(
|
2023-05-19 04:46:29 +00:00
|
|
|
essential, [msg.locale.t("core.message.module.help.table.header.base"),
|
|
|
|
msg.locale.t("core.message.module.help.table.header.help"),
|
|
|
|
msg.locale.t("core.message.module.help.table.header.alias"),
|
|
|
|
msg.locale.t("core.message.module.help.author.type2")]))
|
2022-08-27 16:17:01 +00:00
|
|
|
if m:
|
2023-05-19 04:46:29 +00:00
|
|
|
tables.append(ImageTable(m, [msg.locale.t("core.message.module.help.table.header.external"),
|
|
|
|
msg.locale.t("core.message.module.help.table.header.help"),
|
|
|
|
msg.locale.t("core.message.module.help.table.header.alias"),
|
|
|
|
msg.locale.t("core.message.module.help.author.type2")]))
|
2022-08-27 16:17:01 +00:00
|
|
|
if tables:
|
|
|
|
render = await image_table_render(tables)
|
|
|
|
if render:
|
|
|
|
legacy_help = False
|
|
|
|
await msg.finish([Image(render),
|
2023-05-19 04:46:29 +00:00
|
|
|
Plain(msg.locale.t("core.message.module.help.more_information",
|
2023-05-02 14:31:41 +00:00
|
|
|
prefix=msg.prefixes[0], help_url=Config('help_url'), donate_url=Config('donate_url')))])
|
2022-08-27 16:17:01 +00:00
|
|
|
except Exception:
|
|
|
|
traceback.print_exc()
|
|
|
|
if legacy_help:
|
2023-05-19 04:46:29 +00:00
|
|
|
help_msg = [msg.locale.t("core.message.module.help.legacy.base")]
|
2022-08-27 16:17:01 +00:00
|
|
|
essential = []
|
|
|
|
for x in module_list:
|
2023-03-04 08:51:56 +00:00
|
|
|
if module_list[x].base:
|
2022-08-27 16:17:01 +00:00
|
|
|
essential.append(module_list[x].bind_prefix)
|
|
|
|
help_msg.append(' | '.join(essential))
|
2023-05-19 04:46:29 +00:00
|
|
|
help_msg.append(msg.locale.t("core.message.module.help.legacy.external"))
|
2022-08-27 16:17:01 +00:00
|
|
|
module_ = []
|
|
|
|
for x in module_list:
|
|
|
|
if x in target_enabled_list:
|
|
|
|
module_.append(x)
|
|
|
|
help_msg.append(' | '.join(module_))
|
2023-05-12 18:20:52 +00:00
|
|
|
help_msg.append(
|
|
|
|
msg.locale.t(
|
2023-05-19 04:46:29 +00:00
|
|
|
"core.message.module.help.legacy.more_information",
|
2023-05-12 18:20:52 +00:00
|
|
|
prefix=msg.prefixes[0],
|
|
|
|
help_url=Config('help_url')))
|
2022-08-27 16:17:01 +00:00
|
|
|
if msg.Feature.delete:
|
2023-05-19 04:46:29 +00:00
|
|
|
help_msg.append(msg.locale.t("core.message.module.help.revoke.legacy"))
|
2022-08-27 16:17:01 +00:00
|
|
|
send = await msg.sendMessage('\n'.join(help_msg))
|
|
|
|
await msg.sleep(60)
|
|
|
|
await send.delete()
|
|
|
|
|
|
|
|
|
2023-02-05 14:33:33 +00:00
|
|
|
async def modules_help(msg: Bot.MessageSession):
|
2023-04-19 08:38:23 +00:00
|
|
|
module_list = ModulesManager.return_modules_list(
|
2023-01-22 05:40:53 +00:00
|
|
|
targetFrom=msg.target.targetFrom)
|
2022-08-27 16:17:01 +00:00
|
|
|
legacy_help = True
|
2023-02-07 17:55:45 +00:00
|
|
|
if msg.Feature.image:
|
2022-08-27 16:17:01 +00:00
|
|
|
try:
|
|
|
|
tables = []
|
|
|
|
m = []
|
|
|
|
for x in module_list:
|
|
|
|
module_ = module_list[x]
|
|
|
|
if x[0] == '_':
|
|
|
|
continue
|
2023-03-04 08:51:56 +00:00
|
|
|
if module_.base or module_.required_superuser:
|
2022-08-27 16:17:01 +00:00
|
|
|
continue
|
|
|
|
appends = [module_.bind_prefix]
|
|
|
|
doc_ = []
|
2023-03-04 08:51:56 +00:00
|
|
|
help_ = CommandParser(
|
2023-04-11 10:46:02 +00:00
|
|
|
module_, bind_prefix=module_.bind_prefix, command_prefixes=msg.prefixes, msg=msg)
|
2023-03-04 08:51:56 +00:00
|
|
|
if module_.desc is not None:
|
2023-05-12 18:25:09 +00:00
|
|
|
desc = module_.desc
|
|
|
|
if locale_str := re.findall(r'\{(.*)}', desc):
|
|
|
|
for l in locale_str:
|
|
|
|
desc = desc.replace(f'{{{l}}}', msg.locale.t(l, fallback_failed_prompt=False))
|
|
|
|
doc_.append(desc)
|
2023-03-04 08:51:56 +00:00
|
|
|
if help_.args:
|
|
|
|
doc_.append(help_.return_formatted_help_doc())
|
2022-08-27 16:17:01 +00:00
|
|
|
doc = '\n'.join(doc_)
|
2023-03-04 08:51:56 +00:00
|
|
|
if module_.regex_list.set:
|
2023-05-19 04:46:29 +00:00
|
|
|
doc += '\n' + msg.locale.t("core.message.module.help.support_regex")
|
2023-03-04 08:51:56 +00:00
|
|
|
for regex in module_.regex_list.set:
|
|
|
|
pattern = None
|
|
|
|
if isinstance(regex.pattern, str):
|
|
|
|
pattern = regex.pattern
|
|
|
|
elif isinstance(regex.pattern, re.Pattern):
|
|
|
|
pattern = regex.pattern.pattern
|
|
|
|
if pattern:
|
2023-03-08 11:40:16 +00:00
|
|
|
desc = regex.desc
|
|
|
|
if desc:
|
2023-05-12 18:20:52 +00:00
|
|
|
if locale_str := re.findall(r'\{(.*)}', desc):
|
2023-03-08 11:40:16 +00:00
|
|
|
for l in locale_str:
|
2023-05-12 18:20:52 +00:00
|
|
|
desc = desc.replace(f'{{{l}}}', msg.locale.t(l, fallback_failed_prompt=False))
|
2023-05-19 04:46:29 +00:00
|
|
|
doc += f'\n{pattern} ' + msg.locale.t("core.message.module.help.regex.detail",
|
2023-03-08 11:40:16 +00:00
|
|
|
msg=desc)
|
|
|
|
else:
|
2023-05-19 04:46:29 +00:00
|
|
|
doc += f'\n{pattern} ' + msg.locale.t("core.message.module.help.regex.no_information")
|
2022-08-27 16:17:01 +00:00
|
|
|
appends.append(doc)
|
2023-03-04 08:51:56 +00:00
|
|
|
module_alias = module_.alias
|
2022-08-27 16:17:01 +00:00
|
|
|
malias = []
|
2023-03-04 08:51:56 +00:00
|
|
|
if module_alias:
|
|
|
|
for a in module_alias:
|
|
|
|
malias.append(f'{a} -> {module_alias[a]}')
|
2022-08-27 16:17:01 +00:00
|
|
|
appends.append('\n'.join(malias) if malias else '')
|
2023-03-04 08:51:56 +00:00
|
|
|
if module_.developers:
|
|
|
|
appends.append('、'.join(module_.developers))
|
2022-08-27 16:17:01 +00:00
|
|
|
m.append(appends)
|
|
|
|
if m:
|
2023-05-19 04:46:29 +00:00
|
|
|
tables.append(ImageTable(m, [msg.locale.t("core.message.module.help.table.header.external"),
|
|
|
|
msg.locale.t("core.message.module.help.table.header.help"),
|
|
|
|
msg.locale.t("core.message.module.help.table.header.alias"),
|
|
|
|
msg.locale.t("core.message.module.help.author.type2")]))
|
2022-08-27 16:17:01 +00:00
|
|
|
if tables:
|
|
|
|
render = await image_table_render(tables)
|
|
|
|
if render:
|
|
|
|
legacy_help = False
|
|
|
|
await msg.finish([Image(render)])
|
|
|
|
except Exception:
|
|
|
|
traceback.print_exc()
|
|
|
|
if legacy_help:
|
2023-05-19 04:46:29 +00:00
|
|
|
help_msg = [msg.locale.t("core.message.module.help.legacy.availables")]
|
2022-08-27 16:17:01 +00:00
|
|
|
module_ = []
|
|
|
|
for x in module_list:
|
|
|
|
if x[0] == '_':
|
|
|
|
continue
|
2023-03-04 08:51:56 +00:00
|
|
|
if module_list[x].base or module_list[x].required_superuser:
|
2022-08-27 16:17:01 +00:00
|
|
|
continue
|
|
|
|
module_.append(module_list[x].bind_prefix)
|
|
|
|
help_msg.append(' | '.join(module_))
|
2023-05-12 18:20:52 +00:00
|
|
|
help_msg.append(
|
|
|
|
msg.locale.t(
|
2023-05-19 04:46:29 +00:00
|
|
|
"core.message.module.help.legacy.more_information",
|
2023-05-12 18:20:52 +00:00
|
|
|
prefix=msg.prefixes[0],
|
|
|
|
help_url=Config('help_url')))
|
2022-08-27 16:17:01 +00:00
|
|
|
if msg.Feature.delete:
|
2023-05-19 04:46:29 +00:00
|
|
|
help_msg.append(msg.locale.t("core.message.module.help.revoke.legacy"))
|
2022-08-27 16:17:01 +00:00
|
|
|
send = await msg.sendMessage('\n'.join(help_msg))
|
|
|
|
await msg.sleep(60)
|
|
|
|
await send.delete()
|