Skip to content

Instantly share code, notes, and snippets.

@paulgreg
Created May 15, 2014 07:04
Show Gist options
  • Save paulgreg/ab3cfe807c9f2f423bba to your computer and use it in GitHub Desktop.
Save paulgreg/ab3cfe807c9f2f423bba to your computer and use it in GitHub Desktop.
rsstodolist Hubot script
# Description:
# Allows you to send or fetch links to/from the rsstodolist service (https://rsstodolist.appspot.com)
#
# Dependencies:
# jsdom
#
# Configuration:
# None
#
# Commands:
# hubot rtdl show <user_name> - Display the <user_name> rsstodolist feed url
# hubot rtdl add <user_name> <link> - Send the <link> to <user_name> rsstodolist feed
# hubot rtdl last <user_name> <limit> - Display last <optional limit> links for that <user_name>
#
# Author:
# athieriot
# paulgreg
jsdom = require 'jsdom'
module.exports = (robot) ->
robot.respond /rtdl (add|show|last) ([^ ]*)( .*)?/i, (msg) ->
server_url = 'http://rsstodolist.appspot.com'
[action, user_name, arg] = [msg.match[1], escape(msg.match[2]), msg.match[3]]
if action == 'add' && arg != undefined
msg.http(server_url + '/add')
.query(n: user_name)
.query(url: arg.trim())
.get() (err, res, body) ->
status = res.statusCode
if status == 200 || status == 302
msg.reply 'The feed of ' + user_name + ' is updated'
else
msg.reply "An error occured on " + user_name + " feed"
else if action == 'show'
msg.reply user_name + ' feed is ' + server_url + '/?n=' + user_name
else if action == 'last'
msg.http(server_url + '/')
.query(n: user_name)
.query(l: arg || 10)
.get() (err, res, body) ->
try
xml = jsdom.jsdom(body)
for item in xml.getElementsByTagName("rss")[0].getElementsByTagName("channel")[0].getElementsByTagName("item")
do (item) ->
msg.reply " - " + item.getElementsByTagName("link")[0].childNodes[0].nodeValue
catch err
msg.reply err
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment