This repository has been archived on 2023-04-13. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
CloudBot/disabled_stuff/minecraft_status.py

45 lines
1.3 KiB
Python
Raw Normal View History

2012-08-28 00:29:03 +12:00
import json
2011-11-20 22:23:31 +13:00
2014-02-14 16:36:57 +13:00
from util import hook, http
2012-04-02 09:17:55 -07:00
2012-08-28 00:29:03 +12:00
@hook.command(autohelp=False)
2013-09-04 21:31:07 +08:00
def mcstatus(inp):
2013-09-04 18:30:04 +08:00
"""mcstatus -- Checks the status of various Mojang (the creators of Minecraft) servers."""
2012-05-15 10:16:41 +12:00
2012-09-06 07:16:56 +12:00
try:
request = http.get("http://status.mojang.com/check")
except (http.URLError, http.HTTPError) as e:
return "Unable to get Minecraft server status: {}".format(e)
2012-09-06 07:16:56 +12:00
2013-05-14 01:30:43 +12:00
# lets just reformat this data to get in a nice format
2012-08-28 00:29:03 +12:00
data = json.loads(request.replace("}", "").replace("{", "").replace("]", "}").replace("[", "{"))
2012-05-15 10:16:41 +12:00
2012-08-28 00:29:03 +12:00
out = []
2012-08-28 00:29:03 +12:00
# use a loop so we don't have to update it if they add more servers
2014-02-28 15:52:05 +13:00
green = []
yellow = []
red = []
2012-08-28 00:29:03 +12:00
for server, status in data.items():
if status == "green":
2014-02-28 15:52:05 +13:00
green.append(server)
elif status == "yellow":
yellow.append(server)
2012-08-28 00:29:03 +12:00
else:
2014-02-28 15:52:05 +13:00
red.append(server)
if green:
out = "\x033\x02Online\x02\x0f: " + ", ".join(green)
if yellow:
out += " "
if yellow:
out += "\x02Issues\x02: " + ", ".join(yellow)
if red:
2013-09-04 21:36:35 +08:00
out += " "
2014-02-28 15:52:05 +13:00
if red:
out += "\x034\x02Offline\x02\x0f: " + ", ".join(red)
2013-09-05 09:59:50 +12:00
return "\x0f" + out.replace(".mojang.com", ".mj") \
.replace(".minecraft.net", ".mc")