This repository was archived by the owner on May 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathminecraftfunctionality.py
More file actions
170 lines (156 loc) · 7.77 KB
/
minecraftfunctionality.py
File metadata and controls
170 lines (156 loc) · 7.77 KB
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
import os
import discord
from discord.ext import commands
import hypixel
import asyncio
from urllib.request import urlopen
import json
from bot import API_KEY, DISCORD
"""
-----------------------------------------
README: CLASS INFO
Hypixeldict{} - stores list of games, divided into subgames, divided into stats
ign = ign - supplied by the class and the command enterer
uuid = uuidurl['id'] - gets id from ign from mojang api
jsondump = json.loads(urlopen(jsonurl).read().decode("utf-8")) - loads jsondtata from hypixelapi (the stats)
game_id = game_id - this will be gotten from the class, skywars is current 0
current = current - this is the current page of the embed, which is ALSO used to get the current subname/subgame!, for 0 0 this would be skywars overall
subgames = list of subgames, gotten from all the values in the game's section of hypixeldict, used for subname
subname = current subname (name of the subgame) gotten via list of subgames at current
""" # readme
hypixeldict = {
'SkyWars':
{'overall': # this isnt displayed, used to check category
['wins', 'losses', 'W/L', 'kills', 'deaths', 'K/D'],
'solo': # also known as solos, ones
['wins_solo', 'losses_solo', 'W/L',
'kills_solo', 'deaths_solo', 'K/D'],
'team': # also known as doubles, duos, teams
['wins_team', 'losses_team', 'W/L',
'kills_team', 'deaths_team', 'K/D'],
'mega': # WIP
['wins', 'losses', 'kills', 'deaths'],
'ranked': # aka rankedsw, ranked_normal
['wins_ranked', 'losses_ranked', 'kills_ranked', 'deaths_ranked']
}, # end of sw
'Bedwars':
{'overall':
['wins_bedwars', 'losses_bedwars', 'W/L',
'final_kills_bedwars', 'final_deaths_bedwars', 'K/D'],
}, # end of bw
'Duels':
{
'overall':
['wins', 'losses', 'W/L', 'kills', 'deaths', 'K/D']
} # end of duels
} # dictionary of gamemodes is hypixeldict{}
visualdict = {
'SkyWars':
{'color': discord.Color.blue(),
'imageurl': 'https://imgur.com/BJS8r5H',
},
'Bedwars':
{'color': discord.Color.red(),
'imageurl': 'https://imgur.com/ZbDcW34',
},
'Duels':
{'color': discord.Color.gold(),
'imageurl': 'https://imgur.com/FS5MMMt',
}
} # colors and images dict, seperated for my own use
async def hypixelstats(igns, gameid, current_pages, ctxx):
ign = igns
game_id = gameid # set this value in the game's class, for example 2 would be duelsnotused
# sets the page number, configure in game's class, for example in duels, 0 would be overall
current_page = current_pages
ctx = ctxx
"""
#TODO:
rework json fetching to account for errors - done
organize list based off of order in hypixelAPI so gameorder is obvious
figure out how tf default dict values work or make a way to send either an error or set all stats as zero - done
add win/losses and kds to list of stats, and then if it doesnt exist and contains a /, do something
get rid of underscores when printing the names
""" # todo_section
try:
uuidurl = json.loads(urlopen(
f"https://api.mojang.com/users/profiles/minecraft/{ign}").read().decode("utf-8"))
uuid = uuidurl["id"]
pass
except Exception:
await ctx.send('error in fetching mojang api data')
pass
else:
try:
jsonurl = f"https://api.hypixel.net/player?key={API_KEY}&uuid={uuid}"
jsondump = json.loads(urlopen(jsonurl).read().decode("utf-8"))
pass
except Exception:
await ctx.send('error in fetching hypixel api data')
pass
else:
# gets game (example: skywars)
gamename = (list(hypixeldict.keys())[game_id])
subgames = (hypixeldict[f'{gamename}'].keys()) # list of subgames
subname = (list(subgames)[current_page])# gets current subgame name (example skywars: overall)
embedcolor = (visualdict[f'{gamename}']['color'])
embedimg = (visualdict[f'{gamename}']['imageurl'])
embed = discord.Embed(title=f"IGN: {jsondump['player']['displayname']}",
color=embedcolor)
embed.set_author(name="XStats Bot", url="https://github.com/XCRunnerS",
icon_url=f"{embedimg}.png") # this is the same method as the mojang api but just the url
embed.set_thumbnail(url=f"{embedimg}.png")
embed.add_field(name=f'{gamename}',
value=f'{subname}', inline=False)
gameitemindex = 0 # MAKE SURE THIS IS RESET WHEN A NEW LOOP HAPPENS
# properly loops through items in subname
for items in (hypixeldict[f'{gamename}'][f'{subname}']):
try:
try:
statname = (
hypixeldict[f'{gamename}'][f'{subname}'][gameitemindex])
pass
except:
# this means something is wrong with dictionary logic... hope for not this...
print.send('big fuckin problem oh shit')
pass
try:
# stores previous value
currentstat = (hypixeldict[f'{gamename}'][f'{subname}'][gameitemindex])
gamestatname = ((f'{currentstat}').replace('_', ' ')).replace(f'{(gamename).lower()}', ' ')
embed.add_field(
name=f'{gamestatname}', value=f"`{format((jsondump['player']['stats'][f'{gamename}'][f'{currentstat}']), ',')}`", inline=True)
pass
except:
if statname.__contains__('/'):
try:
stattwiceremoved = (
hypixeldict[f'{gamename}'][f'{subname}'][gameitemindex - 2])
statonceremoved = (
hypixeldict[f'{gamename}'][f'{subname}'][gameitemindex - 1])
WLVar = (jsondump['player']['stats'][f'{gamename}'][f'{stattwiceremoved}']) /\
(jsondump['player']['stats']
[f'{gamename}'][f'{statonceremoved}'])
embed.add_field(
name=f'{gamestatname}', value=f"`{format(WLVar,',.2f')}`", inline=True)
pass
except Exception:
await ctx.send(f'divison error for {gamestatname}')
pass
else:
embed.add_field(
name=f'{gamestatname}', value=f"`0`", inline=True)
pass
except Exception:
embed.add_field(name=f'{gamestatname}',
value=f"`0`", inline=True)
pass
gameitemindex += 1 # iterate loop value
embed.set_image(
url=f"https://crafatar.com/renders/body/{uuid}.png") # full body render instead of just head
embed.set_footer(text=f"page {current_page+1} ")
msg = await ctx.send(embed=embed) # sends embed
# return the message I thinK????
finally:
print('function executed')
return msg