diff --git a/scripts/nope.js b/scripts/nope.js deleted file mode 100644 index 9323143..0000000 --- a/scripts/nope.js +++ /dev/null @@ -1,13 +0,0 @@ -// Description -// > nope -// - -module.exports = function(robot){ - robot.hear(/^([\s\w'@.-:]*)\s*([-+]{2}|—)(?:\s+(?:for|because|cause|cuz)\s+(.+))?$/i, function(msg){ - msg.send("Nope. https://github.com/tudev/owlbot/issues/8") - }) - - robot.hear(/(top|bottom) (\d+)/i, function(msg){ - msg.send("Nope. https://github.com/tudev/owlbot/issues/8") - }) -} diff --git a/scripts/plusplus.js b/scripts/plusplus.js new file mode 100644 index 0000000..5a6d449 --- /dev/null +++ b/scripts/plusplus.js @@ -0,0 +1,74 @@ +/* + * Custom ++/-- script to handle people ++'ing stuff. + * + * Features + * + * Per user rate limiting + * Tracking totals + * + */ + +module.exports = function (robot) { + + //This initilizes the plusplus object. So shit is gonna get overridden + //everytime we connect to redis. I think? + robot.brain.on('loaded', function () { + robot.brain.plusplus = { + users: [], + words: [] + }; + }); + + /** + * ++ - Increment points of target + * */ + robot.respond('/(.*)\\+\\+/', function (msg) { + var target = msg.match[1]; + var user = msg.message.user.name; + var t; + if (clearedTimeout(user)) { + t = robot.brain.plusplus.words.target || 0; + robot.brain.plusplus.words.target = t + 1; + setTimeout(user); + } + }); + + /** + * -- - Decrement points of target + * */ + robot.respond('/(.*)\\\-\\\-/', function (msg) { + var target = msg.match[1]; + var user = msg.message.user.name; + var t; + if (clearedTimeout(user)) { + t = robot.brain.plusplus.words.target || 0; + robot.brain.plusplus.words.target = t - 1; + setTimeout(user); + } + }); + + /** + * points - returns current total points of target + * */ + robot.respond('/points (.*)/', function (msg) { + var target = msg.match[1]; + var user = msg.message.user.name; + if (clearedTimeout(user)) { + var p = robot.brain.plusplus.words.target || 0; + msg.send("points for " + target + ": " + p); + setTimeout(user); + } + }); + + function clearedTimeout(user_name) { + var TIMEOUT = 2000; + var usertime = robot.brain.plusplus.users.user_name || 0; + return (Date.now() - usertime) > TIMEOUT; + return true; + } + + function setTimeout(user_name) { + robot.brain.plusplus.users.user_name = Date.now(); + } +}; +