ryuko-ng/helpers/userlogs.py
Ave Ozkal 6a8819a2a8
Massive cleanup of code, many new features
- added logging and listing of kick/ban/mute events
- add usernotes (.note to add a note to a user, .notes to fetch them)
- split off mod.py into many files, cleanup on many features
- renamed .listwarns to .userlog
- renamed .mywarns to .myuserlog
2018-12-27 13:56:24 +03:00

46 lines
1.5 KiB
Python

import json
import time
userlog_event_types = {"warns": "Warn",
"bans": "Ban",
"kicks": "Kick",
"mutes": "Mute",
"notes": "Note"}
def get_userlog():
with open("data/warnsv2.json", "r") as f:
return json.load(f)
def set_userlog(contents):
with open("data/warnsv2.json", "w") as f:
f.write(contents)
def userlog(uid, issuer, reason, event_type, uname: str = ""):
with open("data/warnsv2.json", "r") as f:
userlogs = json.load(f)
uid = str(uid)
if uid not in userlogs:
userlogs[uid] = {"warns": [],
"mutes": [],
"kicks": [],
"bans": [],
"notes": [],
"watch": False,
"name": "n/a"}
if uname:
userlogs[uid]["name"] = uname
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)
with open("data/warnsv2.json", "w") as f:
json.dump(userlogs, f)
return len(userlogs[uid][event_type])