1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
import re
import json
from pathlib import Path
from nonebot.permission import SUPERUSER
from nonebot.adapters.cqhttp import Bot, MessageEvent
from ATRI.service import Service as sv
from ATRI.exceptions import ReadFileError, FormatError
ESSENTIAL_DIR = Path('.') / 'ATRI' / 'data' / 'database' / 'essential'
__doc__ = """
查看好友/群申请列表
权限组:维护者
用法:
查看申请列表
"""
req_list = sv.on_command(
cmd="申请列表",
docs=__doc__,
permission=SUPERUSER
)
@req_list.handle()
async def _req_list(bot: Bot, event: MessageEvent) -> None:
path_f = ESSENTIAL_DIR / 'request_friend.json'
path_g = ESSENTIAL_DIR / 'request_group.json'
data_f, data_g = dict()
try:
data_f = json.loads(path_f.read_bytes())
except ReadFileError:
msg_f = "[读取文件失败]"
try:
data_g = json.loads(path_g.read_bytes())
except ReadFileError:
msg_g = "[读取文件失败]"
msg_f = str()
for i in data_f.keys():
msg_f += f"{i} | {data_f[i]['user_id']} | {data_f[i]['comment']}\n"
msg_g = str()
for i in data_g.keys():
msg_g += f"{i} | {data_g[i]['sub_type']} | {data_g[i]['user_id']} | {data_g[i]['comment']}\n"
msg = (
"好友/群申请列表如下:\n"
"· 好友:\n"
f"{msg_f}"
"· 群:\n"
f"{msg_g}"
)
await req_list.finish(msg)
req_deal = sv.on_regex(
r'[同意|拒绝][好友|群]申请',
permission=SUPERUSER
)
@req_deal.handle()
async def _req_deal(bot: Bot, event: MessageEvent) -> None:
msg = str(event.message).split(' ')
arg = re.findall(r'[同意|拒绝][好友|群]申请', msg[0])
app = arg[0]
_type = arg[1]
if not msg[1]:
await req_deal.finish(f'正确用法!速看\n{app}{_type}申请 (reqid)')
path = ESSENTIAL_DIR / "request_group.json"
data_g = dict()
try:
data_g = json.loads(path.read_bytes())
except FileExistsError:
await req_deal.finish("读取群数据失败,可能并没有请求...")
reqid = msg[1]
if app == "同意":
if _type == "好友":
try:
await bot.set_friend_add_request(flag=reqid,
approve=True)
await req_deal.finish('完成~!已同意申请')
except FormatError:
await req_deal.finish('请检查输入的值是否正确——!')
elif _type == "群":
try:
await bot.set_group_add_request(flag=reqid,
sub_type=data_g[reqid]['sub_type'],
approve=True)
await req_deal.finish('完成~!已同意申请')
except FormatError:
await req_deal.finish('请检查输入的值是否正确——!')
else:
await req_deal.finish('请检查输入的值是否正确——!')
elif app == "拒绝":
if _type == "好友":
try:
await bot.set_friend_add_request(flag=reqid,
approve=False)
await req_deal.finish('完成~!已拒绝申请')
except FormatError:
await req_deal.finish('请检查输入的值是否正确——!')
elif _type == "群":
try:
await bot.set_group_add_request(flag=reqid,
sub_type=data_g[reqid]['sub_type'],
approve=False)
await req_deal.finish('完成~!已拒绝申请')
except FormatError:
await req_deal.finish('请检查输入的值是否正确——!')
else:
await req_deal.finish('请检查输入的值是否正确——!')
else:
await req_deal.finish('请检查输入的值是否正确——!')
|