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
Original file line number Diff line number Diff line change
Expand Up @@ -13,46 +13,17 @@ All commands require you to explicitly mention lunchbot at the beginning of the
either as 'lunchbot:' or 'lunchbot'

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]
- ask ops
2) add yourself to the whitelist (automatically takes you of the blacklist)
- whitelist me

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

once you do this you will be pinged for lunch regardless of you signing up for alarms
or exclusion.

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.
4) you've already had lunch, so don't bother for the rest of the day (temporary blacklist)
- i had lunch

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
as the name is changed.

DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
do what the fuck you want to public license
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 :))

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

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

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) {
return nick.replace(/^[%@]/, '');
}
Expand All @@ -57,76 +25,65 @@ var sanitizeNickList = function(nicks) {
return clean;
}

var commands = {
ask: cmd.use({
'ops': function() {
conn.names(CHAN, function(channel, nicks) {
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');
var getOperators = function(nicks) {
return nicks
.filter(function(nick) { return nick[0] == '@' })
.map(sanitizeNick);
}

if (!lunches[time])
lunches[time] = new LunchTime(time);
lunches[time].add(command.options.nick, args.slice(1).join(' '));
var whiteList = [];
var blackList = [];
// 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 lunchesStr = '';
for (var time in lunches) {
if (!lunches.hasOwnProperty(time))
continue;
var lunchtime = lunches[time];
lunchesStr += lunchtime;
}
conn.privmsg(command.options.channel, lunchesStr);
var commands = {
spam: function(command) {
console.log("CALLED");
conn.names(CHAN, function(channel, nicks) {
var ops = getOperators(nicks);
var list = ops.filter(function(nick) { return ops.indexOf(nick) == -1; })
.concat(whiteList.filter(function(nick) { return ops.indexOf(nick) == -1; }));
if (list.length != 0)
conn.privmsg(command.options.channel, list.join(', ') + ': lunch?');
});
},

signup: 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 (!(args[1] == 'with'))
conn.privmsg(command.options.channel, sanitizeNick(command.options.nick) + ': invalid syntax');
whitelist: function(command) {
if (editLists(command.options.nick, whiteList, blackList))
conn.privmsg(command.options.channel, command.options.nick + ': ' + 'added to whitelist');
else
conn.privmsg(command.options.channel, command.options.nick + ': ' + 'already on whitelist');
},

if (!args[2])
conn.privmsg(command.options.channel, sanitizeNick(command.options.nick) + ': with whom?');
blacklist: function(command) {
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])
lunches[time].signup(command.options.nick, args[2]);
hadlunch: function(command) {
// TODO
}
};

var dispatcher = cmd.use({
'ask': commands.ask,
'lunch': commands.lunch,
'lunches': commands.lunches,
'signup': commands.signup,
'spam': commands.spam,
'whitelist': commands.whitelist,
'blacklist': commands.blacklist,
'i': commands.hadlunch,
_unhandled: function(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() {
console.log('Connected');
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.