status changes colours based on amount of servers
This commit is contained in:
@@ -12,18 +12,31 @@ class ServerStatus(commands.Cog):
|
||||
servers = {"Earth": "25568", "Moon": "25567"}
|
||||
ip = "81.82.224.207:"
|
||||
|
||||
embed = discord.Embed(colour=0x00ff00)
|
||||
# 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)
|
||||
|
||||
Reference in New Issue
Block a user