From 9c91cc1c7f39a7178e753d5f32a707db0ae19790 Mon Sep 17 00:00:00 2001 From: Kyomotoi <1172294279@qq.com> Date: Sun, 13 Sep 2020 16:36:05 +0800 Subject: [Update] --- ATRI/modules/favoIMP/__init__.py | 58 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 ATRI/modules/favoIMP/__init__.py (limited to 'ATRI/modules/favoIMP/__init__.py') diff --git a/ATRI/modules/favoIMP/__init__.py b/ATRI/modules/favoIMP/__init__.py new file mode 100644 index 0000000..3dabdae --- /dev/null +++ b/ATRI/modules/favoIMP/__init__.py @@ -0,0 +1,58 @@ +import json +from random import randint +from pathlib import Path + +def GetFavoIMP(u): + try: + with open(Path('.') / 'ATRI' / 'modules' / 'favoIMP' / 'user.json', 'r') as f: + data = json.load(f) + except: + return 0 + + try: + if data[f"{u}"][0]: + pass + else: + return 0 + except: + return 0 + + return [data[f"{u}"][0], data[f"{u}"][1]] + +def AddFavoIMP(u, f:int, s:bool): + if s: + favoIMP = randint(1,f) + else: + favoIMP = f + try: + with open(Path('.') / 'ATRI' / 'modules' / 'favoIMP' / 'user.json', 'r') as a: + data = json.load(a) + data[f"{u}"][0] = int(data[f"{u}"][0]) + favoIMP + with open(Path('.') / 'ATRI' / 'modules' / 'favoIMP' / 'user.json', 'w') as a: + a.write(json.dumps(data)) + a.close() + except: + data = {} + data[f"{u}"] = [f"{favoIMP}"] + with open(Path('.') / 'ATRI' / 'modules' / 'favoIMP' / 'user.json', 'w') as a: + a.write(json.dumps(data)) + a.close() + +def DelFavoIMP(u, f:int, s:bool): + if s: + favoIMP = randint(1,f) + else: + favoIMP = f + try: + with open(Path('.') / 'ATRI' / 'modules' / 'favoIMP' / 'user.json', 'r') as a: + data = json.load(a) + data[f"{u}"][0] = int(data[f"{u}"][0]) - favoIMP + with open(Path('.') / 'ATRI' / 'modules' / 'favoIMP' / 'user.json', 'w') as a: + a.write(json.dumps(data)) + a.close() + except: + data = {} + data[f"{u}"] = [f"{0 - favoIMP}"] + with open(Path('.') / 'ATRI' / 'modules' / 'favoIMP' / 'user.json', 'w') as a: + a.write(json.dumps(data)) + a.close() \ No newline at end of file -- cgit v1.2.3