-
Notifications
You must be signed in to change notification settings - Fork 0
/
leaderboard.py
51 lines (45 loc) · 2.74 KB
/
leaderboard.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
import json
from discord import Embed
def update(length:int) -> dict:
with open('db.json', 'r') as f:
db:dict = json.loads(f.read())
t10:dict = {"10":{"name": "", "count": 0},"9":{"name": "", "count": 0},"8":{"name": "", "count": 0},"7":{"name": "", "count": 0},"6":{"name": "", "count": 0},"5":{"name": "", "count": 0},"4":{"name": "", "count": 0},"3":{"name": "", "count": 0},"2":{"name": "", "count": 0},"1":{"name": "", "count": 0}, "debug": {"count": 9999999, "name": "DEBUG"}}
for word in db:
if len(word) >= length if length > 0 else 1:
if db[word] > t10["10"]["count"]:
stop = False
for place in range(10,0, -1):
if db[word] <= t10[str(place)]["count"]:
stop = True
if word != t10[str(place)]["name"]:
t10[str(place+1)]["name"] = word
t10[str(place+1)]["count"] = db[word]
break
if not stop:
t10[str(1)]["name"] = word
t10[str(1)]["count"] = db[word]
return t10
def export(length:int) -> Embed:
t10:dict = update(length)
# leaderboard:str = ""
# for i in range(1,11):
# leaderboard += f"{(' ' if i < 10 else '') + str(i)}: {t10[str(i)]['name']} - {t10[str(i)]['count']}\n"
# return leaderboard
embed = Embed(title="Leaderboard", color=0xff0000)
embed.add_field(name='', value=f"1. \t {t10['1'] ['name']} - {t10['1'] ['count']}", inline=False)
embed.add_field(name='', value=f"3. \t {t10['2'] ['name']} - {t10['2'] ['count']}", inline=False)
embed.add_field(name='', value=f"4. \t {t10['3'] ['name']} - {t10['3'] ['count']}", inline=False)
embed.add_field(name='', value=f"5. \t {t10['4'] ['name']} - {t10['4'] ['count']}", inline=False)
embed.add_field(name='', value=f"6. \t {t10['5'] ['name']} - {t10['5'] ['count']}", inline=False)
embed.add_field(name='', value=f"7. \t {t10['6'] ['name']} - {t10['6'] ['count']}", inline=False)
embed.add_field(name='', value=f"8. \t {t10['7'] ['name']} - {t10['7'] ['count']}", inline=False)
embed.add_field(name='', value=f"9. \t {t10['8'] ['name']} - {t10['8'] ['count']}", inline=False)
embed.add_field(name='', value=f"9. \t {t10['9'] ['name']} - {t10['9'] ['count']}", inline=False)
embed.add_field(name='', value=f"10. \t{t10['10']['name']} - {t10['10']['count']}", inline=False)
return embed
async def index(query:str) -> Embed:
with open('db.json', 'r') as f:
db:dict = json.loads(f.read())
embed = Embed(title="Index", color=0xff0000)
embed.add_field(name='', value=query.capitalize()+': '+str(db[query] if db[query] else 0))
return embed