Tweaked mctools.py, added new rss.py plugin
This commit is contained in:
parent
ab02d10674
commit
6ae302bf48
3 changed files with 73 additions and 12 deletions
|
@ -1,7 +1,4 @@
|
||||||
from util import hook
|
from util import hook, http
|
||||||
from util import http
|
|
||||||
from util.text import get_text_list
|
|
||||||
import string
|
|
||||||
import socket
|
import socket
|
||||||
import json
|
import json
|
||||||
import struct
|
import struct
|
||||||
|
@ -44,12 +41,12 @@ def mclogin(inp, bot=None):
|
||||||
|
|
||||||
@hook.command(autohelp=False)
|
@hook.command(autohelp=False)
|
||||||
def mcstatus(inp, say=None):
|
def mcstatus(inp, say=None):
|
||||||
"mcstatus -- Checks the status various Mojang servers."
|
"mcstatus -- Checks the status of various Mojang (the creators of Minecraft) servers."
|
||||||
|
|
||||||
try:
|
try:
|
||||||
request = http.get("http://status.mojang.com/check")
|
request = http.get("http://status.mojang.com/check")
|
||||||
except (http.URLError, http.HTTPError) as e:
|
except (http.URLError, http.HTTPError) as e:
|
||||||
return "Unable to get minecraft server status: %s" % e
|
return "Unable to get Minecraft server status: {}".format(e)
|
||||||
|
|
||||||
# change the json from a list of dictionaies to a dictionary
|
# change the json from a list of dictionaies to a dictionary
|
||||||
data = json.loads(request.replace("}", "").replace("{", "").replace("]", "}").replace("[", "{"))
|
data = json.loads(request.replace("}", "").replace("{", "").replace("]", "}").replace("[", "{"))
|
||||||
|
@ -58,9 +55,9 @@ def mcstatus(inp, say=None):
|
||||||
# use a loop so we don't have to update it if they add more servers
|
# use a loop so we don't have to update it if they add more servers
|
||||||
for server, status in data.items():
|
for server, status in data.items():
|
||||||
if status == "green":
|
if status == "green":
|
||||||
out.append("%s is \x033\x02online\x02\x03" % server)
|
out.append("{} is \x033\x02online\x02\x03".format(server))
|
||||||
else:
|
else:
|
||||||
out.append("%s is \x034\x02offline\x02\x03" % server)
|
out.append("{} is \x034\x02offline\x02\x03".format(server))
|
||||||
|
|
||||||
return ", ".join(out) + "."
|
return ", ".join(out) + "."
|
||||||
|
|
||||||
|
@ -69,12 +66,18 @@ def mcstatus(inp, say=None):
|
||||||
@hook.command
|
@hook.command
|
||||||
def mcpaid(inp):
|
def mcpaid(inp):
|
||||||
"mcpaid <username> -- Checks if <username> has a premium Minecraft account."
|
"mcpaid <username> -- Checks if <username> has a premium Minecraft account."
|
||||||
login = http.get("http://www.minecraft.net/haspaid.jsp", user=inp)
|
|
||||||
|
|
||||||
if "true" in login:
|
user = inp.strip()
|
||||||
return 'The account "%s" is a premium Minecraft account!' % inp
|
|
||||||
|
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:
|
else:
|
||||||
return 'The account "%s" is not a premium Minecraft account!' % inp
|
return 'The account "{}" is not a premium Minecraft account!'.format(inp)
|
||||||
|
|
||||||
|
|
||||||
@hook.command
|
@hook.command
|
||||||
|
|
29
plugins/news.py
Normal file
29
plugins/news.py
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
from util import hook, web
|
||||||
|
|
||||||
|
|
||||||
|
@hook.command("feed")
|
||||||
|
@hook.command
|
||||||
|
def rss(inp, say=None):
|
||||||
|
|
||||||
|
# preset news feeds
|
||||||
|
strip = inp.lower().strip()
|
||||||
|
if strip == "bukkit":
|
||||||
|
feed = "http://dl.bukkit.org/downloads/craftbukkit/feeds/latest-rb.rss"
|
||||||
|
limit = 1
|
||||||
|
elif strip == "xkcd":
|
||||||
|
feed = "http://xkcd.com/rss.xml"
|
||||||
|
limit = 2
|
||||||
|
else:
|
||||||
|
feed = inp
|
||||||
|
limit = 3
|
||||||
|
|
||||||
|
query = "SELECT title, link FROM rss WHERE url=@feed LIMIT @limit"
|
||||||
|
result = web.query(query, {"feed": feed, "limit": limit or 3})
|
||||||
|
for row in result.rows:
|
||||||
|
link = web.isgd(row["link"])
|
||||||
|
say(u"{} - {}".format(row["title"], link))
|
||||||
|
|
||||||
|
|
||||||
|
@hook.command
|
||||||
|
def rb(inp, say=None):
|
||||||
|
rss("bukkit", say)
|
29
plugins/rss.py
Normal file
29
plugins/rss.py
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
from util import hook, web
|
||||||
|
|
||||||
|
|
||||||
|
@hook.command("feed")
|
||||||
|
@hook.command
|
||||||
|
def rss(inp, say=None):
|
||||||
|
|
||||||
|
# preset news feeds
|
||||||
|
strip = inp.lower().strip()
|
||||||
|
if strip == "bukkit":
|
||||||
|
feed = "http://dl.bukkit.org/downloads/craftbukkit/feeds/latest-rb.rss"
|
||||||
|
limit = 1
|
||||||
|
elif strip == "xkcd":
|
||||||
|
feed = "http://xkcd.com/rss.xml"
|
||||||
|
limit = 2
|
||||||
|
else:
|
||||||
|
feed = inp
|
||||||
|
limit = 3
|
||||||
|
|
||||||
|
query = "SELECT title, link FROM rss WHERE url=@feed LIMIT @limit"
|
||||||
|
result = web.query(query, {"feed": feed, "limit": limit or 3})
|
||||||
|
for row in result.rows:
|
||||||
|
link = web.isgd(row["link"])
|
||||||
|
say(u"{} - {}".format(row["title"], link))
|
||||||
|
|
||||||
|
|
||||||
|
@hook.command
|
||||||
|
def rb(inp, say=None):
|
||||||
|
rss("bukkit", say)
|
Reference in a new issue