This repository has been archived by the owner on Apr 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser_exp.py
58 lines (46 loc) · 1.64 KB
/
user_exp.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
import json
import os
def get_raw_info(user_id):
folder = os.path.abspath(os.path.dirname(__file__)) + "\\user_data\\"
file = folder + str(user_id) + ".json"
if os.path.exists(file):
with open(file, "r") as f:
user_info = json.load(f)
return user_info
else:
with open(file, "w") as f:
user_info = {"join_date": None,
"exp": [
{"voice": 0,
"text": 0}
]}
json.dump(user_info, f)
return user_info
def write_raw_info(user_id, data):
folder = os.path.abspath(os.path.dirname(__file__)) + "\\user_data\\"
file = folder + str(user_id) + ".json"
with open(file, "w") as f:
json.dump(data, f)
def get_specific_info(user_id, info):
user_info = get_raw_info(user_id)
if info:
return user_info[info]
else:
return user_info
def get_exp(user_id, exp_type: ["voice", "text"]):
user_info = get_raw_info(user_id)
if exp_type in ["voice", "text"]:
return user_info["exp"][0][exp_type]
else:
raise ValueError("exp_type must be either \"voice\" or \"text\"")
def add_exp(user_id, exp_type: ["voice", "text"], amount):
user_info = get_raw_info(user_id)
if exp_type in ["voice", "text"]:
user_info["exp"][0][exp_type] += amount
write_raw_info(user_id, user_info)
else:
raise ValueError("exp_type must be either \"voice\" or \"text\"")
def set_join_date(user_id, date):
user_info = get_raw_info(user_id)
user_info["join_date"] = date
write_raw_info(user_id, user_info)