summaryrefslogtreecommitdiff
path: root/ATRI/modules/favoIMP/__init__.py
blob: 3dabdae3347a5fc1d8531d04c716eeb2d283dcf2 (plain)
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
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()