Skip to content
Open
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
30 changes: 27 additions & 3 deletions krasula.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ bot.on('join', function(channel, nick) {
if (nick == options.nick) {
console.log('Connected!');
}

store.set('nick_' + nick, true);
});

store.on("error", function (err) {
Expand All @@ -70,14 +72,24 @@ bot.addListener('error', function(err) {
if (err.rawCommand != '421') console.log(err);
});

bot.addListener('names', function(channel, nicks) {
if (nicks) {
for (var nick in nicks) {
store.set('nick_' + nick, true);
}
}
});
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Should we first delete all nick_ keys here?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Or, how about we use a Set for each channel? http://redis.io/commands#set


bot.addListener('quit', function (channel, who, reason) {
console.log(who + ' has left');
store.set('quit_' + who, Date.now());
store.del('nick_' + who, null);
});

bot.addListener('part', function (channel, who, reason) {
console.log(who + ' has left');
store.set('quit_' + who, Date.now());
store.del('nick_' + who, null);
});

bot.addListener('message', function (from, channel, msg) {
Expand Down Expand Up @@ -188,9 +200,21 @@ bot.addListener('message', function (from, channel, msg) {
if (parts.shift() != options.nick + ':') return;
if (parts.shift() != 'seen') return;
var who = parts.shift();
store.get('quit_' + who, function(err, res) {
var when = new Date(parseInt(res));
bot.say(channel, who + ' has left on ' + when.toString());
store.get('nick_' + who, function(err, res) {
if (res) {
bot.say(channel, who + ' jest w tej chwili na kanale');
}
else {
store.get('quit_' + who, function(err, res) {
if (res) {
var when = new Date(parseInt(res));
bot.say(channel, who + ' opuścił kanał ostatnio dnia ' + when.toString());
}
else {
bot.say(channel, who + ' mnie jeszcze nie doił(a) :(');
}
});
}
});
});

Expand Down