Last active
August 29, 2015 14:11
-
-
Save regtan/27fa7959f4718c7ae8bb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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