Skip to content

Commit

Permalink
Removed all functionality.
Browse files Browse the repository at this point in the history
Just spam, whitelist and blacklist.
Current bugs:
 saveLists() not implemented
 if /names is long, the callback will be triggered twice!
  • Loading branch information
nikhilm committed Jul 10, 2011
1 parent ec02c76 commit e318af9
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 149 deletions.
51 changes: 11 additions & 40 deletions README.md
Expand Up @@ -13,46 +13,17 @@ All commands require you to explicitly mention lunchbot at the beginning of the
either as 'lunchbot:' or 'lunchbot' either as 'lunchbot:' or 'lunchbot'


1) ask everyone in channel for lunch [IMPLEMENTED] 1) ask everyone in channel for lunch [IMPLEMENTED]
- ask everyone - spam
ask all ops + a whitelist - a blacklist


2) ask ops for lunch (At mozilla, all current interns have ops) [IMPLEMENTED] 2) add yourself to the whitelist (automatically takes you of the blacklist)
- ask ops - whitelist me


3) express interest in lunch 3) add yourself to the blacklist (automatically takes you of the whitelist)
- i [want/would like/need/desperate for] lunch - blacklist me
- i [am/will be] hungry


once you do this you will be pinged for lunch regardless of you signing up for alarms 4) you've already had lunch, so don't bother for the rest of the day (temporary blacklist)
or exclusion. - i had lunch

4) create a lunch time and ping everyone interested at that time (this is pretty useless without options) [IMPLEMENTED]
- lunch at HH:MM [+options] [message]
eg. lunch at 12:30 at Le Boulanger

Options:
[NOT implemented, needs some thinking]
* --invite=<names> - automatically ping all <names> (space separated nicks) at that time
* --exclusive - no one else can sign up for this lunch and it won't show up when anyone not in --invite runs command (5)

5) view lunch times
- lunches

6) signup for a lunch time [IMPLEMENTED]
- signup HH:MM with <nick>

You will be pinged 5 minutes before the time.

7) disable notifications
- had lunch
full
not hungry

disable all lunch notifications, including any you have manually signed up for.
NOTE: there is no way to undo this for now, so be careful.

8) reset (useful for the next day)
- rollover <password>
requires a password so that only one responsible person can initiate day change.


lunchbot does NOT handle time zones, it better be in the same physical location as everyone else. lunchbot does NOT handle time zones, it better be in the same physical location as everyone else.


Expand All @@ -70,10 +41,10 @@ Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long copies of this license document, and changing it is allowed as long
as the name is changed. as the name is changed.


DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE do what the fuck you want to public license
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION terms and conditions for copying, distribution and modification


0. You just DO WHAT THE FUCK YOU WANT TO. 0. you just do what the fuck you want to.


(Attribution is appreciated :)) (Attribution is appreciated :))


Expand Down
165 changes: 56 additions & 109 deletions lunchbot.js
Expand Up @@ -7,45 +7,13 @@
var irc = require('IRC-js'); var irc = require('IRC-js');
var cmd = require('cmd'); var cmd = require('cmd');


var SERV = 'localhost'; var SERV = 'irc.mozilla.org';
//var SERV = 'localhost';
var NICK = 'lunchbot'; var NICK = 'lunchbot';
var CHAN = '#lunchbot'; var CHAN = '#interns';


var conn = new irc({ 'server': SERV, 'nick': NICK }); var conn = new irc({ 'server': SERV, 'nick': NICK });


var LunchTime = function(time) {
this._time = time;
this._list = [];
}

LunchTime.prototype.add = function(by, message) {
this._list.push({by: by, message: message, signups: []});
}

LunchTime.prototype.signup = function(nick, with_) {
for (var i = 0; i < this._list.length; i++) {
if (this._list[i].by == with_)
this._list[i].signups.push(nick);
}
}

LunchTime.prototype.notify = function() {
for (var i = 0; i < this._list.length; i++) {
var obj = this._list[i];
var msg = obj.signups.concat([obj.by]).join(', ') + ': you have a lunch at ' + this._time + ' which is NOW (' + obj.message + ')';
conn.privmsg(CHAN, msg);
}
}

LunchTime.prototype.toString = function() {
var str = '';
for (var i = 0; i < this._list.length; i++)
str += this._time + ' ' + this._list[i].by + ': ' + this._list[i].message + '\n';
return str;
}

var lunches = {};

var sanitizeNick = function(nick) { var sanitizeNick = function(nick) {
return nick.replace(/^[%@]/, ''); return nick.replace(/^[%@]/, '');
} }
Expand All @@ -57,76 +25,65 @@ var sanitizeNickList = function(nicks) {
return clean; return clean;
} }


var commands = { var getOperators = function(nicks) {
ask: cmd.use({ return nicks
'ops': function() { .filter(function(nick) { return nick[0] == '@' })
conn.names(CHAN, function(channel, nicks) { .map(sanitizeNick);
var ops = []; }
for (var i = 0; i < nicks.length; i++) {
if (nicks[i].indexOf('@') == 0)
ops.push(nicks[i]);
}

if (ops.length == 0)
return;

conn.privmsg(CHAN, sanitizeNickList(ops).join(', ') + ': lunch?');
});
},
_unhandled: function() {
conn.names(CHAN, function(channel, nicks) {
conn.privmsg(CHAN, sanitizeNickList(nicks).join(', ') + ': lunch?');
});
}
}),

lunch: cmd.use({
'at': function(command) {
var args = command.unshifted();
var time = args[0];
var match = time.match(/^(0?[0-9]|1[0-9]|2[0-3]):(0[0-9]|[1-5][0-9])$/);
if (!match)
conn.privmsg(command.options.channel, sanitizeNick(command.options.nick) + ': invalid time');


if (!lunches[time]) var whiteList = [];
lunches[time] = new LunchTime(time); var blackList = [];
lunches[time].add(command.options.nick, args.slice(1).join(' ')); // returns true if success
// false if already on that list
var editLists = function(nick, addTo, removeFrom) {
var nick = sanitizeNick(nick);
if (addTo.indexOf(nick) == -1) {
addTo.push(nick);
} else {
return false;
} }
}), var index = removeFrom.indexOf(nick);
if (index != -1)
removeFrom.splice(index, 1);
return true;
}


lunches: function(command) { var commands = {
var lunchesStr = ''; spam: function(command) {
for (var time in lunches) { console.log("CALLED");
if (!lunches.hasOwnProperty(time)) conn.names(CHAN, function(channel, nicks) {
continue; var ops = getOperators(nicks);
var lunchtime = lunches[time]; var list = ops.filter(function(nick) { return ops.indexOf(nick) == -1; })
lunchesStr += lunchtime; .concat(whiteList.filter(function(nick) { return ops.indexOf(nick) == -1; }));
} if (list.length != 0)
conn.privmsg(command.options.channel, lunchesStr); conn.privmsg(command.options.channel, list.join(', ') + ': lunch?');
});
}, },


signup: function(command) { whitelist: function(command) {
var args = command.unshifted(); if (editLists(command.options.nick, whiteList, blackList))
var time = args[0]; conn.privmsg(command.options.channel, command.options.nick + ': ' + 'added to whitelist');
var match = time.match(/^(0?[0-9]|1[0-9]|2[0-3]):(0[0-9]|[1-5][0-9])$/); else
if (!match) conn.privmsg(command.options.channel, command.options.nick + ': ' + 'already on whitelist');
conn.privmsg(command.options.channel, sanitizeNick(command.options.nick) + ': invalid time'); },
if (!(args[1] == 'with'))
conn.privmsg(command.options.channel, sanitizeNick(command.options.nick) + ': invalid syntax');


if (!args[2]) blacklist: function(command) {
conn.privmsg(command.options.channel, sanitizeNick(command.options.nick) + ': with whom?'); if (editLists(command.options.nick, blackList, whiteList))
conn.privmsg(command.options.channel, command.options.nick + ': ' + 'added to blacklist');
else
conn.privmsg(command.options.channel, command.options.nick + ': ' + 'already on blacklist');
},


if (lunches[time]) hadlunch: function(command) {
lunches[time].signup(command.options.nick, args[2]); // TODO
} }
}; };


var dispatcher = cmd.use({ var dispatcher = cmd.use({
'ask': commands.ask, 'spam': commands.spam,
'lunch': commands.lunch, 'whitelist': commands.whitelist,
'lunches': commands.lunches, 'blacklist': commands.blacklist,
'signup': commands.signup, 'i': commands.hadlunch,
_unhandled: function(cmd) { _unhandled: function(cmd) {
console.log("don't understand", cmd); console.log("don't understand", cmd);
} }
Expand All @@ -146,22 +103,12 @@ var onConnect = function() {
}); });
} }


var notifier = function() {
var d = new Date();
var h = d.getHours() < 10 ? "0" + d.getHours() : "" + d.getHours();
var m = d.getMinutes() < 10 ? "0" + d.getMinutes() : "" + d.getMinutes();
var t = h + ":" + m;

for (var i in lunches) {
if (i == t) {
lunches[i].notify();
}
}
}

conn.connect(function() { conn.connect(function() {
console.log('Connected'); console.log('Connected');
setTimeout(onConnect, 1000); setTimeout(onConnect, 1000);
// lunches checker });
setInterval(notifier, 60 * 1000);
process.on('SIGINT', function () {
saveLists();
console.log('Got SIGINT. Press Control-D to exit.');
}); });

0 comments on commit e318af9

Please sign in to comment.