Archived
1
0
Fork 0
This repository has been archived on 2024-04-26. You can view files and clone it, but cannot push or open issues or pull requests.
akari-bot/modules/core/__init__.py

146 lines
5.8 KiB
Python
Raw Normal View History

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
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-07 16:00:24 +00:00
@command(bind_prefix='module')
async def config_modules(kwargs: dict):
2021-02-01 15:13:11 +00:00
"""
~module <enable/disable> <module/all>"""
2021-02-01 15:13:11 +00:00
command = kwargs['trigger_msg'].split(' ')
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
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:
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:
msg = '此模块不存在。'
2021-02-01 15:13:11 +00:00
elif Friend in kwargs:
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:
msg = '此模块不存在。'
await sendMessage(kwargs, msg)
2021-02-01 15:13:11 +00:00
async def bot_help(kwargs: dict):
help_list = kwargs['bot_modules']['help']
alias = kwargs['bot_modules']['alias']
2021-02-01 17:41:45 +00:00
command = kwargs['trigger_msg'].split(' ')
if len(command) > 1:
2021-02-07 09:56:01 +00:00
msg = []
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]:
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))
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)
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):
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))
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}
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}
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> - 配置群内成员为机器人管理员(无需设置其为群内管理员)'}}
alias = {'enable': 'module enable', 'disable': 'module disable'}