3
0
mirror of https://github.com/reality/dbot.git synced 2024-11-23 12:29:26 +01:00

moved everything to a module

This commit is contained in:
Luke Slater 2011-08-22 19:24:23 +01:00
parent a32b011b7f
commit b1cb45798f
5 changed files with 85 additions and 49 deletions

30
karma.js Normal file
View File

@ -0,0 +1,30 @@
var karma = function(dbot) {
var dbot = dbot;
return {
'listener': function(data) {
if(data.user == 'aisbot' && data.channel == 'aisbot' &&
dbot.waitingForKarma != false && data.message.match(/is at/)) {
var split = data.message.split(' ');
var target = split[0];
var karma = split[3];
if(karma.startsWith('-')) {
dbot.say(dbot.waitingForKarma, target + dbot.db.hatedPhrases.random() + ' (' + karma + ')');
} else if(karma == '0') {
dbot.say(dbot.waitingForKarma, target + dbot.db.neutralPhrases.random() + ' (0)');
} else {
dbot.say(dbot.waitingForKarma, target + dbot.db.lovedPhrases.random() + ' (' + karma + ')');
}
dbot.waitingForKarma = false;
}
},
'on': 'PRIVMSG'
}
};
exports.fetch = function(dbot) {
return karma(dbot);
};

26
kick.js Normal file
View File

@ -0,0 +1,26 @@
var kick = function(dbot) {
return {
'listener': function(data) {
if(data.kickee == dbot.name) {
dbot.instance.join(data.channel); // make interface
dbot.say(data.channel, 'Thou shalt not kick ' + dbot.name);
dbot.db.kicks[name] += 1;
} else {
if(dbot.db.kicks[data.kickee] == undefined) {
dbot.db.kicks[data.kickee] = 1;
} else {
dbot.db.kicks[data.kickee] += 1;
}
instance.say(data.channel, data.kickee + '-- (' + data.kickee + ' has been kicked ' + dbot.db.kicks[data.kickee] + ' times)');
}
dbot.save();
},
on: 'KICK'
};
};
exports.fetch = function(dbot) {
return kick(dbot);
};

View File

@ -1,10 +1,10 @@
var quotes = function(dbot) {
var qArrs = dbot.db.quoteArrs;
var quotes = dbot.db.quoteArrs;
return {
get: function(key) {
if(quotes.hasOwnProperty(key)) {
return key + ': ' + qArrs[key].random();
return key + ': ' + quotes[key].random();
} else {
return 'No quotes under ' + key;
}

22
reality.js Normal file
View File

@ -0,0 +1,22 @@
var reality = function(dbot) {
var dbot = dbot;
return {
'listener': function(data, params) {
if(data.user == 'reality') {
var once = data.message.match(/I ([\d\w\s]* once)/);
if(once != null) {
dbot.db.realiPuns.push('reality ' + once[1] + '.');
dbot.instance.say(data.channel, '\'reality ' + once[1] + '.\' saved.');
dbot.save();
}
}
},
'on': 'PRIVMSG'
};
}
exports.fetch = function(dbot) {
return reality(dbot);
}

52
run.js
View File

@ -4,6 +4,9 @@ var quote = require('./quotes');
var userCommands = require('./user');
var adminCommands = require('./admin');
var puns = require('./puns');
var kick = require('./kick');
var reality = require('./reality');
var karma = require('./karma');
///////////////////////////
@ -12,6 +15,7 @@ Array.prototype.random = function() {
};
///////////////////////////
var dbot = Class.create({
initialize: function(dModules, quotes) {
this.admin = 'reality';
@ -30,52 +34,6 @@ var dbot = Class.create({
return n.fetch(this);
}.bind(this));
this.instance.addListener('KICK', function(data) {
if(data.kickee == name) {
this.instance.join(data.channel);
this.instance.say(data.channel, 'Thou shalt not kick ' + name);
this.db.kicks[name] += 1;
} else {
if(this.db.kicks[data.kickee] == undefined) {
this.db.kicks[data.kickee] = 1;
} else {
this.db.kicks[data.kickee] += 1;
}
instance.say(data.channel, data.kickee + '-- (' + data.kickee + ' has been kicked ' + this.db.kicks[data.kickee] + ' times)');
}
this.save();
});
this.instance.addListener('PRIVMSG', function(data) {
if(data.user == 'aisbot' && data.channel == name && waitingForKarma != false && data.message.match(/is at/)) {
var split = data.message.split(' ');
var target = split[0];
var karma = split[3];
if(karma.startsWith('-')) {
this.instance.say(waitingForKarma, target + this.db.hatedPhrases.random() + ' (' + karma + ')');
} else if(karma == '0') {
this.instance.say(waitingForKarma, target + this.db.neutralPhrases.random() + ' (0)');
} else {
this.instance.say(waitingForKarma, target + this.db.lovedPhrases.random() + ' (' + karma + ')');
}
waitingForKarma = false;
}
});
this.instance.addListener('PRIVMSG', function(data) {
if(data.user == 'reality') {
var once = data.message.match(/I ([\d\w\s]* once.)/);
if(once != null) {
this.db.realiPuns.push('reality ' + once[1]);
this.instance.say(data.channel, '\'reality ' + once[1] + '\' saved.');
this.save();
}
}
});
this.instance.connect();
},
@ -88,4 +46,4 @@ var dbot = Class.create({
}
});
new dbot([userCommands, adminCommands, puns], quote);
new dbot([userCommands, adminCommands, puns, kick, reality, karma], quote);