upload gitea
This commit is contained in:
commit
6747dbacb8
13 files changed
+1074
No files matched your search
+159
@@ -0,0 +1,159 @@
|
||||
import csv
|
||||
|
||||
def load_user_data(ID):
|
||||
try:
|
||||
with open("./data/User_Data.csv", mode="r", newline="", encoding="utf-8") as csvfile:
|
||||
reader = csv.DictReader(csvfile)
|
||||
for row in reader:
|
||||
if row["ID"] == str(ID):
|
||||
user_data = {
|
||||
"ID": row["ID"],
|
||||
"total_coin": int(row["total_coin"]),
|
||||
"last_signin": row["last_signin"],
|
||||
"total_signin": int(row["total_signin"]),
|
||||
"exp": int(row["exp"])
|
||||
}
|
||||
return user_data
|
||||
# 如果沒找到該ID
|
||||
print(f"[Load.py] 使用者 ID {ID} 不存在於 User_Data.csv 中。")
|
||||
return None
|
||||
except FileNotFoundError:
|
||||
print("[Load.py] 找不到 User_Data.csv 檔案。")
|
||||
return None
|
||||
|
||||
def load_user_achievement(ID):
|
||||
try:
|
||||
with open("./data/User_Achievement.csv", mode="r", newline="", encoding="utf-8") as csvfile:
|
||||
reader = csv.DictReader(csvfile)
|
||||
for row in reader:
|
||||
if row["ID"] == str(ID):
|
||||
user_achievement = {
|
||||
"ID": row["ID"],
|
||||
"achi_1": int(row["achi_1"]),
|
||||
"achi_2": int(row["achi_2"]),
|
||||
"achi_3": int(row["achi_3"]),
|
||||
"achi_4": int(row["achi_4"]),
|
||||
"achi_5": int(row["achi_5"]),
|
||||
"achi_6": int(row["achi_6"]),
|
||||
"achi_7": int(row["achi_7"])
|
||||
}
|
||||
return user_achievement
|
||||
# 如果沒找到該ID
|
||||
print(f"[Load.py] 使用者 ID {ID} 不存在於 User_Achievement.csv 中。")
|
||||
return None
|
||||
except FileNotFoundError:
|
||||
print("[Load.py] 找不到 User_Achievement.csv 檔案。")
|
||||
return None
|
||||
|
||||
def load_user_backpack(ID):
|
||||
try:
|
||||
with open("./data/User_Backpack.csv", mode="r", newline="", encoding="utf-8") as csvfile:
|
||||
reader = csv.DictReader(csvfile)
|
||||
for row in reader:
|
||||
if row["ID"] == str(ID):
|
||||
user_backpack = {
|
||||
"ID": row["ID"],
|
||||
"case": int(row["case"]),
|
||||
"cpu": int(row["cpu"]),
|
||||
"mother_board": int(row["mother_board"]),
|
||||
"ram": int(row["ram"]),
|
||||
"gpu": int(row["gpu"]),
|
||||
"fan": int(row["fan"]),
|
||||
"psu": int(row["psu"]),
|
||||
"hdd": int(row["hdd"]),
|
||||
"white_shark": int(row["white_shark"]),
|
||||
"red_shark": int(row["red_shark"]),
|
||||
"orange_shark": int(row["orange_shark"]),
|
||||
"yellow_shark": int(row["yellow_shark"]),
|
||||
"green_shark": int(row["green_shark"]),
|
||||
"blue_shark": int(row["blue_shark"]),
|
||||
"purple_shark": int(row["purple_shark"]),
|
||||
"gray_shark": int(row["gray_shark"]),
|
||||
"black_shark": int(row["black_shark"]),
|
||||
"rgb_shark": int(row["rgb_shark"]),
|
||||
"my_left_hand": int(row["my_left_hand"]),
|
||||
"my_right_hand": int(row["my_right_hand"]),
|
||||
"my_hair": int(row["my_hair"]),
|
||||
"my_left_leg": int(row["my_left_leg"]),
|
||||
"my_right_leg": int(row["my_right_leg"]),
|
||||
"my_body": int(row["my_body"]),
|
||||
"my_head": int(row["my_head"]),
|
||||
"bed": int(row["bed"]),
|
||||
"pillow": int(row["pillow"]),
|
||||
"quilt": int(row["quilt"]),
|
||||
"ac": int(row["ac"]),
|
||||
"chair": int(row["chair"]),
|
||||
"desk": int(row["desk"]),
|
||||
"laptop": int(row["laptop"]),
|
||||
"screen": int(row["screen"]),
|
||||
"phone": int(row["phone"]),
|
||||
"plug": int(row["plug"]),
|
||||
"wig": int(row["wig"]),
|
||||
"pants": int(row["pants"]),
|
||||
"top": int(row["top"]),
|
||||
"dress": int(row["dress"]),
|
||||
"sleeve_cover": int(row["sleeve_cover"]),
|
||||
"stocking": int(row["stocking"]),
|
||||
"pantyhose": int(row["pantyhose"]),
|
||||
"bow": int(row["bow"]),
|
||||
"hair_accessories": int(row["hair_accessories"]),
|
||||
"cosmetics": int(row["cosmetics"]),
|
||||
}
|
||||
return user_backpack
|
||||
# 如果沒找到該ID
|
||||
print(f"[Load.py] 使用者 ID {ID} 不存在於 User_Backpack.csv 中。")
|
||||
return None
|
||||
except FileNotFoundError:
|
||||
print("[Load.py] 找不到 User_Backpack.csv 檔案。")
|
||||
return None
|
||||
|
||||
def load_server_setting(ID):
|
||||
try:
|
||||
with open("./data/Server_Setting.csv", mode="r", newline="", encoding="utf-8") as csvfile:
|
||||
reader = csv.DictReader(csvfile)
|
||||
for row in reader:
|
||||
if row["Server_ID"] == str(ID):
|
||||
# 根據字串決定是否轉成 int
|
||||
signin_channel_raw = row["signin_channel"]
|
||||
if signin_channel_raw == "default":
|
||||
signin_channel = "default"
|
||||
else:
|
||||
signin_channel = int(signin_channel_raw)
|
||||
|
||||
server_setting = {
|
||||
"Server_ID": row["Server_ID"],
|
||||
"signin_channel": signin_channel,
|
||||
"signin_emoji": row["signin_emoji"]
|
||||
}
|
||||
return server_setting
|
||||
print(f"[Load.py] 伺服器 ID {ID} 不存在於 Server_Setting.csv 中。")
|
||||
return None
|
||||
except FileNotFoundError:
|
||||
print("[Load.py] 找不到 Server_Setting.csv 檔案。")
|
||||
return None
|
||||
|
||||
|
||||
def get_signin_count(user_id: str) -> int:
|
||||
user_data = load_user_data(user_id)
|
||||
if user_data:
|
||||
return user_data.get("total_signin", 0)
|
||||
return 0
|
||||
|
||||
def get_coin_count(user_id: str) -> int:
|
||||
user_data = load_user_data(user_id)
|
||||
if user_data:
|
||||
return user_data.get("total_coin", 0)
|
||||
return 0
|
||||
|
||||
def get_exp_count(user_id: str) -> int:
|
||||
user_data = load_user_data(user_id)
|
||||
if user_data:
|
||||
return user_data.get("exp", 0)
|
||||
return 0
|
||||
|
||||
def get_signin_time(user_id: str) -> str:
|
||||
user_data = load_user_data(user_id)
|
||||
if user_data:
|
||||
return user_data.get("last_signin", "no signin data")
|
||||
return 0
|
||||
|
||||
Reference in new issue
Block a user