添加重启完成提醒,插件管理器支持插件中文名,修复云原神消息推送

This commit is contained in:
CMHopeSunshine 2022-09-04 11:33:09 +08:00
parent 11db74eb7a
commit 4945dd8c22
6 changed files with 60 additions and 33 deletions

View File

@ -1,13 +1,14 @@
import os
import subprocess
import sys
from pathlib import Path
from nonebot import on_command
from nonebot import on_command, get_bot
from nonebot.permission import SUPERUSER
from nonebot.plugin import PluginMetadata
from nonebot.rule import to_me
from nonebot.adapters.onebot.v11 import MessageEvent
from LittlePaimon import NICKNAME
from LittlePaimon import NICKNAME, DRIVER, SUPERUSERS, __version__
update_cmd = on_command('更新', permission=SUPERUSER, rule=to_me(), priority=1)
reboot_cmd = on_command('重启', permission=SUPERUSER, rule=to_me(), priority=1)
@ -18,7 +19,7 @@ __plugin_meta__ = PluginMetadata(
usage='...',
extra={
'priority': 16,
'show': False
'show': False
}
)
@ -33,6 +34,14 @@ async def _(event: MessageEvent):
@reboot_cmd.handle()
async def _(event: MessageEvent):
await reboot_cmd.send(f'{NICKNAME}开始执行重启,请等待{NICKNAME}的归来', at_sender=True)
(Path() / 'rebooting.json').open('w').close()
if sys.argv[0].endswith('nb'):
sys.argv[0] = 'bot.py'
os.execv(sys.executable, ['python'] + sys.argv)
@DRIVER.on_bot_connect
async def _():
if (Path() / 'rebooting.json').exists():
await get_bot().send_private_msg(user_id=SUPERUSERS[0], message=f'{NICKNAME}已重启完成,当前版本为{__version__}')
(Path() / 'rebooting.json').unlink()

View File

