diff options
author | Lint Action <noreply@github.com> | 2021-08-08 13:32:06 +0000 |
---|---|---|
committer | Lint Action <noreply@github.com> | 2021-08-08 13:32:06 +0000 |
commit | 6d9d237fe7b6d6216bad1b23ef784778d52022ce (patch) | |
tree | 5fceaf52ff970002aeeba52ee695a9c5c78af1c9 /ATRI/plugins/essential.py | |
parent | 5c4c4695e143b9b79a8eb77da62b41c41007c802 (diff) | |
download | ATRI-6d9d237fe7b6d6216bad1b23ef784778d52022ce.tar.gz ATRI-6d9d237fe7b6d6216bad1b23ef784778d52022ce.tar.bz2 ATRI-6d9d237fe7b6d6216bad1b23ef784778d52022ce.zip |
:rotating_light: 自动进行代码格式化
Diffstat (limited to 'ATRI/plugins/essential.py')
-rw-r--r-- | ATRI/plugins/essential.py | 61 |
1 files changed, 24 insertions, 37 deletions
diff --git a/ATRI/plugins/essential.py b/ATRI/plugins/essential.py index 11a6d91..ddf96fc 100644 --- a/ATRI/plugins/essential.py +++ b/ATRI/plugins/essential.py @@ -61,12 +61,12 @@ async def _check_block( if not path.is_file(): with open(path, "w", encoding="utf-8") as w: w.write(json.dumps(dict())) - + try: data = json.loads(path.read_bytes()) except BaseException: data = dict() - + user_id = event.get_user_id() if user_id in data: raise IgnoredException(f"Block user: {user_id}") @@ -77,12 +77,12 @@ async def _check_block( if not path.is_file(): with open(path, "w", encoding="utf-8") as w: w.write(json.dumps(dict())) - + try: data = json.loads(path.read_bytes()) except BaseException: data = dict() - + group_id = str(event.group_id) if group_id in data: raise IgnoredException(f"Block group: {user_id}") @@ -108,13 +108,13 @@ __doc__ = """ class Essential(Service): - def __init__(self): Service.__init__(self, "基础部件", __doc__) friend_add_event = Essential().on_request("好友添加") + @friend_add_event.handle() async def _friend_add(bot: Bot, event: FriendRequestEvent): """ @@ -134,22 +134,19 @@ async def _friend_add(bot: Bot, event: FriendRequestEvent): with open(path, "w", encoding="utf-8") as w: w.write(json.dumps({})) data = dict() - + apply_code = event.flag apply_comment = event.comment user_id = event.get_user_id() now_time = datetime.now() - + data = json.loads(path.read_bytes()) data[apply_code] = FriendRequestInfo( - user_id=user_id, - comment=apply_comment, - time=now_time, - is_approve=False + user_id=user_id, comment=apply_comment, time=now_time, is_approve=False ) with open(path, "w", encoding="utf-8") as w: w.write(json.dumps(data.dict(), indent=4)) - + repo = ( "咱收到一条好友请求...\n" f"请求人:{user_id}\n" @@ -163,6 +160,7 @@ async def _friend_add(bot: Bot, event: FriendRequestEvent): group_invite_event = Essential().on_request("邀请入群") + @group_invite_event.handle() async def _group_invite(bot: Bot, event: GroupRequestEvent): """ @@ -182,22 +180,19 @@ async def _group_invite(bot: Bot, event: GroupRequestEvent): with open(path, "w", encoding="utf-8") as w: w.write(json.dumps({})) data = dict() - + apply_code = event.flag apply_comment = event.comment user_id = event.get_user_id() now_time = datetime.now() - + data = json.loads(path.read_bytes()) data[apply_code] = GroupRequestInfo( - user_id=user_id, - comment=apply_comment, - time=now_time, - is_approve=False + user_id=user_id, comment=apply_comment, time=now_time, is_approve=False ) with open(path, "w", encoding="utf-8") as w: w.write(json.dumps(data.dict(), indent=4)) - + repo = ( "咱收到一条群聊邀请请求...\n" f"请求人:{user_id}\n" @@ -211,15 +206,14 @@ async def _group_invite(bot: Bot, event: GroupRequestEvent): group_member_event = Essential().on_notice("群成员变动") + @group_member_event.handle() async def _group_member_join(bot: Bot, event: GroupIncreaseNoticeEvent): await asyncio.sleep(randint(1, 6)) - msg = ( - "好欸!事新人!\n" - f"在下 {choice(list(BotSelfConfig.nickname))} 哒!w!" - ) + msg = "好欸!事新人!\n" f"在下 {choice(list(BotSelfConfig.nickname))} 哒!w!" await group_member_event.finish(msg) + @group_member_event.handle() async def _group_member_left(bot: Bot, event: GroupDecreaseNoticeEvent): await asyncio.sleep(randint(1, 6)) @@ -228,6 +222,7 @@ async def _group_member_left(bot: Bot, event: GroupDecreaseNoticeEvent): group_admin_event = Essential().on_notice("群管理变动") + @group_admin_event.handle() async def _group_admin_event(bot: Bot, event: GroupAdminNoticeEvent): if not event.is_tome(): @@ -241,6 +236,7 @@ async def _group_admin_event(bot: Bot, event: GroupAdminNoticeEvent): group_ban_event = Essential().on_notice("群禁言变动") + @group_ban_event.handle() async def _group_ban_event(bot: Bot, event: GroupBanNoticeEvent): if not event.is_tome(): @@ -262,11 +258,12 @@ async def _group_ban_event(bot: Bot, event: GroupBanNoticeEvent): recall_event = Essential().on_notice("撤回事件") + @recall_event.handle() async def _recall_group_event(bot: Bot, event: GroupRecallNoticeEvent): if event.is_tome(): return - + try: repo = await bot.get_msg(message_id=event.message_id) except BaseException: @@ -279,12 +276,7 @@ async def _recall_group_event(bot: Bot, event: GroupRecallNoticeEvent): if not check: repo = repo.replace("CQ", "QC") - msg = ( - "主人,咱拿到了一条撤回信息!\n" - f"{user}@[群:{group}]\n" - "撤回了\n" - f"{repo}" - ) + msg = "主人,咱拿到了一条撤回信息!\n" f"{user}@[群:{group}]\n" "撤回了\n" f"{repo}" for superuser in BotSelfConfig.superusers: await bot.send_private_msg(user_id=int(superuser), message=msg) @@ -293,7 +285,7 @@ async def _recall_group_event(bot: Bot, event: GroupRecallNoticeEvent): async def _recall_private_event(bot: Bot, event: FriendRecallNoticeEvent): if event.is_tome(): return - + try: repo = await bot.get_msg(message_id=event.message_id) except BaseException: @@ -305,11 +297,6 @@ async def _recall_private_event(bot: Bot, event: FriendRecallNoticeEvent): if not check: repo = repo.replace("CQ", "QC") - msg = ( - "主人,咱拿到了一条撤回信息!\n" - f"{user}@[私聊]" - "撤回了\n" - f"{repo}" - ) + msg = "主人,咱拿到了一条撤回信息!\n" f"{user}@[私聊]" "撤回了\n" f"{repo}" for superuser in BotSelfConfig.superusers: await bot.send_private_msg(user_id=int(superuser), message=msg) |