-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathblock_utils.py
More file actions
28 lines (23 loc) · 787 Bytes
/
Copy pathblock_utils.py
File metadata and controls
28 lines (23 loc) · 787 Bytes
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
from imports import *
from config import BLOCKED_USERS_FILE
def load_blocked_users():
if not os.path.exists(BLOCKED_USERS_FILE):
return set()
with open(BLOCKED_USERS_FILE, "r") as f:
try:
data = json.load(f)
return set(data)
except json.JSONDecodeError:
return set()
def block_user(user_id):
users = load_blocked_users()
users.add(user_id)
with open(BLOCKED_USERS_FILE, "w") as f:
json.dump(list(users), f, indent=2)
def unblock_user(user_id):
users = load_blocked_users()
users.discard(user_id)
with open(BLOCKED_USERS_FILE, "w") as f:
json.dump(list(users), f, indent=2)
def is_user_blocked(user_id):
return user_id in load_blocked_users()