2018-12-27 10:56:24 +00:00
|
|
|
import json
|
|
|
|
|
|
|
|
|
2018-12-27 11:56:13 +00:00
|
|
|
def get_restrictions():
|
2018-12-27 10:56:24 +00:00
|
|
|
with open("data/restrictions.json", "r") as f:
|
2018-12-27 11:56:13 +00:00
|
|
|
return json.load(f)
|
|
|
|
|
|
|
|
|
|
|
|
def set_restrictions(contents):
|
2018-12-27 10:56:24 +00:00
|
|
|
with open("data/restrictions.json", "w") as f:
|
2018-12-27 11:56:13 +00:00
|
|
|
f.write(contents)
|
2018-12-27 10:56:24 +00:00
|
|
|
|
|
|
|
|
2018-12-27 11:56:13 +00:00
|
|
|
def get_user_restrictions(uid):
|
|
|
|
uid = str(uid)
|
2018-12-27 10:56:24 +00:00
|
|
|
with open("data/restrictions.json", "r") as f:
|
|
|
|
rsts = json.load(f)
|
2018-12-27 11:56:13 +00:00
|
|
|
if uid in rsts:
|
|
|
|
return rsts[uid]
|
|
|
|
return []
|
|
|
|
|
|
|
|
|
|
|
|
def add_restriction(uid, rst):
|
|
|
|
# mostly from kurisu source, credits go to ihaveamac
|
|
|
|
uid = str(uid)
|
|
|
|
rsts = get_restrictions()
|
|
|
|
if uid not in rsts:
|
|
|
|
rsts[uid] = []
|
|
|
|
if rst not in rsts[uid]:
|
|
|
|
rsts[uid].append(rst)
|
|
|
|
set_restrictions(json.dumps(rsts))
|
|
|
|
|
|
|
|
|
|
|
|
def remove_restriction(uid, rst):
|
|
|
|
# mostly from kurisu source, credits go to ihaveamac
|
|
|
|
uid = str(uid)
|
|
|
|
rsts = get_restrictions()
|
|
|
|
if uid not in rsts:
|
|
|
|
rsts[uid] = []
|
|
|
|
if rst in rsts[uid]:
|
|
|
|
rsts[uid].remove(rst)
|
|
|
|
set_restrictions(json.dumps(rsts))
|