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
|
import time
import json
from pathlib import Path
from nonebot import on_command, CommandSession
import config # type: ignore
master = config.MASTER()
file = Path('.') / 'ATRI' / 'plugins' / 'noobList' / 'noobList.json'
file1 = Path('.') / 'ATRI' / 'plugins' / 'noobList' / 'noobGroup.json'
@on_command('add_noobList', aliases = ['屏蔽', '移除'], only_to_me = False)
async def _(session: CommandSession):
if session.event.user_id == master:
msg = session.event.raw_message.split(' ', 2)
b_type = msg[0]
g_type = msg[1]
u = msg[2]
if g_type == 'qq':
if b_type == '屏蔽':
try:
with open(file, 'r') as f:
bL = json.load(f)
except:
bL = {}
bL[f"{u}"] = f"{u}"
f = open(file, 'w')
f.write(json.dumps(bL))
f.close()
await session.send(f'正义执行!![{u}]已被ATRI屏蔽!')
elif b_type == '移除':
try:
with open(file, 'r') as f:
bL = json.load(f)
except:
bL = {}
bL.pop(f"{u}")
f = open(file, 'w')
f.write(json.dumps(bL))
f.close()
await session.send(f'将[{u}]移出黑名单成功~!')
elif g_type == 'group':
if b_type == '屏蔽':
try:
with open(file1, 'r') as f:
bL = json.load(f)
except:
bL = {}
bL[f"{u}"] = f"{u}"
f = open(file1, 'w')
f.write(json.dumps(bL))
f.close()
await session.send(f'正义执行!!群[{u}]已被ATRI屏蔽!')
elif b_type == '移除':
try:
with open(file1, 'r') as f:
bL = json.load(f)
except:
bL = {}
bL.pop(f"{u}")
f = open(file1, 'w')
f.write(json.dumps(bL))
f.close()
await session.send(f'将群[{u}]移出黑名单成功~!')
@on_command('look_noobList', aliases = ['查看黑名单'], only_to_me = False)
async def _(session: CommandSession):
start = time.perf_counter()
with open(file, 'r') as f:
data = json.load(f)
with open(file1, 'r') as f:
data0 = json.load(f)
msg = f'被ATRI列入黑名单有以下列表:\n'
try:
msg1 = f'=====[用户]=====\n'
msg += msg1
for i in data.keys():
msg0 = f'{i}\n'
msg += msg0
except:
end = time.perf_counter()
msg0 = f"==============\nDone time: {round(end - start, 3)}s"
msg += msg0
await session.send(msg)
return
try:
msg1 = f'======[群]======\n'
msg += msg1
for i in data0.keys():
msg0 = f'{i}\n'
msg += msg0
except:
end = time.perf_counter()
msg0 = f"==============\nDone time: {round(end - start, 3)}s"
msg += msg0
await session.send(msg)
return
end = time.perf_counter()
msg0 = f"==============\nDone time: {round(end - start, 3)}s"
msg += msg0
await session.send(msg)
|