Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions scripts/nope.js

This file was deleted.

74 changes: 74 additions & 0 deletions scripts/plusplus.js
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) {
Copy link
Collaborator

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, using robot.hear will filter any message (ie something++)

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) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should be robot.hear instead of robot.respond. The reason is that respond requires @owlbot at the head of the message. We want to be able to bill++ without @owlbot bill++

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();
}
};