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/mctools.py

44 lines
1.4 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)
def mcstatus(inp, say=None):
"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 = []
# 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
def mcpaid(inp):
"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)