Merge pull request #2 from victormylle/update_status

Update status command
This commit is contained in:
Stijn De Clercq
2020-09-29 21:48:11 +02:00
committed by GitHub

View File

@@ -7,19 +7,39 @@ class ServerStatus(commands.Cog):
def __init__(self, client):
self.client = client
@commands.command()
@commands.command(name="Ping", aliases=["Status"])
async def ping(self, ctx):
#25568 -> Earth
#25567 -> Moon
server = MinecraftServer.lookup("81.82.224.207:25568")
try:
latency = server.ping()
embedVar = discord.Embed(title="", description="", color=0x00ff00)
embedVar.add_field(name="Server1", value="🟢 The Minecraft Server replied in {0} ms".format(latency), inline=False)
await ctx.send(embed=embedVar)
except ConnectionRefusedError:
await ctx.send("🔴 The Minecraft Server is offline")
servers = {"Earth": "25568", "Moon": "25567"}
ip = "81.82.224.207:"
# List of colours for the amount of servers that are online
upColours = [discord.Colour.red(), discord.Colour.orange(), discord.Colour.green()]
embed = discord.Embed()
embed.set_author(name="Status")
# Amount of servers that are online
upCounter = 2
# Add field for all the servers (for-loop so nothing has to be changed for future servers)
for server in servers:
minecraftServer = MinecraftServer.lookup(ip + servers[server])
try:
# Online
latency = f":green_circle: Server replied in {minecraftServer.ping()}ms."
except ConnectionRefusedError:
# Offline
upCounter -= 1
latency = ":red_circle: Server is offline."
embed.add_field(name=server, value=latency, inline=False)
# Set the embed colour
embed.colour = upColours[upCounter]
# Bot's latency
embed.add_field(name="WorldCraft Bot", value=f":green_circle: {round(self.client.latency * 1000)}ms")
await ctx.send(embed=embed)
def setup(client):