-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathguild.py
91 lines (76 loc) · 2.33 KB
/
guild.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import requests, replit, player, math
hypixel_key = replit.db["key-hypixel"]
def getGuildDictByPlayer(profile):
uuid = profile["id"]
r = requests.get("https://api.hypixel.net/guild?key={key}&player={uuid}".format(key=hypixel_key,uuid=uuid))
guildDict = r.json()["guild"]
return guildDict
def getGuildDictByName(name):
r = requests.get("https://api.hypixel.net/guild?key={key}&name={name}".format(key=hypixel_key,name=name))
guildDict = r.json()["guild"]
return guildDict
class Guild():
def __init__(self, player=None, name=None, guildDict=None):
if not player == None:
guildDict = getGuildDictByPlayer(player)
elif not name == None:
guildDict = getGuildDictByName(name)
else:
raise Exception("No arguments provided.")
self.guildDict = guildDict
def name(self):
name = self.guildDict["name"]
return name
def owner(self):
uuid = self.guildDict["members"][0]["uuid"]
owner = player.getProfileUuid(uuid)
return owner
def tag(self):
if "tag" in self.guildDict:
return self.guildDict["tag"]
return "None"
def description(self):
if "description" in self.guildDict:
return self.guildDict["description"]
return "None"
def createdDateFormatted(self):
if "created" in self.guildDict:
timeFormatted = player.formattedTime(int(self.guildDict["created"])/1000)
return timeFormatted
return "Unknown"
def memberCount(self):
if "members" in self.guildDict:
return len(self.guildDict["members"])
return 0
def exp(self):
if "exp" in self.guildDict:
return self.guildDict["exp"]
return 0
def level(self):
#Why does hypixel have to hard code these values?
#Based on https://hypixel.net/threads/hypixel-guild-xp-to-level-php.1774806/post-13656451
#Translated into Python from PHP
exp = self.exp()
if exp < 100000:
return 0
elif exp < 250000:
return 1
elif exp < 500000:
return 2
elif exp < 1000000:
return 3
elif exp < 1750000:
return 4
elif exp < 2750000:
return 5
elif exp < 4000000:
return 6
elif exp < 5500000:
return 7
elif exp < 7500000:
return 8
else:
if exp < 15000000:
return math.floor((exp - 7500000) / 2500000) + 9
else:
return math.floor((exp - 15000000) / 3000000) + 12