Skip to content

Commit

Permalink
Update !!randommc command to new minecraft.global API
Browse files Browse the repository at this point in the history
  • Loading branch information
Iapetus-11 committed Nov 26, 2023
1 parent 9cc9583 commit 801a4a5
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions bot/cogs/commands/minecraft.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,17 +250,16 @@ async def mcstatus(self, ctx: Ctx, host=None, port: int = None):
async def random_mc_server(self, ctx: Ctx):
"""Checks the status of a random Minecraft server"""

res = await self.aiohttp.get("https://api.minecraft.global/server/random")
data = await res.json()

if not data["success"]:
await asyncio.sleep(1)

res = await self.aiohttp.get("https://api.minecraft.global/server/random")
data = await res.json()

server = cj.ClassyDict((await res.json())["payload"])
server_id = server.server_id
server_id = (
await (
await self.aiohttp.get("https://api.minecraft.global/MinecraftServers/random/")
).json()
)["id"]
server = cj.ClassyDict(
await (
await self.aiohttp.get(f"https://api.minecraft.global/MinecraftServers/{server_id}")
).json()
)

if server.port:
address = server.host + ":" + str(server.port)
Expand Down Expand Up @@ -291,7 +290,7 @@ async def random_mc_server(self, ctx: Ctx):
)

embed.description = ctx.l.minecraft.mcping.learn_more.format(
f"https://minecraft.global/server/{server_id}?utm_source=villager+bot&utm_medium=discord&utm_id=1"
f"https://minecraft.global/servers/{server_id}?utm_source=villager+bot&utm_medium=discord&utm_id=1"
)

embed.set_footer(
Expand Down

0 comments on commit 801a4a5

Please sign in to comment.