2018-12-27 10:56:24 +00:00
|
|
|
import json
|
|
|
|
import time
|
|
|
|
|
|
|
|
userlog_event_types = {"warns": "Warn",
|
|
|
|
"bans": "Ban",
|
|
|
|
"kicks": "Kick",
|
|
|
|
"mutes": "Mute",
|
|
|
|
"notes": "Note"}
|
|
|
|
|
|
|
|
|
|
|
|
def get_userlog():
|
2018-12-27 11:19:33 +00:00
|
|
|
with open("data/userlog.json", "r") as f:
|
2018-12-27 10:56:24 +00:00
|
|
|
return json.load(f)
|
|
|
|
|
|
|
|
|
|
|
|
def set_userlog(contents):
|
2018-12-27 11:19:33 +00:00
|
|
|
with open("data/userlog.json", "w") as f:
|
2018-12-27 10:56:24 +00:00
|
|
|
f.write(contents)
|
|
|
|
|
|
|
|
|
2020-01-08 10:08:38 +00:00
|
|
|
def fill_userlog(userid, uname):
|
2019-03-02 18:00:55 +00:00
|
|
|
userlogs = get_userlog()
|
2020-01-08 10:08:38 +00:00
|
|
|
uid = str(userid)
|
2019-03-02 18:00:55 +00:00
|
|
|
if uid not in userlogs:
|
|
|
|
userlogs[uid] = {"warns": [],
|
|
|
|
"mutes": [],
|
|
|
|
"kicks": [],
|
|
|
|
"bans": [],
|
|
|
|
"notes": [],
|
|
|
|
"watch": False,
|
|
|
|
"name": "n/a"}
|
|
|
|
if uname:
|
|
|
|
userlogs[uid]["name"] = uname
|
2020-01-08 10:08:38 +00:00
|
|
|
|
|
|
|
return userlogs, uid
|
|
|
|
|
|
|
|
|
|
|
|
def userlog(uid, issuer, reason, event_type, uname: str = ""):
|
|
|
|
userlogs, uid = fill_userlog(uid, uname)
|
|
|
|
|
2019-03-02 18:00:55 +00:00
|
|
|
timestamp = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
|
|
|
|
log_data = {"issuer_id": issuer.id,
|
|
|
|
"issuer_name": f"{issuer}",
|
|
|
|
"reason": reason,
|
|
|
|
"timestamp": timestamp}
|
|
|
|
if event_type not in userlogs[uid]:
|
|
|
|
userlogs[uid][event_type] = []
|
|
|
|
userlogs[uid][event_type].append(log_data)
|
|
|
|
set_userlog(json.dumps(userlogs))
|
|
|
|
return len(userlogs[uid][event_type])
|
|
|
|
|
|
|
|
|
|
|
|
def setwatch(uid, issuer, watch_state, uname: str = ""):
|
2020-01-08 10:08:38 +00:00
|
|
|
userlogs, uid = fill_userlog(uid, uname)
|
2019-03-02 18:00:55 +00:00
|
|
|
|
|
|
|
userlogs[uid]["watch"] = watch_state
|
|
|
|
set_userlog(json.dumps(userlogs))
|
|
|
|
return
|