summaryrefslogtreecommitdiff
path: root/ATRI/plugins/essential.py
diff options
context:
space:
mode:
authorKyomotoi <[email protected]>2021-08-08 21:31:09 +0800
committerKyomotoi <[email protected]>2021-08-08 21:31:09 +0800
commit5c4c4695e143b9b79a8eb77da62b41c41007c802 (patch)
treeaa21e28113e70dd067fa23620f704b046a282c8d /ATRI/plugins/essential.py
parent9ca6c31ee128e0234907e29bfed8442dae390c19 (diff)
downloadATRI-5c4c4695e143b9b79a8eb77da62b41c41007c802.tar.gz
ATRI-5c4c4695e143b9b79a8eb77da62b41c41007c802.tar.bz2
ATRI-5c4c4695e143b9b79a8eb77da62b41c41007c802.zip
🐛 Magic
Diffstat (limited to 'ATRI/plugins/essential.py')
-rw-r--r--ATRI/plugins/essential.py73
1 files changed, 45 insertions, 28 deletions
diff --git a/ATRI/plugins/essential.py b/ATRI/plugins/essential.py
index 9980518..11a6d91 100644
--- a/ATRI/plugins/essential.py
+++ b/ATRI/plugins/essential.py
@@ -60,11 +60,13 @@ async def _check_block(
path = MANEGE_DIR / user_file
if not path.is_file():
with open(path, "w", encoding="utf-8") as w:
- w.write(json.dumps({}))
+ w.write(json.dumps(dict()))
+
+ try:
+ data = json.loads(path.read_bytes())
+ except BaseException:
data = dict()
-
- data = json.loads(path.read_bytes())
-
+
user_id = event.get_user_id()
if user_id in data:
raise IgnoredException(f"Block user: {user_id}")
@@ -74,11 +76,13 @@ async def _check_block(
path = MANEGE_DIR / group_file
if not path.is_file():
with open(path, "w", encoding="utf-8") as w:
- w.write(json.dumps({}))
+ w.write(json.dumps(dict()))
+
+ try:
+ data = json.loads(path.read_bytes())
+ except BaseException:
data = dict()
-
- data = json.loads(path.read_bytes())
-
+
group_id = str(event.group_id)
if group_id in data:
raise IgnoredException(f"Block group: {user_id}")
@@ -104,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):
"""
@@ -130,19 +134,22 @@ 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"
@@ -156,7 +163,6 @@ 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):
"""
@@ -176,19 +182,22 @@ 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"
@@ -202,14 +211,15 @@ 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))
@@ -218,7 +228,6 @@ 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():
@@ -232,7 +241,6 @@ 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():
@@ -254,12 +262,11 @@ 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:
@@ -272,7 +279,12 @@ 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)
@@ -281,7 +293,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:
@@ -293,6 +305,11 @@ 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)