diff --git a/plugins/minecraft_status.py b/plugins/minecraft_status.py index 8bb7e07..da5cd73 100644 --- a/plugins/minecraft_status.py +++ b/plugins/minecraft_status.py @@ -34,21 +34,3 @@ def mcstatus(inp): return "\x0f" + out.replace(".mojang.com", ".mj") \ .replace(".minecraft.net", ".mc") - - -@hook.command("haspaid") -@hook.command -def mcpaid(inp): - """mcpaid -- Checks if has a premium Minecraft account.""" - - 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) - else: - return 'The account "{}" is not a premium Minecraft account!'.format(inp) diff --git a/plugins/minecraft_user.py b/plugins/minecraft_user.py new file mode 100644 index 0000000..17e972a --- /dev/null +++ b/plugins/minecraft_user.py @@ -0,0 +1,69 @@ +from util import hook, http + +NAME_URL = "https://account.minecraft.net/buy/frame/checkName/{}" +PAID_URL = "http://www.minecraft.net/haspaid.jsp" + + +class McuError(Exception): + pass + + +def get_status(name): + """ takes a name and returns status """ + try: + name_encoded = http.quote_plus(name) + response = http.get(NAME_URL.format(name_encoded)) + except (http.URLError, http.HTTPError) as e: + raise McuError("Could not get name status: {}".format(e)) + + if "OK" in response: + return "free" + elif "TAKEN" in response: + return "taken" + elif "invalid characters" in response: + return "invalid" + + +def is_paid(name): + """ takes a name and returns true if it's assosiated with a paid minecraft account + if the account does not exist or is not paid, returns false """ + try: + response = http.get(PAID_URL, user=name) + except (http.URLError, http.HTTPError) as e: + raise McuError("Could not get payment status: {}".format(e)) + + if "true" in response: + return True + else: + return False + + +@hook.command("haspaid") +@hook.command("mcstatus") +@hook.command +def mcuser(inp): + """mcpaid -- Gets information about the Minecraft user .""" + user = inp.strip() + + try: + name_status = get_status(user) + except McuError as e: + return e + + if name_status == "taken": + try: + paid = is_paid(user) + except McuError as e: + return e + + if paid: + return u"The account \x02{}\x02 exists and \x02is a paid\x02 minecraft account.".format(user) + else: + return u"The account \x02{}\x02 exists, but \x02is not a paid\x02 minecraft account.".format(user) + elif name_status == "free": + return u"The account \x02{}\x02 does not exist.".format(user) + elif name_status == "invalid": + return u"The name \x02{}\x02 contains invalid characters.".format(user) + else: + # if you see this, panic + return "Unknown Error." \ No newline at end of file