This repository has been archived on 2023-04-13. You can view files and clone it, but cannot push or open issues or pull requests.
CloudBot/plugins/minecraft_status.py

54 lines
1.6 KiB
Python
Raw Normal View History

from util import hook, http
2012-08-27 14:29:03 +02:00
import json
2011-11-20 10:23:31 +01:00
2012-04-02 18:17:55 +02:00
2012-08-27 14:29:03 +02:00
@hook.command(autohelp=False)
2013-09-04 15:31:07 +02:00
def mcstatus(inp):
2013-09-04 12:30:04 +02:00
"""mcstatus -- Checks the status of various Mojang (the creators of Minecraft) servers."""
2012-05-15 00:16:41 +02:00
2012-09-05 21:16:56 +02: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-05 21:16:56 +02:00
2013-05-13 15:30:43 +02:00
# lets just reformat this data to get in a nice format
2012-08-27 14:29:03 +02:00
data = json.loads(request.replace("}", "").replace("{", "").replace("]", "}").replace("[", "{"))
2012-05-15 00:16:41 +02:00
2012-08-27 14:29:03 +02:00
out = []
2012-08-27 14:29:03 +02:00
# use a loop so we don't have to update it if they add more servers
2013-09-04 15:31:07 +02:00
yes = []
no = []
2012-08-27 14:29:03 +02:00
for server, status in data.items():
if status == "green":
2013-09-04 15:31:07 +02:00
yes.append(server)
2012-08-27 14:29:03 +02:00
else:
2013-09-04 15:31:07 +02:00
no.append(server)
if yes:
out = "\x033\x02Online\x02\x0f: " + ", ".join(yes)
2013-09-04 15:36:35 +02:00
if no:
out += " "
2013-09-04 15:31:07 +02:00
if no:
out += "\x034\x02Offline\x02\x0f: " + ", ".join(no)
2013-09-04 23:59:50 +02:00
return "\x0f" + out.replace(".mojang.com", ".mj") \
.replace(".minecraft.net", ".mc")
2012-04-02 18:17:55 +02:00
2011-11-21 12:03:41 +01:00
2012-08-27 14:32:04 +02:00
@hook.command("haspaid")
2011-11-21 12:03:41 +01:00
@hook.command
def mcpaid(inp):
2013-09-04 12:30:04 +02:00
"""mcpaid <username> -- Checks if <username> has a premium Minecraft account."""
2012-05-15 00:16:41 +02:00
user = inp.strip()
try:
status = http.get("http://www.minecraft.net/haspaid.jsp", user=user)
except (http.URLError, http.HTTPError) as e:
return "Unable to get user registration status: {}".format(e)
if "true" in status:
return 'The account "{}" is a premium Minecraft account!'.format(inp)
2011-11-21 12:03:41 +01:00
else:
return 'The account "{}" is not a premium Minecraft account!'.format(inp)