@ -20,7 +20,7 @@ from .draw_help import draw_help
plugin_manager = PluginManager()
manage_cmd = on_regex(r'^pm (?P<func>ban|unban) (?P<plugin>([\w ]*)|all) ?(-g (?P<group>[\d ]*) ?)?(-u (?P<user>[\d ]*) ?)?(?P<reserve>-r)?', priority=1)
manage_cmd = on_regex(r'^pm (?P<func>ban|unban) (?P<plugin>([\w ]*)|all|全部) ?(-g (?P<group>[\d ]*) ?)?(-u (?P<user>[\d ]*) ?)?(?P<reserve>-r)?', priority=1)
help_cmd = on_command('help', aliases={'帮助', '菜单', 'pm help'}, priority=1)
set_config_cmd = on_command('pm set', priority=1, permission=SUPERUSER)
@ -33,7 +33,14 @@ async def _(event: GroupMessageEvent, state: T_State, match: dict = RegexDict(),
await manage_cmd.finish('你没有权限使用该命令', at_sender=True)
state['session_id'] = session_id
state['bool'] = match['func'] == 'unban'
state['plugin'] = match['plugin'].strip().split(' ')
state['plugin'] = []
state['plugin_no_exist'] = []
for plugin in match['plugin'].strip().split(' '):
if plugin not in plugin_manager.data.keys() and plugin not in ['all', '全部']:
if module_name := list(filter(lambda x: plugin_manager.data[x].name == plugin, plugin_manager.data.keys())):
state['plugin'].append(module_name[0])
else:
state['plugin_no_exist'].append(plugin)
if not match['group'] or event.user_id not in SUPERUSERS:
state['group'] = [event.group_id]
else:
@ -47,7 +54,14 @@ async def _(event: PrivateMessageEvent, state: T_State, match: dict = RegexDict(
await manage_cmd.finish('你没有权限使用该命令', at_sender=True)
state['session_id'] = session_id
state['bool'] = match['func'] == 'unban'
state['plugin'] = match['plugin'].strip().split(' ')
state['plugin'] = []
state['plugin_no_exist'] = []
for plugin in match['plugin'].strip().split(' '):
if plugin not in plugin_manager.data.keys() and plugin not in ['all', '全部']:
if module_name := list(filter(lambda x: plugin_manager.data[x].name == plugin, plugin_manager.data.keys())):
state['plugin'].append(module_name[0])
else:
state['plugin_no_exist'].append(plugin)
state['group'] = [int(group) for group in match['group'].strip().split(' ')] if match['group'] else []
state['user'] = [int(user) for user in match['user'].strip().split(' ')] if match['user'] else []
@ -58,6 +72,9 @@ async def _(state: T_State):
await manage_cmd.finish('使用ban|unban -g 群号 -u 用户', at_sender=True)
if state['session_id'] in cache_help:
del cache_help[state['session_id']]
if not state['plugin'] and state['plugin_no_exist']:
await manage_cmd.finish(f'没有叫{" ".join(state["plugin_no_exist"])}的插件')
extra_msg = f'但没有叫{" ".join(state["plugin_no_exist"])}的插件' if state['plugin_no_exist'] else ''
if state['group'] and not state['user']:
for group_id in state['group']:
if 'all' in state['plugin']:
@ -65,7 +82,7 @@ async def _(state: T_State):
else:
await asyncio.gather(*[PluginPermission.filter(name=plugin, session_id=group_id, session_type='group').update(status=state['bool']) for plugin in state['plugin']])
logger.info('插件管理器', f'{"<g>启用</g>" if state["bool"] else "<r>禁用</r>"}群<m>{" ".join(map(str, state["group"]))}</m>的插件<m>{" ".join(state["plugin"])}</m>使用权限')
await manage_cmd.finish(f'{"启用" if state["bool"] else "禁用"}{" ".join(map(str, state["group"]))}的插件{" ".join(state["plugin"])}使用权限')
await manage_cmd.finish(f'{"启用" if state["bool"] else "禁用"}{" ".join(map(str, state["group"]))}的插件{" ".join(state["plugin"])}使用权限{extra_msg}')
elif state['user'] and not state['group']:
for user_id in state['user']:
if 'all' in state['plugin']:
@ -74,7 +91,7 @@ async def _(state: T_State):
await asyncio.gather(*[PluginPermission.filter(name=plugin, session_id=user_id, session_type='user').update(status=state['bool']) for plugin in state['plugin']])
logger.info('插件管理器',
f'{"<g>启用</g>" if state["bool"] else "<r>禁用</r>"}用户<m>{" ".join(map(str, state["user"]))}</m>的插件<m>{" ".join(state["plugin"])}</m>使用权限')
await manage_cmd.finish(f'{"启用" if state["bool"] else "禁用"}用户{" ".join(map(str, state["user"]))}的插件{" ".join(state["plugin"])}使用权限')
await manage_cmd.finish(f'{"启用" if state["bool"] else "禁用"}用户{" ".join(map(str, state["user"]))}的插件{" ".join(state["plugin"])}使用权限{extra_msg}')
else:
for group_id in state['group']:
if 'all' in state['plugin']:
@ -87,7 +104,7 @@ async def _(state: T_State):
await plugin.save()
logger.info('插件管理器',
f'{"<g>启用</g>" if state["bool"] else "<r>禁用</r>"}群<m>{" ".join(map(str, state["group"]))}</m>中用户<m>{" ".join(map(str, state["user"]))}</m>的插件<m>{" ".join(state["plugin"])}</m>使用权限')
await manage_cmd.finish(f'{"启用" if state["bool"] else "禁用"}{" ".join(map(str, state["group"]))}中用户{" ".join(map(str, state["user"]))}的插件{" ".join(state["plugin"])}使用权限')
await manage_cmd.finish(f'{"启用" if state["bool"] else "禁用"}{" ".join(map(str, state["group"]))}中用户{" ".join(map(str, state["user"]))}的插件{" ".join(state["plugin"])}使用权限{extra_msg}')
@help_cmd.handle()

View File

@ -47,7 +47,7 @@ async def _(event: MessageEvent, msg: Message = CommandArg()):
if not msg:
await yys_bind.finish('请给出要绑定的token', at_sender=True)
if match := re.search(r'oi=\d+', msg):
group_id = str(event.group_id) if isinstance(event, GroupMessageEvent) else str(event.user_id)
group_id = event.group_id if isinstance(event, GroupMessageEvent) else event.user_id
uid = str(match.group()).split('=')[1]
await CloudGenshinSub.update_or_create(user_id=str(event.user_id), uid=uid, defaults={'group_id': group_id, 'uuid': uuid_, 'token': msg})
await yys_bind.finish(f'米游社账号{uid}云原神token绑定成功将会每日为你自动领免费时长', at_sender=True)

View File

@ -46,14 +46,14 @@ async def _():
else:
sign = await get_Notification(sub.uuid, sub.token)
msg = '云原神签到成功' if sign['data']['list'] else '云原神今日已签到'
result_list['private' if sub.user_id == sub.group_id else 'group'][sub.group_id].append(
result_list['private' if sub.user_id == str(sub.group_id) else 'group'][str(sub.group_id)].append(
{
'uid': sub.uid,
'msg': f'UID{sub.uid}{msg}',
'result': True
})
else:
result_list['private' if sub.user_id == sub.group_id else 'group'][sub.group_id].append(
result_list['private' if sub.user_id == str(sub.group_id) else 'group'][str(sub.group_id)].append(
{
'uid': sub.uid,
'msg': f'UID{sub.uid}云原神token已失效请重新绑定',

View File

@ -43,24 +43,24 @@ delete_log = on_command('删除模拟抽卡记录', priority=13, block=True, sta
'pm_usage': '删除模拟抽卡记录',
'pm_priority': 3
})
show_dg = on_command('查看定轨', priority=13, block=True, state={
'pm_name': '查看定轨',
'pm_description': '查看当前定轨的武器',
'pm_usage': '查看定轨',
'pm_priority': 4
})
delete_dg = on_command('删除定轨', priority=13, block=True, state={
'pm_name': '删除定轨',
'pm_description': '删除当前定轨武器',
'pm_usage': '删除定轨',
'pm_priority': 5
})
choose_dg = on_command('选择定轨', priority=13, block=True, state={
'pm_name': '选择定轨',
'pm_description': '选择定轨武器',
'pm_usage': '选择定轨<武器名>',
'pm_priority': 6
})
# show_dg = on_command('查看定轨', priority=13, block=True, state={
# 'pm_name': '查看定轨',
# 'pm_description': '查看当前定轨的武器',
# 'pm_usage': '查看定轨',
# 'pm_priority': 4
# })
# delete_dg = on_command('删除定轨', priority=13, block=True, state={
# 'pm_name': '删除定轨',
# 'pm_description': '删除当前定轨武器',
# 'pm_usage': '删除定轨',
# 'pm_priority': 5
# })
# choose_dg = on_command('选择定轨', priority=13, block=True, state={
# 'pm_name': '选择定轨',
# 'pm_description': '选择定轨武器',
# 'pm_usage': '选择定轨<武器名>',
# 'pm_priority': 6
# })
@sim_gacha.handle()

View File

@ -8,6 +8,7 @@ from nonebot.params import RegexDict, ArgPlainText
from nonebot.plugin import PluginMetadata
from nonebot.typing import T_State
from LittlePaimon import NICKNAME
from LittlePaimon.utils.alias import get_match_alias
from LittlePaimon.utils.message import MessageBuild
from LittlePaimon.database.models import PlayerAlias
@ -181,12 +182,12 @@ def create_wiki_matcher(pattern: str, help_fun: str, help_name: str):
if choice not in match_alias:
state['times'] = state['times'] + 1 if 'times' in state else 1
if state['times'] == 1:
await maps.reject(f'请旅行者从上面的{state["type"]}中选一个问派蒙\n回答\"q\"可以取消查询', at_sender=True)
await maps.reject(f'请旅行者从上面的{state["type"]}中选一个问{NICKNAME}\n回答\"取消\"可以取消查询', at_sender=True)
elif state['times'] == 2:
await maps.reject(f'别调戏派蒙啦,快选一个吧,不想问了请回答\"q\"', at_sender=True)
await maps.reject(f'别调戏{NICKNAME}啦,快选一个吧,不想问了请回答\"取消\"', at_sender=True)
elif state['times'] >= 3:
await maps.finish(f'看来旅行者您有点神志不清哦(,下次再问派蒙{MessageSegment.face(146)}', at_sender=True)
await maps.finish(f'看来旅行者您有点神志不清哦(,下次再问{NICKNAME}{MessageSegment.face(146)}', at_sender=True)
try:
await maps.finish(MessageSegment.image(state['img_url'].format(choice)))
except ActionFailed: