2012-03-02 20:10:51 +01:00
|
|
|
from util import hook
|
|
|
|
from util import http
|
2012-08-27 14:29:03 +02:00
|
|
|
from util.text import get_text_list
|
2011-11-21 12:24:23 +01:00
|
|
|
import string
|
2012-03-02 20:10:51 +01:00
|
|
|
import socket
|
2012-08-27 14:29:03 +02:00
|
|
|
import json
|
2012-03-02 20:10:51 +01:00
|
|
|
import struct
|
|
|
|
|
|
|
|
|
2012-08-27 14:32:04 +02:00
|
|
|
def mcping_connect(host, port):
|
2012-03-02 20:10:51 +01:00
|
|
|
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
|
|
try:
|
|
|
|
sock.connect((host, port))
|
|
|
|
sock.send('\xfe')
|
|
|
|
response = sock.recv(1)
|
|
|
|
if response != '\xff':
|
2012-04-02 18:17:55 +02:00
|
|
|
return "Server gave invalid response: " + repr(response)
|
2012-03-02 20:10:51 +01:00
|
|
|
length = struct.unpack('!h', sock.recv(2))[0]
|
2012-04-02 18:17:55 +02:00
|
|
|
values = sock.recv(length * 2).decode('utf-16be').split(u'\xa7')
|
2012-03-02 20:10:51 +01:00
|
|
|
sock.close()
|
2012-04-02 18:17:55 +02:00
|
|
|
return "%s - %d/%d players"\
|
|
|
|
% (values[0], int(values[1]), int(values[2]))
|
2012-03-02 20:10:51 +01:00
|
|
|
except:
|
2012-04-02 18:17:55 +02:00
|
|
|
return "Error pinging " + host + ":" + str(port) +\
|
|
|
|
", is it up? Double-check your address!"
|
2012-03-02 20:10:51 +01:00
|
|
|
|
2011-11-20 10:23:31 +01:00
|
|
|
|
2011-11-21 07:56:14 +01:00
|
|
|
@hook.command(autohelp=False)
|
2012-08-27 14:29:03 +02:00
|
|
|
def mclogin(inp, bot=None):
|
|
|
|
"mclogin -- Checks the status of Minecraft's login servers."
|
2012-02-24 04:17:59 +01:00
|
|
|
username = bot.config.get("api_keys", {}).get("mc_user", None)
|
|
|
|
password = bot.config.get("api_keys", {}).get("mc_pass", None)
|
2012-02-24 04:23:16 +01:00
|
|
|
if password is None:
|
|
|
|
return "error: no login set"
|
2012-02-24 04:17:59 +01:00
|
|
|
|
2012-05-15 00:16:41 +02:00
|
|
|
login = http.get("https://login.minecraft.net/", user=username,
|
|
|
|
password=password, version=13)
|
|
|
|
|
2011-11-21 12:24:23 +01:00
|
|
|
if username.lower() in login.lower():
|
2011-11-21 12:27:14 +01:00
|
|
|
return "Minecraft login servers appear to be online!"
|
2011-11-20 10:23:31 +01:00
|
|
|
else:
|
2012-02-28 03:03:43 +01:00
|
|
|
return "Minecraft login servers appear to be offline!"
|
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 various Mojang 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: %s" % e
|
|
|
|
|
|
|
|
# change the json from a list of dictionaies to a dictionary
|
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-09-05 21:28:27 +02:00
|
|
|
# check if skins are online
|
|
|
|
try:
|
|
|
|
request = http.get("http://s3.amazonaws.com/MinecraftSkins/Shnaw.png")
|
|
|
|
data["minecraft skin server"] = "green"
|
|
|
|
except (http.URLError, http.HTTPError) as e:
|
|
|
|
data["minecraft skin server"] = "red"
|
|
|
|
|
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":
|
2012-08-28 07:53:20 +02:00
|
|
|
out.append("%s is \x033\x02online\x02\x03" % server)
|
2012-08-27 14:29:03 +02:00
|
|
|
else:
|
2012-08-28 07:53:20 +02:00
|
|
|
out.append("%s is \x034\x02offline\x02\x03" % server)
|
2012-08-27 14:29:03 +02:00
|
|
|
|
|
|
|
return ", ".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
|
|
|
login = http.get("http://www.minecraft.net/haspaid.jsp", user=inp)
|
|
|
|
|
2011-11-21 12:03:41 +01:00
|
|
|
if "true" in login:
|
2012-05-15 00:16:41 +02:00
|
|
|
return 'The account "%s" is a premium Minecraft account!' % inp
|
2011-11-21 12:03:41 +01:00
|
|
|
else:
|
2012-05-15 00:16:41 +02:00
|
|
|
return 'The account "%s" is not a premium Minecraft account!' % inp
|
2012-03-02 20:10:51 +01:00
|
|
|
|
|
|
|
|
|
|
|
@hook.command
|
|
|
|
def mcping(inp):
|
2012-05-16 05:07:27 +02:00
|
|
|
"mcping <server>[:port] - Ping a Minecraft server to check status."
|
2012-03-02 20:10:51 +01:00
|
|
|
inp = inp.strip().split(" ")[0]
|
|
|
|
|
|
|
|
if ":" in inp:
|
|
|
|
host, port = inp.split(":", 1)
|
|
|
|
try:
|
|
|
|
port = int(port)
|
|
|
|
except:
|
2012-03-19 04:09:26 +01:00
|
|
|
return "error: invalid port!"
|
2012-03-02 20:10:51 +01:00
|
|
|
else:
|
|
|
|
host = inp
|
2012-08-27 14:32:04 +02:00
|
|
|
port = 25565
|
|
|
|
return mcping_connect(host, port)
|