diff options
Diffstat (limited to 'ATRI/plugins/manage')
-rw-r--r-- | ATRI/plugins/manage/__init__.py | 126 | ||||
-rw-r--r-- | ATRI/plugins/manage/data_source.py | 25 |
2 files changed, 85 insertions, 66 deletions
diff --git a/ATRI/plugins/manage/__init__.py b/ATRI/plugins/manage/__init__.py index 0be7b83..a841dfb 100644 --- a/ATRI/plugins/manage/__init__.py +++ b/ATRI/plugins/manage/__init__.py @@ -7,7 +7,6 @@ from nonebot.adapters.cqhttp.permission import GROUP_OWNER, GROUP_ADMIN from .data_source import Manage - block_user = Manage().on_command("封禁用户", "对目标用户进行封禁", permission=SUPERUSER) @@ -104,7 +103,9 @@ async def _deal_unblock_group(bot: Bot, event: MessageEvent, state: T_State): await unblock_group.finish(f"好欸!群 {group_id} 重获新生!") -global_block_service = Manage().on_command("全局禁用", "全局禁用某服务", permission=SUPERUSER) +global_block_service = Manage().on_command("全局禁用", + "全局禁用某服务", + permission=SUPERUSER) @global_block_service.handle() @@ -115,7 +116,8 @@ async def _ready_block_service(bot: Bot, event: MessageEvent, state: T_State): @global_block_service.got("global_block_service", "阿...是哪个服务呢") -async def _deal_global_block_service(bot: Bot, event: MessageEvent, state: T_State): +async def _deal_global_block_service(bot: Bot, event: MessageEvent, + state: T_State): block_service = state["global_block_service"] quit_list = ["算了", "罢了"] if block_service in quit_list: @@ -128,18 +130,22 @@ async def _deal_global_block_service(bot: Bot, event: MessageEvent, state: T_Sta await global_block_service.finish(f"服务 {block_service} 已被禁用") -global_unblock_service = Manage().on_command("全局启用", "全局启用某服务", permission=SUPERUSER) +global_unblock_service = Manage().on_command("全局启用", + "全局启用某服务", + permission=SUPERUSER) @global_unblock_service.handle() -async def _ready_unblock_service(bot: Bot, event: MessageEvent, state: T_State): +async def _ready_unblock_service(bot: Bot, event: MessageEvent, + state: T_State): msg = str(event.message).strip() if msg: state["global_unblock_service"] = msg @global_unblock_service.got("global_unblock_service", "阿...是哪个服务呢") -async def _deal_global_unblock_service(bot: Bot, event: MessageEvent, state: T_State): +async def _deal_global_unblock_service(bot: Bot, event: MessageEvent, + state: T_State): unblock_service = state["global_unblock_service"] quit_list = ["算了", "罢了"] if unblock_service in quit_list: @@ -152,9 +158,9 @@ async def _deal_global_unblock_service(bot: Bot, event: MessageEvent, state: T_S await global_unblock_service.finish(f"服务 {unblock_service} 已启用") -user_block_service = Manage().on_regex( - r"对用户(.*?)禁用(.*)", "针对某一用户禁用服务", permission=SUPERUSER -) +user_block_service = Manage().on_regex(r"对用户(.*?)禁用(.*)", + "针对某一用户禁用服务", + permission=SUPERUSER) @user_block_service.handle() @@ -171,9 +177,9 @@ async def _user_block_service(bot: Bot, event: MessageEvent): await user_block_service.finish(f"完成~已禁止用户 {aim_user} 使用 {aim_service}") -user_unblock_service = Manage().on_regex( - r"对用户(.*?)启用(.*)", "针对某一用户启用服务", permission=SUPERUSER -) +user_unblock_service = Manage().on_regex(r"对用户(.*?)启用(.*)", + "针对某一用户启用服务", + permission=SUPERUSER) @user_unblock_service.handle() @@ -190,22 +196,23 @@ async def _user_unblock_service(bot: Bot, event: MessageEvent): await user_unblock_service.finish(f"完成~已允许用户 {aim_user} 使用 {aim_service}") -group_block_service = Manage().on_command( - "禁用", "针对所在群禁用某服务", permission=SUPERUSER | GROUP_OWNER | GROUP_ADMIN -) +group_block_service = Manage().on_command("禁用", + "针对所在群禁用某服务", + permission=SUPERUSER | GROUP_OWNER + | GROUP_ADMIN) @group_block_service.handle() -async def _ready_group_block_service( - bot: Bot, event: GroupMessageEvent, state: T_State -): +async def _ready_group_block_service(bot: Bot, event: GroupMessageEvent, + state: T_State): msg = str(event.message).strip() if msg: state["group_block_service"] = msg @group_block_service.got("group_block_service", "阿...是哪个服务呢") -async def _deal_group_block_service(bot: Bot, event: GroupMessageEvent, state: T_State): +async def _deal_group_block_service(bot: Bot, event: GroupMessageEvent, + state: T_State): aim_service = state["group_block_service"] group_id = str(event.group_id) quit_list = ["算了", "罢了"] @@ -218,24 +225,23 @@ async def _deal_group_block_service(bot: Bot, event: GroupMessageEvent, state: T await group_block_service.finish(f"完成!~已禁止本群使用服务:{aim_service}") -group_unblock_service = Manage().on_command( - "启用", "针对所在群启用某服务", permission=SUPERUSER | GROUP_OWNER | GROUP_ADMIN -) +group_unblock_service = Manage().on_command("启用", + "针对所在群启用某服务", + permission=SUPERUSER | GROUP_OWNER + | GROUP_ADMIN) @group_unblock_service.handle() -async def _ready_group_unblock_service( - bot: Bot, event: GroupMessageEvent, state: T_State -): +async def _ready_group_unblock_service(bot: Bot, event: GroupMessageEvent, + state: T_State): msg = str(event.message).strip() if msg: state["group_unblock_service"] = msg @group_unblock_service.got("group_unblock_service", "阿...是哪个服务呢") -async def _deal_group_unblock_service( - bot: Bot, event: GroupMessageEvent, state: T_State -): +async def _deal_group_unblock_service(bot: Bot, event: GroupMessageEvent, + state: T_State): aim_service = state["group_unblock_service"] group_id = str(event.group_id) quit_list = ["算了", "罢了"] @@ -248,7 +254,9 @@ async def _deal_group_unblock_service( await group_unblock_service.finish(f"完成!~已允许本群使用服务:{aim_service}") -get_friend_add_list = Manage().on_command("获取好友申请", "获取好友申请列表", permission=SUPERUSER) +get_friend_add_list = Manage().on_command("获取好友申请", + "获取好友申请列表", + permission=SUPERUSER) @get_friend_add_list.handle() @@ -267,18 +275,22 @@ async def _get_friend_add_list(bot: Bot, event: MessageEvent): await get_friend_add_list.finish(msg1) -approve_friend_add = Manage().on_command("同意好友", "同意好友申请", permission=SUPERUSER) +approve_friend_add = Manage().on_command("同意好友", + "同意好友申请", + permission=SUPERUSER) @approve_friend_add.handle() -async def _ready_approve_friend_add(bot: Bot, event: MessageEvent, state: T_State): +async def _ready_approve_friend_add(bot: Bot, event: MessageEvent, + state: T_State): msg = str(event.message).strip() if msg: - state["approve_friend_add"] + state["approve_friend_add"] = msg @approve_friend_add.got("approve_friend_add", "申请码GKD!") -async def _deal_approve_friend_add(bot: Bot, event: MessageEvent, state: T_State): +async def _deal_approve_friend_add(bot: Bot, event: MessageEvent, + state: T_State): apply_code = state["approve_friend_add"] quit_list = ["算了", "罢了"] if apply_code in quit_list: @@ -298,14 +310,16 @@ refuse_friend_add = Manage().on_command("拒绝好友", "拒绝好友申请", pe @refuse_friend_add.handle() -async def _ready_refuse_friend_add(bot: Bot, event: MessageEvent, state: T_State): +async def _ready_refuse_friend_add(bot: Bot, event: MessageEvent, + state: T_State): msg = str(event.message).strip() if msg: - state["refuse_friend_add"] + state["refuse_friend_add"] = msg @refuse_friend_add.got("refuse_friend_add", "申请码GKD!") -async def _deal_refuse_friend_add(bot: Bot, event: MessageEvent, state: T_State): +async def _deal_refuse_friend_add(bot: Bot, event: MessageEvent, + state: T_State): apply_code = state["refuse_friend_add"] quit_list = ["算了", "罢了"] if apply_code in quit_list: @@ -321,7 +335,9 @@ async def _deal_refuse_friend_add(bot: Bot, event: MessageEvent, state: T_State) await refuse_friend_add.finish("已拒绝!") -get_group_invite_list = Manage().on_command("获取邀请列表", "获取群邀请列表", permission=SUPERUSER) +get_group_invite_list = Manage().on_command("获取邀请列表", + "获取群邀请列表", + permission=SUPERUSER) @get_group_invite_list.handle() @@ -340,27 +356,31 @@ async def _get_group_invite_list(bot: Bot, event: MessageEvent): await get_friend_add_list.finish(msg1) -approve_group_invite = Manage().on_command("同意邀请", "同意群聊邀请", permission=SUPERUSER) +approve_group_invite = Manage().on_command("同意邀请", + "同意群聊邀请", + permission=SUPERUSER) @approve_group_invite.handle() -async def _ready_approve_group_invite(bot: Bot, event: MessageEvent, state: T_State): +async def _ready_approve_group_invite(bot: Bot, event: MessageEvent, + state: T_State): msg = str(event.message).strip() if msg: - state["approve_group_invite"] + state["approve_group_invite"] = msg @approve_group_invite.got("approve_group_invite", "申请码GKD!") -async def _deal_approve_group_invite(bot: Bot, event: MessageEvent, state: T_State): +async def _deal_approve_group_invite(bot: Bot, event: MessageEvent, + state: T_State): apply_code = state["approve_group_invite"] quit_list = ["算了", "罢了"] if apply_code in quit_list: await approve_group_invite.finish("好吧...") try: - await bot.set_group_add_request( - flag=apply_code, sub_type="invite", approve=True - ) + await bot.set_group_add_request(flag=apply_code, + sub_type="invite", + approve=True) except BaseException: await approve_group_invite.finish("同意失败...尝试下手动?") data = Manage().load_invite_apply_list() @@ -369,27 +389,31 @@ async def _deal_approve_group_invite(bot: Bot, event: MessageEvent, state: T_Sta await approve_group_invite.finish("好欸!申请已通过!") -refuse_group_invite = Manage().on_command("拒绝邀请", "拒绝群聊邀请", permission=SUPERUSER) +refuse_group_invite = Manage().on_command("拒绝邀请", + "拒绝群聊邀请", + permission=SUPERUSER) @refuse_group_invite.handle() -async def _ready_refuse_group_invite(bot: Bot, event: MessageEvent, state: T_State): +async def _ready_refuse_group_invite(bot: Bot, event: MessageEvent, + state: T_State): msg = str(event.message).strip() if msg: - state["refuse_group_invite"] + state["refuse_group_invite"] = msg @refuse_group_invite.got("refuse_group_invite", "申请码GKD!") -async def _deal_refuse_group_invite(bot: Bot, event: MessageEvent, state: T_State): +async def _deal_refuse_group_invite(bot: Bot, event: MessageEvent, + state: T_State): apply_code = state["refuse_group_invite"] quit_list = ["算了", "罢了"] if apply_code in quit_list: await refuse_group_invite.finish("好吧...") try: - await bot.set_group_add_request( - flag=apply_code, sub_type="invite", approve=False - ) + await bot.set_group_add_request(flag=apply_code, + sub_type="invite", + approve=False) except BaseException: await refuse_group_invite.finish("拒绝失败...尝试下手动?") data = Manage().load_invite_apply_list() diff --git a/ATRI/plugins/manage/data_source.py b/ATRI/plugins/manage/data_source.py index 1897d03..0ecc9ae 100644 --- a/ATRI/plugins/manage/data_source.py +++ b/ATRI/plugins/manage/data_source.py @@ -4,27 +4,20 @@ from pathlib import Path from datetime import datetime from ATRI.service import Service, ServiceTools -from ATRI.utils import UbuntuPaste from ATRI.exceptions import ReadFileError, load_error - MANAGE_DIR = Path(".") / "data" / "database" / "manege" ESSENTIAL_DIR = Path(".") / "data" / "database" / "essential" os.makedirs(MANAGE_DIR, exist_ok=True) os.makedirs(ESSENTIAL_DIR, exist_ok=True) - -TRACK_BACK_FORMAT = """ -Track ID:{track_id} +TRACK_BACK_FORMAT = """Track ID:{track_id} Prompt: {prompt} Time: {time} {content} """.strip() - -__doc__ = """ -控制bot的各项服务 -""" +__doc__ = """控制bot的各项服务""" class Manage(Service): @@ -160,7 +153,8 @@ class Manage(Service): return True @staticmethod - def control_user_service(service: str, user_id: str, is_enabled: bool) -> bool: + def control_user_service(service: str, user_id: str, + is_enabled: bool) -> bool: """ Only SUPERUSER. """ @@ -182,7 +176,8 @@ class Manage(Service): return True @staticmethod - def control_group_service(service: str, group_id: str, is_enabled: bool) -> bool: + def control_group_service(service: str, group_id: str, + is_enabled: bool) -> bool: """ SUPERUSER and GROUPADMIN or GROUPOWNER. Only current group. @@ -267,8 +262,8 @@ class Manage(Service): time = data.get("time", "ignore") content = data.get("content", "ignore") - msg0 = TRACK_BACK_FORMAT.format( - track_id=track_id, prompt=prompt, time=time, content=content - ) - repo = f"详细请移步此处~\n{await UbuntuPaste(content=msg0).paste()}" + repo = TRACK_BACK_FORMAT.format(track_id=track_id, + prompt=prompt, + time=time, + content=content) return repo |