-
Notifications
You must be signed in to change notification settings - Fork 2
Adding plusplus #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Adding plusplus #16
Changes from all commits
0e950ee
7a1ce97
019509a
ac2bc69
378d39a
bf62195
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These should be The concolusion of each ++/-- should also end with owlbot returning the current score for a specific item. |
||
| 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(); | ||
| } | ||
| }; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using
robot.respond, owlbot will only respond to ++/-- when the message it@owlbot something++was this intentional? If not, usingrobot.hearwill filter any message (iesomething++)