Skip to content

Instantly share code, notes, and snippets.

@AlSquire
Last active December 15, 2015 09:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlSquire/5242049 to your computer and use it in GitHub Desktop.
Save AlSquire/5242049 to your computer and use it in GitHub Desktop.
Script for Hubot (http://hubot.github.com/) to use with my Weblapine (https://github.com/AlSquire/WebLapine). Needs WEBLAPINE_URI (ie: http://mylapine.net) and WEBLAPINE_IRC_NETWORK_NAME (ie: freenode) env variables to work.
# Description:
# Ouai WebLapine ! See https://github.com/AlSquire/WebLapine
#
# Commands:
# anything with http://www.example.com - Saved to WebLapine
# hubot links - The Weblapine uri for the current irc channel
# hubot addlog <quote> - Record <quote>
# hubot log - Random quote
# hubot log + - Details about the last displayed quote (more + for deeper history)
# hubot log <term> - Search quotes for <term>
#
# Configuration:
# WEBLAPINE_URI
# WEBLAPINE_IRC_NETWORK_NAME
module.exports = (robot) ->
lapineClient = robot.http(process.env.WEBLAPINE_URI)
.header('Content-type', 'application/json')
resourcePath = (type, msg) ->
room = msg.message.room.replace('#', '')
process.env.WEBLAPINE_IRC_NETWORK_NAME + "/" + room + "/" + type
robot.respond /links/i, (msg) ->
msg.send process.env.WEBLAPINE_URI + '/' + resourcePath('links', msg)
robot.hear /http[s]?:\/\/\w+/, (msg) ->
params = { link: { sender: msg.message.user.name, line: msg.message.text } }
lapineClient.scope resourcePath('links', msg), (client) ->
client.post(JSON.stringify(params)) (err, res, body) ->
msg.send "Ooouch did not work" if res.statusCode != 200
robot.respond /log(\s+(.*))?/i, (msg) ->
arg = msg.match[2]
if !arg?
path = 'random'
query = {}
else if arg.match(/^(\+)+$/)
path = 'previous'
query = { offset: arg.length - 1}
else
path = 'search'
query = { term: arg }
lapineClient.scope resourcePath('logs', msg) + '/' + path, (client) ->
client.query(query).get() (err, res, body) -> msg.send body
robot.respond /addlog (.*)/i, (msg) ->
params = { log: { sender: msg.message.user.name, line: msg.match[1] } }
lapineClient.scope resourcePath('logs', msg), (client) ->
client.post(JSON.stringify(params)) (err, res, body) ->
if res.statusCode == 200
msg.send "C'est dans la boite"
else
msg.send "Ooouch pas dans la boite"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment