-
Notifications
You must be signed in to change notification settings - Fork 1
/
priv.py
83 lines (65 loc) · 2.31 KB
/
priv.py
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
"""The privilege of user discribed in an `int` number.
`0` is for Default or NotSet. The other numbers may change in future versions.
"""
BLACK = -999
DEFAULT = 0
NORMAL = 1
PRIVATE = 10
ADMIN = 21
OWNER = 22
WHITE = 51
SUPERUSER = 999
from datetime import datetime
import hoshino
from hoshino.typing import CQEvent
#===================== block list =======================#
_black_group = {} # Dict[group_id, expr_time]
_black_user = {} # Dict[user_id, expr_time]
def set_block_group(group_id, time):
_black_group[group_id] = datetime.now() + time
def remove_block_group(group_id):
if group_id in _black_group:
del _black_group[group_id] #在黑名单中移除群
return False
return bool(group_id in _black_group)
def set_block_user(user_id, time):
if user_id not in hoshino.config.SUPERUSERS:
_black_user[user_id] = datetime.now() + time
def check_block_group(group_id):
if group_id in _black_group and datetime.now() > _black_group[group_id]:
del _black_group[group_id] # 拉黑时间过期
return False
return bool(group_id in _black_group)
def check_block_user(user_id):
if user_id in _black_user and datetime.now() > _black_user[user_id]:
del _black_user[user_id] # 拉黑时间过期
return False
return bool(user_id in _black_user)
#========================================================#
def get_user_priv(ev: CQEvent):
uid = ev.user_id
if uid in hoshino.config.SUPERUSERS:
return SUPERUSER
if check_block_user(uid):
return BLACK
# TODO: White list
if ev['message_type'] == 'group':
if not ev.anonymous:
role = ev.sender.get('role')
if role == 'member':
return NORMAL
elif role == 'admin':
return ADMIN
elif role == 'administrator':
return ADMIN # for cqhttpmirai
elif role == 'owner':
return OWNER
return NORMAL
if ev['message_type'] == 'private':
return PRIVATE
return NORMAL
def check_priv(ev: CQEvent, require: int) -> bool:
if ev['message_type'] == 'group':
return bool(get_user_priv(ev) >= require)
else:
return False # 不允许私聊