2012-10-17 00:00:43 +02:00
|
|
|
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)
|
|
|
|
def mcstatus(inp, say=None):
|
2012-10-17 00:00:43 +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:
|
2012-10-17 00:00:43 +02:00
|
|
|
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 = []
|
|
|
|
# use a loop so we don't have to update it if they add more servers
|
|
|
|
for server, status in data.items():
|
|
|
|
if status == "green":
|
2013-04-04 21:59:49 +02:00
|
|
|
out.append("{} is \x033\x02online\x02\x0f".format(server))
|
2012-08-27 14:29:03 +02:00
|
|
|
else:
|
2013-04-04 21:59:49 +02:00
|
|
|
out.append("{} is \x034\x02offline\x02\x0f".format(server))
|
2012-08-27 14:29:03 +02:00
|
|
|
|
2013-04-04 21:59:49 +02:00
|
|
|
return "\x0f" + ", ".join(out) + "."
|
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
|
2012-02-28 02:06:12 +01:00
|
|
|
def mcpaid(inp):
|
2012-09-05 21:28:27 +02:00
|
|
|
"mcpaid <username> -- Checks if <username> has a premium Minecraft account."
|
2012-05-15 00:16:41 +02:00
|
|
|
|
2012-10-17 00:00:43 +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:
|
2012-10-17 00:00:43 +02:00
|
|
|
return 'The account "{}" is not a premium Minecraft account!'.format(inp)
|