🐛 修复入群欢迎问题

This commit is contained in:
CMHopeSunshine 2022-09-12 13:36:15 +08:00
parent 8c711b4302
commit eba4c0ee89
4 changed files with 19 additions and 17 deletions

View File

@ -70,8 +70,8 @@ async def _(event: PrivateMessageEvent, state: T_State, match: dict = RegexDict(
@manage_cmd.got('bool') @manage_cmd.got('bool')
async def _(state: T_State): async def _(state: T_State):
if not state['group'] and state['user']: if not state['group'] and not state['user']:
await manage_cmd.finish('用法:ban|unban 插件名 -g 群号列表 -u 用户列表', at_sender=True) await manage_cmd.finish('用法:pm ban|unban 插件名 -g 群号列表 -u 用户列表', at_sender=True)
if state['session_id'] in cache_help: if state['session_id'] in cache_help:
del cache_help[state['session_id']] del cache_help[state['session_id']]
if not state['plugin'] and state['plugin_no_exist']: if not state['plugin'] and state['plugin_no_exist']:

View File

@ -7,9 +7,10 @@ from nonebot import on_command, on_regex, on_notice, on_request
from nonebot.rule import Rule from nonebot.rule import Rule
from nonebot.permission import SUPERUSER from nonebot.permission import SUPERUSER
from nonebot.params import CommandArg, ArgPlainText, RegexDict from nonebot.params import CommandArg, ArgPlainText, RegexDict
from nonebot.adapters.onebot.v11 import Bot, Message, MessageEvent, PrivateMessageEvent, FriendRequestEvent, GroupRequestEvent, \ from nonebot.adapters.onebot.v11 import Bot, Message, MessageEvent, PrivateMessageEvent, FriendRequestEvent, \
GroupRequestEvent, \
RequestEvent, NoticeEvent, \ RequestEvent, NoticeEvent, \
GroupIncreaseNoticeEvent, FriendAddNoticeEvent GroupIncreaseNoticeEvent, FriendAddNoticeEvent, GroupMessageEvent
from nonebot.typing import T_State from nonebot.typing import T_State
from LittlePaimon import NICKNAME, SUPERUSERS from LittlePaimon import NICKNAME, SUPERUSERS
@ -174,21 +175,24 @@ async def _(event: MessageEvent, msg: Message = CommandArg()):
target = ['全部'] target = ['全部']
else: else:
try: try:
target = list(map(int, target)) target = list(map(int, target.split(' ')))
except Exception: except Exception:
await ban_greet.finish('请发送正确的要关闭入群欢迎的群号或者"全部"') await ban_greet.finish(f'请发送正确的要{"启用" if type else "禁用"}入群欢迎的群号或者"全部"')
if not target: if not target:
if isinstance(event, GroupMessageEvent):
target = [event.group_id] target = [event.group_id]
else:
await ban_greet.finish(f'请发送正确的要{"启用" if type else "禁用"}入群欢迎的群号或者"全部"')
for t in target: for t in target:
if t == '全部': if t == '全部':
config.group_ban = ['全部'] if type else [] config.group_ban = [] if type else ['全部']
elif not type: elif not type:
if t not in config.group_ban: if t not in config.group_ban:
config.group_ban.append(t) config.group_ban.append(t)
elif t in config.group_ban: elif t in config.group_ban:
config.group_ban.remove(t) config.group_ban.remove(t)
config.save() config.save()
await ban_greet.finish(f'{"启用" if type else "禁用"}{" ".join(target)}的群欢迎') await ban_greet.finish(f'{"启用" if type else "禁用"}{" ".join(map(str, target))}的群欢迎')
@scheduler.scheduled_job('cron', hour='*/1') @scheduler.scheduled_job('cron', hour='*/1')

View File

@ -332,12 +332,11 @@ async def bbs_auto_coin():
for group_id, result_list in coin_result_group.items(): for group_id, result_list in coin_result_group.items():
result_num = len(result_list) result_num = len(result_list)
result_fail = len([result for result in result_list if not result['result']]) if result_fail := len([result for result in result_list if not result['result']]):
if result_fail:
msg = f'本群米游币自动获取共{result_num}个任务,已全部完成'
else:
fails = '\n'.join(result['uid'] for result in result_list if not result['result']) fails = '\n'.join(result['uid'] for result in result_list if not result['result'])
msg = f'本群米游币自动获取共{result_num}个任务,其中成功{result_num - result_fail}个,失败{result_fail}失败的UID列表\n{fails}' msg = f'本群米游币自动获取共{result_num}个任务,其中成功{result_num - result_fail}个,失败{result_fail}失败的UID列表\n{fails}'
else:
msg = f'本群米游币自动获取共{result_num}个任务,已全部完成'
try: try:
await get_bot().send_group_msg(group_id=int(group_id), message=msg) await get_bot().send_group_msg(group_id=int(group_id), message=msg)
except Exception as e: except Exception as e:

View File

@ -63,12 +63,11 @@ async def _():
for group_id, result_list in result_list['group'].items(): for group_id, result_list in result_list['group'].items():
result_num = len(result_list) result_num = len(result_list)
result_fail = len([result for result in result_list if not result['result']]) if result_fail := len([result for result in result_list if not result['result']]):
if result_fail:
msg = f'本群云原神自动签到共{result_num}个任务,已全部完成'
else:
fails = '\n'.join(result['uid'] for result in result_list if not result['result']) fails = '\n'.join(result['uid'] for result in result_list if not result['result'])
msg = f'本群云原神自动签到共{result_num}个任务,其中成功{result_num - result_fail}个,失败{result_fail}失败的UID列表\n{fails}' msg = f'本群云原神自动签到共{result_num}个任务,其中成功{result_num - result_fail}个,失败{result_fail}失败的UID列表\n{fails}'
else:
msg = f'本群云原神自动签到共{result_num}个任务,已全部完成'
try: try:
await get_bot().send_group_msg(group_id=int(group_id), message=msg) await get_bot().send_group_msg(group_id=int(group_id), message=msg)
except Exception as e: except Exception as e: