2021-02-01 17:41:45 +00:00
|
|
|
import asyncio
|
|
|
|
|
2021-02-01 15:13:11 +00:00
|
|
|
from graia.application import Group, MessageChain, Member, Friend
|
|
|
|
from graia.application.message.elements.internal import Plain
|
|
|
|
|
2021-04-08 15:20:14 +00:00
|
|
|
from core.template import check_permission, revokeMessage
|
2021-02-25 12:36:19 +00:00
|
|
|
from .admin import *
|
2021-07-06 18:00:26 +00:00
|
|
|
from core.decorator import command
|
2021-02-01 15:13:11 +00:00
|
|
|
|
|
|
|
|
2021-07-06 18:00:26 +00:00
|
|
|
@command(name='module')
|
2021-06-05 10:25:21 +00:00
|
|
|
async def config_modules(kwargs: dict):
|
2021-02-01 15:13:11 +00:00
|
|
|
"""
|
2021-06-05 10:25:21 +00:00
|
|
|
~module <enable/disable> <module/all>"""
|
2021-02-01 15:13:11 +00:00
|
|
|
command = kwargs['trigger_msg'].split(' ')
|
2021-06-05 10:25:21 +00:00
|
|
|
bot_modules = kwargs['bot_modules']
|
|
|
|
function_list = bot_modules['modules_function']
|
|
|
|
friend_function_list = bot_modules['friend_modules_function']
|
|
|
|
alias_list = bot_modules['alias']
|
|
|
|
msg = '命令格式错误。' + config_modules.__doc__
|
|
|
|
if not len(command) > 2:
|
|
|
|
await sendMessage(kwargs, msg)
|
2021-02-01 15:13:11 +00:00
|
|
|
return
|
2021-06-05 10:25:21 +00:00
|
|
|
do = command[1]
|
|
|
|
command_third_word = command[2]
|
|
|
|
if command_third_word in alias_list:
|
|
|
|
command_third_word = alias_list[command_third_word]
|
2021-02-01 15:13:11 +00:00
|
|
|
if Group in kwargs:
|
2021-06-05 10:25:21 +00:00
|
|
|
if not check_permission(kwargs):
|
|
|
|
await sendMessage(kwargs, '你没有使用该命令的权限。')
|
|
|
|
return
|
|
|
|
if command_third_word == 'all':
|
|
|
|
msglist = []
|
|
|
|
for function in function_list:
|
|
|
|
msg = database.update_modules(do, kwargs[Group].id, function)
|
|
|
|
msglist.append(msg)
|
|
|
|
msg = '\n'.join(msglist)
|
|
|
|
elif command_third_word in function_list:
|
|
|
|
msg = database.update_modules(do, kwargs[Group].id, command_third_word)
|
2021-02-01 15:13:11 +00:00
|
|
|
else:
|
2021-06-05 10:25:21 +00:00
|
|
|
msg = '此模块不存在。'
|
2021-02-01 15:13:11 +00:00
|
|
|
elif Friend in kwargs:
|
2021-06-05 10:25:21 +00:00
|
|
|
if command_third_word in friend_function_list:
|
|
|
|
msg = database.update_modules(do, kwargs[Friend].id, command_third_word, table='friend_permission')
|
2021-02-01 15:13:11 +00:00
|
|
|
else:
|
2021-06-05 10:25:21 +00:00
|
|
|
msg = '此模块不存在。'
|
|
|
|
await sendMessage(kwargs, msg)
|
2021-02-01 15:13:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def bot_help(kwargs: dict):
|
2021-06-05 10:25:21 +00:00
|
|
|
help_list = kwargs['bot_modules']['help']
|
|
|
|
alias = kwargs['bot_modules']['alias']
|
2021-02-01 17:41:45 +00:00
|
|
|
command = kwargs['trigger_msg'].split(' ')
|
2021-06-05 10:25:21 +00:00
|
|
|
if len(command) > 1:
|
2021-02-07 09:56:01 +00:00
|
|
|
msg = []
|
2021-06-05 10:25:21 +00:00
|
|
|
help_name = command[1]
|
|
|
|
if help_name in alias:
|
|
|
|
help_name = alias[help_name].split(' ')[0]
|
|
|
|
if help_name in help_list:
|
|
|
|
msg.append(help_list[help_name]['help'])
|
2021-02-07 09:56:01 +00:00
|
|
|
for x in help_list:
|
|
|
|
if 'depend' in help_list[x]:
|
2021-06-05 10:25:21 +00:00
|
|
|
if help_list[x]['depend'] == help_name:
|
2021-02-07 09:56:01 +00:00
|
|
|
msg.append(help_list[x]['help'])
|
|
|
|
await sendMessage(kwargs, '\n'.join(msg))
|
2021-06-05 10:25:21 +00:00
|
|
|
else:
|
2021-02-01 17:41:45 +00:00
|
|
|
print(help_list)
|
|
|
|
help_msg = []
|
|
|
|
help_msg.append('基础命令:')
|
2021-02-07 09:56:01 +00:00
|
|
|
essential = []
|
2021-02-01 17:41:45 +00:00
|
|
|
for x in help_list:
|
|
|
|
if 'essential' in help_list[x]:
|
2021-02-07 09:56:01 +00:00
|
|
|
essential.append(x)
|
|
|
|
help_msg.append(' | '.join(essential))
|
2021-02-01 17:41:45 +00:00
|
|
|
help_msg.append('模块扩展命令:')
|
2021-02-07 09:56:01 +00:00
|
|
|
module = []
|
2021-02-01 17:41:45 +00:00
|
|
|
for x in help_list:
|
|
|
|
if Group in kwargs:
|
|
|
|
if database.check_enable_modules(kwargs, x):
|
2021-02-10 14:11:26 +00:00
|
|
|
if 'help' in help_list[x]:
|
2021-02-07 09:56:01 +00:00
|
|
|
module.append(x)
|
2021-02-01 17:41:45 +00:00
|
|
|
elif Friend in kwargs:
|
2021-02-01 15:13:11 +00:00
|
|
|
if 'help' in help_list[x]:
|
2021-02-07 09:56:01 +00:00
|
|
|
module.append(x)
|
|
|
|
help_msg.append(' | '.join(module))
|
|
|
|
print(help_msg)
|
2021-06-05 10:25:21 +00:00
|
|
|
help_msg.append('使用~help <对应模块名>查看详细信息。\n使用~modules查看所有的可用模块。\n你也可以通过查阅文档获取帮助:\nhttps://bot.teahou.se/modules/')
|
2021-02-07 09:56:01 +00:00
|
|
|
if Group in kwargs:
|
|
|
|
help_msg.append('[本消息将在一分钟后撤回]')
|
2021-02-01 17:41:45 +00:00
|
|
|
send = await sendMessage(kwargs, '\n'.join(help_msg))
|
2021-02-07 09:56:01 +00:00
|
|
|
if Group in kwargs:
|
|
|
|
await asyncio.sleep(60)
|
|
|
|
await revokeMessage(send)
|
2021-02-01 15:13:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def modules_help(kwargs: dict):
|
2021-06-05 10:25:21 +00:00
|
|
|
help_list = kwargs['bot_modules']['help']
|
2021-02-01 15:13:11 +00:00
|
|
|
help_msg = []
|
|
|
|
help_msg.append('当前可用的模块有:')
|
2021-02-07 09:56:01 +00:00
|
|
|
module = []
|
2021-02-01 15:13:11 +00:00
|
|
|
for x in help_list:
|
2021-02-10 14:11:26 +00:00
|
|
|
if 'help' in help_list[x]:
|
2021-02-07 09:56:01 +00:00
|
|
|
module.append(x)
|
2021-02-10 14:11:26 +00:00
|
|
|
help_msg.append(' | '.join(module))
|
2021-02-10 15:49:43 +00:00
|
|
|
help_msg.append('使用~help <模块名>查看详细信息。\n你也可以通过查阅文档获取帮助:\nhttps://bot.teahou.se/modules/')
|
2021-02-07 09:56:01 +00:00
|
|
|
if Group in kwargs:
|
|
|
|
help_msg.append('[本消息将在一分钟后撤回]')
|
2021-02-01 17:41:45 +00:00
|
|
|
send = await sendMessage(kwargs, '\n'.join(help_msg))
|
2021-02-07 09:56:01 +00:00
|
|
|
if Group in kwargs:
|
|
|
|
await asyncio.sleep(60)
|
|
|
|
await revokeMessage(send)
|
2021-02-01 15:13:11 +00:00
|
|
|
|
|
|
|
|
2021-03-05 16:08:10 +00:00
|
|
|
async def bot_version(kwargs: dict):
|
2021-03-05 16:19:06 +00:00
|
|
|
version = os.path.abspath('.version')
|
|
|
|
openfile = open(version, 'r')
|
|
|
|
msg = '当前运行的代码版本号为:' + openfile.read()
|
2021-03-05 16:08:10 +00:00
|
|
|
await sendMessage(kwargs, msg)
|
2021-03-05 16:19:06 +00:00
|
|
|
openfile.close()
|
2021-03-05 16:08:10 +00:00
|
|
|
|
|
|
|
|
2021-06-04 15:54:08 +00:00
|
|
|
async def config_gu(kwargs):
|
|
|
|
if Group in kwargs:
|
|
|
|
if check_permission(kwargs):
|
|
|
|
command = kwargs['trigger_msg'].split(' ')
|
|
|
|
if len(command) < 3:
|
|
|
|
await sendMessage(kwargs, '命令格式错误。')
|
|
|
|
return
|
|
|
|
print(command)
|
|
|
|
if command[1] == 'add':
|
|
|
|
await sendMessage(kwargs, database.add_group_adminuser(command[2], kwargs[Group].id))
|
|
|
|
if command[1] == 'del':
|
|
|
|
await sendMessage(kwargs, database.del_group_adminuser(command[2], kwargs[Group].id))
|
|
|
|
|
|
|
|
|
2021-06-05 10:25:21 +00:00
|
|
|
essential = {'module': config_modules, 'add_base_su': add_base_su, 'help': bot_help,
|
2021-06-04 15:54:08 +00:00
|
|
|
'modules': modules_help, 'version': bot_version, 'admin_user': config_gu}
|
2021-04-08 15:20:14 +00:00
|
|
|
admin = {'add_su': add_su, 'del_su': del_su, 'set': set_modules, 'restart': restart_bot, 'update': update_bot,
|
|
|
|
'echo': echo_msg, 'update&restart': update_and_restart_bot}
|
2021-06-05 10:25:21 +00:00
|
|
|
help = {'module': {'help': '~module <enable/disable> <模块名> - 开启/关闭一个模块', 'essential': True},
|
|
|
|
'modules': {'help': '~modules - 查询所有可用模块。'},
|
2021-06-04 15:54:08 +00:00
|
|
|
'admin_user': {'help': '~admin_user <add/del> <QQ> - 配置群内成员为机器人管理员(无需设置其为群内管理员)'}}
|
2021-06-05 10:25:21 +00:00
|
|
|
|
|
|
|
alias = {'enable': 'module enable', 'disable': 'module disable'}
|