-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.py
298 lines (273 loc) · 10.6 KB
/
bot.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
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
import discord
from discord.ext import commands
import requests
import time
import dotenv
import os
startup_time = round(time.time())
intents = discord.Intents.default()
intents.message_content = True
description = '''a w take bot'''
dotenv.load_dotenv()
bot = commands.Bot(command_prefix='?', description=description, intents=intents, help_command=None)
bot.remove_command('help')
hypixel_api_key = os.getenv("APIKEY")
headers = {"API-Key":hypixel_api_key}
ranks = {
"MVP_PLUS": "\u001b[0;34m[MVP\u001b[0;*m+\u001b[0;34m]",
"MVP": "\u001b[0;34m[MVP]",
"VIP_PLUS": "\u001b[0;32m[VIP\u001b[0;33m+\u001b[0;32m]",
"VIP": "\u001b[0;32m[VIP]",
"NONE": "[NOOB]"
}
pluscolours = {
"RED": "31",
"LIGHT_PURPLE": "35",
"DARK_PURPLE": "35",
"DARK_BLUE": "34",
"GOLD": "33",
"GREEN": "32",
"YELLOW":"33",
"WHITE": "37",
"BLUE": "34",
"DARK_GREEN": "32",
"DARK_RED": "31",
"DARK_AQUA": "36",
"DARK_GREY": "30",
"BLACK": "30"
}
def get_uuid(username):
try:
response = requests.get(f"https://api.mojang.com/users/profiles/minecraft/{username}").json()
print(response)
return response["id"]
except:
return None
@bot.event
async def on_ready():
print(f'We have logged in as {bot.user}')
@bot.event
async def on_message(message):
if message.author == bot.user:
return
if message.content.startswith('$hello'):
await message.channel.send('engineer gaming')
await bot.process_commands(message)
@bot.command()
async def uptime(ctx):
await ctx.reply(f"LobsterBot has been online since <t:{startup_time}:R>")
@bot.command()
async def user(ctx, username:str):
"""Gets info on a user"""
if ctx.author.id == 750400391136673933:
await ctx.reply("🤓")
uuid = get_uuid(username)
if uuid == None:
await ctx.send("Error: user not found")
return
userinfo = requests.get(f"https://api.hypixel.net/v2/player?uuid={uuid}", headers=headers).json()
useractivity = requests.get(f"https://api.hypixel.net/v2/status?uuid={uuid}", headers=headers).json()
gamenames = requests.get("https://api.hypixel.net/v2/resources/games", headers=headers).json()
print(useractivity)
if userinfo["success"] != True:
await ctx.send("Error: user may have not played hypixel")
if useractivity["session"]["online"] == True:
userGame = useractivity["session"]["gameType"]
try:
prettifiedGame = gamenames["games"][userGame]["name"]
except:
prettifiedGame = None
try:
userMode = useractivity["session"]["mode"]
if userMode == "LOBBY":
prettifiedMode = "Lobby"
elif userGame == "MAIN":
prettifiedGame = "Main Lobby"
else:
prettifiedMode = gamenames["games"][userGame]["modeNames"][userMode]
try:
if userGame == "MAIN":
activitymessage = "Online in the Main Lobby."
else:
usermap = useractivity["session"]["map"]
activitymessage = f"Online, playing {prettifiedGame}, in mode {prettifiedMode}, on map {usermap}."
except:
activitymessage = f"Online, playing {prettifiedGame}, in mode {prettifiedMode}."
except:
activitymessage = f"Online, playing {prettifiedGame}."
else:
try:
lastlogin = round(userinfo["player"]["lastLogin"] / 1000)
activitymessage = f"Offline, and last logged in <t:{lastlogin}:R>"
except:
if username.lower() == "technoblade":
activitymessage = f"Technoblade never dies."
else:
activitymessage = f"Offline."
try:
specialrank = userinfo["player"]["rank"]
except:
specialrank = None
if username.lower() == "technoblade":
rank = "\u001b[0;35m[PIG\u001b[0;36m+++\u001b[0;35m]"
elif username.lower() == "hypixel":
rank = "\u001b[0;31m[OWNER]"
elif username.lower() == "tommyinnit":
rank = "\u001b[0;35m[INNIT]"
elif specialrank == "ADMIN":
rank = "\u001b[0;31m[ADMIN]"
elif specialrank == "YOUTUBER":
rank = "\u001b[0;31m[\u001b[0;37mYOUTUBE\u001b[0;31m]"
else:
try:
rankcolour = userinfo["player"]["rankPlusColor"]
except:
rankcolour = "RED"
try:
mvpplusplus = userinfo["player"]["monthlyPackageRank"] == "SUPERSTAR"
except:
mvpplusplus = False
if mvpplusplus:
try:
mvppluspluscolour = userinfo["player"]["monthlyRankColor"]
if mvppluspluscolour == "AQUA":
mvppluspluscolour = "36"
else:
mvppluspluscolour = "33"
except:
mvppluspluscolour = "33"
rank = f"\u001b[0;{mvppluspluscolour}m[MVP\u001b[0;{pluscolours[rankcolour]}m++\u001b[0;{mvppluspluscolour}m]"
else:
try:
rank = ranks[userinfo["player"]["newPackageRank"]]
except:
rank = ""
rank = rank.replace("*",pluscolours[rankcolour])
await ctx.send(f"""```ansi
{rank} {userinfo["player"]["displayname"]}\u001b[0m
```{activitymessage}
[Body](https://api.mineatar.io/body/full/{uuid}?scale=32)
""")
@bot.command()
async def watchdog(ctx):
"""gets watchdog and the admins stats"""
r = requests.get("https://api.hypixel.net/v2/punishmentstats", headers=headers).json()
if r["success"]:
stafftoday = r["staff_rollingDaily"]
watchdogtoday = r["watchdog_rollingDaily"]
if stafftoday > watchdogtoday:
message = f"""W admins: Today, the Hypixel admins have punished {stafftoday} bozos, while Watchdog has only punished {watchdogtoday}."""
elif watchdogtoday > stafftoday:
message = f"""L admins: Today, the Hypixel admins have only punished {stafftoday} bozos, while Watchdog has banhammered {watchdogtoday}."""
elif watchdogtoday == stafftoday:
message = f"""Perfectly balanced?? Both the admins _and_ Watchdog have banned {stafftoday} noobs!?"""
await ctx.send(message)
else:
await ctx.send("error: unknown error, ask @EngineerRunner")
@bot.command()
async def stats(ctx, username:str):
"""gets user stats"""
uuid = get_uuid(username)
if uuid == None:
await ctx.send("Error: user not found")
return
userinfo = requests.get(f"https://api.hypixel.net/v2/player?uuid={uuid}", headers=headers).json()
if userinfo["success"] == False:
await ctx.send("Error: user has not played Hypixel")
return
stats = userinfo["player"]["stats"]["Bedwars"]
kills = stats["kills_bedwars"]
deaths = stats["deaths_bedwars"]
finalkills = stats["final_kills_bedwars"]
finaldeaths = stats["final_deaths_bedwars"]
kdr = round(kills / deaths, 2)
fkdr = round(finalkills / finaldeaths, 2)
try:
specialrank = userinfo["player"]["rank"]
except:
specialrank = None
if username.lower() == "technoblade":
rank = "\u001b[0;35m[PIG\u001b[0;36m+++\u001b[0;35m]"
elif username.lower() == "hypixel":
rank = "\u001b[0;31m[OWNER]"
elif username.lower() == "tommyinnit":
rank = "\u001b[0;35m[INNIT]"
elif specialrank == "ADMIN":
rank = "\u001b[0;31m[ADMIN]"
elif specialrank == "YOUTUBER":
rank = "\u001b[0;31m[\u001b[0;37mYOUTUBE\u001b[0;31m]"
else:
try:
rankcolour = userinfo["player"]["rankPlusColor"]
except:
rankcolour = "RED"
try:
mvpplusplus = userinfo["player"]["monthlyPackageRank"] == "SUPERSTAR"
except:
mvpplusplus = False
if mvpplusplus:
try:
mvppluspluscolour = userinfo["player"]["monthlyRankColor"]
if mvppluspluscolour == "AQUA":
mvppluspluscolour = "36"
else:
mvppluspluscolour = "33"
except:
mvppluspluscolour = "33"
rank = f"\u001b[0;{mvppluspluscolour}m[MVP\u001b[0;{pluscolours[rankcolour]}m++\u001b[0;{mvppluspluscolour}m]"
else:
try:
rank = ranks[userinfo["player"]["newPackageRank"]]
except:
rank = ""
rank = rank.replace("*",pluscolours[rankcolour])
await ctx.send(f"""```ansi
{rank}{username}\u001b[0m
```
KDR: {kdr} ({kills} kills, {deaths} deaths)
FKDR: {fkdr} ({finalkills} final kills, {finaldeaths} final deaths).
[Body](https://api.mineatar.io/body/full/{uuid}?scale=32)""")
@bot.command()
async def help(ctx):
await ctx.send("""
# LobsterBot <:lobter:1275711085399248917> v1.0.0
## Commands:
### ?help
Shows this menu.
### ?user [hypixel-username]
Gets some basic information about a user.
### ?stats [hypixel-username]
Gets a user's BedWars stats.
### ?watchdog
Compares Watchdog and the Hypixel Staff: who can ban the most noobs?
### ?dailygames [hypixel-username]
Tells you how many BedWars games a user plays per day.
join the discord for announcements, polls and more at <https://discord.gg/CpuJV82NXd>
Check out [LobsterBot](<https://github.com/EngineerRunner/LobsterBot>) on Github!
-# made by @EngineerRunner
""")
@bot.command()
async def dailygames(ctx, username):
uuid = get_uuid(username)
if uuid == None:
await ctx.send("Error: user not found")
return
userinfo = requests.get(f"https://api.hypixel.net/v2/player?uuid={uuid}", headers=headers).json()
if userinfo["success"] == False:
await ctx.send("Error: user has not played Hypixel")
return
firstLogin = userinfo["player"]["firstLogin"] / 1000
currenttime = time.time()
secondsplayed = currenttime - firstLogin
daysplayed = round(secondsplayed / 86400)
gamesplayed = userinfo["player"]["stats"]["Bedwars"]["games_played_bedwars"]
gamesperday = round(gamesplayed / daysplayed, 2)
if gamesperday > 1 and gamesperday < 2:
await ctx.send(f"{username} plays an average of {gamesperday} BedWars matches a day. They need to go touch some grass IMHO.")
elif gamesperday < 1 and gamesperday:
await ctx.send(f"{username} has played an average of only {gamesperday} BedWars matches per day. No sweatiness here!")
elif gamesperday == 1:
await ctx.send(f"{username} has played exactly {gamesperday} BedWars matches per day. They're perfectly balanced!")
elif gamesperday > 2:
await ctx.send(f"{username} plays an average of _{gamesperday} BedWars matches_ a day!? They need grass ASAP")
bot.run(os.getenv("BOTTOKEN"))