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/rss.py
2013-09-04 18:30:04 +08:00

40 lines
1.2 KiB
Python

from util import hook, http, web, text
@hook.command("feed")
@hook.command
def rss(inp, say=None):
"""rss <feed> -- Gets the first three items from the RSS feed <feed>."""
limit = 3
# 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"
elif strip == "ars":
feed = "http://feeds.arstechnica.com/arstechnica/index"
else:
feed = inp
query = "SELECT title, link FROM rss WHERE url=@feed LIMIT @limit"
result = web.query(query, {"feed": feed, "limit": limit})
if not result.rows:
return "Could not find/read RSS feed."
for row in result.rows:
title = text.truncate_str(row["title"], 100)
try:
link = web.isgd(row["link"])
except (web.ShortenError, http.HTTPError, http.URLError):
link = row["link"]
say(u"{} - {}".format(title, link))
@hook.command(autohelp=False)
def rb(inp, say=None):
"""rb -- Shows the latest Craftbukkit recommended build"""
rss("bukkit", say)