Skip to content

Instantly share code, notes, and snippets.

@regtan
Last active August 29, 2015 14:11
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 regtan/27fa7959f4718c7ae8bb to your computer and use it in GitHub Desktop.
Save regtan/27fa7959f4718c7ae8bb to your computer and use it in GitHub Desktop.
redisClient = require('redis').createClient()
unixtime = require('unixtime')
push = require('pushover-notifications')
pushoverClient = new push({user:YOUR_USER_TOKEN,token:YOUR_API_TOKEN})
module.exports = (robot) ->
robot.respond /(regtan).*(呼んで|よんで).*/i, (msg) ->
isRateLimited (err,result) ->
if err
msg.send("redis エラーですー")
if result == true
msg.send("しばらく経ってからおかけ直しください")
else
msg.send ("regtanを呼び出しました")
sendMessage("#{msg.message.user.name}が呼んでいます","ircからの呼び出しです")
redisClient.set process.env.HUBOT_IRC_NICK + "_last_called_at",unixtime()
sendMessage = ( messageBody = "" , title = "", sound = "magick", url = "", priority = 0) ->
pushoverClient.send(
{
message : messageBody,
title : title,
sound : sound,
url : url,
priority : priority
},(err,result) ->
if err
throw err
)
isRateLimited = (callback) ->
redisClient.get process.env.HUBOT_IRC_NICK + "_last_called_at",(err,val) ->
if err
return callback new Error "redis error"
if val == null
return callback(null,false)
if unixtime() - val > (60 * 5)
return callback(null,false)
else
return callback(null,true)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment