mirror of
https://github.com/reality/dbot.git
synced 2024-12-25 12:12:35 +01:00
Remove dependency on prototype.js. Not everything is tested so far though...
This commit is contained in:
parent
df61c97eb2
commit
3d843f6c96
@ -17,7 +17,6 @@ var adminCommands = function(dbot) {
|
|||||||
dbot.say(dbot.admin, 'Reloading DB.');
|
dbot.say(dbot.admin, 'Reloading DB.');
|
||||||
try {
|
try {
|
||||||
dbot.db = JSON.parse(fs.readFileSync('db.json', 'utf-8'));
|
dbot.db = JSON.parse(fs.readFileSync('db.json', 'utf-8'));
|
||||||
dbot.reloadModules();
|
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
dbot.say(dbot.admin, 'DB reload failed.');
|
dbot.say(dbot.admin, 'DB reload failed.');
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -6,14 +6,14 @@ var kick = function(dbot) {
|
|||||||
if(data.kickee == dbot.name) {
|
if(data.kickee == dbot.name) {
|
||||||
dbot.instance.join(data.channel); // TODO: make interface
|
dbot.instance.join(data.channel); // TODO: make interface
|
||||||
dbot.say(data.channel, 'Thou shalt not kick ' + dbot.name);
|
dbot.say(data.channel, 'Thou shalt not kick ' + dbot.name);
|
||||||
dbot.db.kicks[name] += 1;
|
dbot.db.kicks[dbot.name] += 1;
|
||||||
} else {
|
} else {
|
||||||
if(dbot.db.kicks.hasOwnProperty(data.kickee)) {
|
if(!dbot.db.kicks.hasOwnProperty(data.kickee)) {
|
||||||
dbot.db.kicks[data.kickee] = 1;
|
dbot.db.kicks[data.kickee] = 1;
|
||||||
} else {
|
} else {
|
||||||
dbot.db.kicks[data.kickee] += 1;
|
dbot.db.kicks[data.kickee] += 1;
|
||||||
}
|
}
|
||||||
instance.say(data.channel, data.kickee + '-- (' + data.kickee + ' has been kicked ' + dbot.db.kicks[data.kickee] + ' times)');
|
dbot.say(data.channel, data.kickee + '-- (' + data.kickee + ' has been kicked ' + dbot.db.kicks[data.kickee] + ' times)');
|
||||||
}
|
}
|
||||||
|
|
||||||
dbot.save();
|
dbot.save();
|
||||||
|
@ -51,7 +51,7 @@ var userCommands = function(dbot) {
|
|||||||
},
|
},
|
||||||
|
|
||||||
'~kickcount': function(data, params) {
|
'~kickcount': function(data, params) {
|
||||||
if(dbot.db.kicks.hasOwnProperty(params[1])) {
|
if(!dbot.db.kicks.hasOwnProperty(params[1])) {
|
||||||
dbot.say(data.channel, params[1] + ' has either never been kicked or does not exist.');
|
dbot.say(data.channel, params[1] + ' has either never been kicked or does not exist.');
|
||||||
} else {
|
} else {
|
||||||
dbot.say(data.channel, params[1] + ' has been kicked ' + dbot.db.kicks[params[1]] + ' times.');
|
dbot.say(data.channel, params[1] + ' has been kicked ' + dbot.db.kicks[params[1]] + ' times.');
|
||||||
|
23
run.js
23
run.js
@ -1,12 +1,10 @@
|
|||||||
require('./snippets');
|
require('./snippets');
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
var jsbot = require('./jsbot');
|
var jsbot = require('./jsbot');
|
||||||
//var quote = require('./modules/quotes');
|
|
||||||
|
|
||||||
var modules = ['user', 'admin', 'puns', 'kick', 'reality', 'karma'];
|
var modules = ['user', 'admin', 'puns', 'kick', 'reality', 'karma'];
|
||||||
|
|
||||||
var dbot = Class.create({
|
var DBot = function(dModules, quotes) {
|
||||||
initialize: function(dModules, quotes) {
|
|
||||||
this.admin = 'reality';
|
this.admin = 'reality';
|
||||||
this.waitingForKarma = false;
|
this.waitingForKarma = false;
|
||||||
this.name = 'depressionbot';
|
this.name = 'depressionbot';
|
||||||
@ -26,19 +24,17 @@ var dbot = Class.create({
|
|||||||
this.reloadModules();
|
this.reloadModules();
|
||||||
|
|
||||||
this.instance.connect();
|
this.instance.connect();
|
||||||
},
|
};
|
||||||
|
|
||||||
say: function(channel, data) {
|
DBot.prototype.say = function(channel, data) {
|
||||||
this.instance.say(channel, data);
|
this.instance.say(channel, data);
|
||||||
},
|
};
|
||||||
|
|
||||||
save: function() {
|
DBot.prototype.save = function() {
|
||||||
fs.writeFile('db.json', JSON.stringify(this.db, null, ' '));
|
fs.writeFile('db.json', JSON.stringify(this.db, null, ' '));
|
||||||
},
|
};
|
||||||
|
|
||||||
reloadModules: function() {
|
|
||||||
require.cache = {}; // Stupid bloody prototype.js
|
|
||||||
|
|
||||||
|
DBot.prototype.reloadModules = function() {
|
||||||
this.rawModules = [];
|
this.rawModules = [];
|
||||||
this.modules = [];
|
this.modules = [];
|
||||||
|
|
||||||
@ -53,7 +49,6 @@ var dbot = Class.create({
|
|||||||
this.instance.addListener(module.on, module.listener);
|
this.instance.addListener(module.on, module.listener);
|
||||||
return module;
|
return module;
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
}
|
};
|
||||||
});
|
|
||||||
|
|
||||||
new dbot(modules, './modules/quotes');
|
new DBot(modules, './modules/quotes');
|
||||||
|
43
snippets.js
43
snippets.js
@ -1,3 +1,46 @@
|
|||||||
Array.prototype.random = function() {
|
Array.prototype.random = function() {
|
||||||
return this[Math.floor((Math.random()*this.length))];
|
return this[Math.floor((Math.random()*this.length))];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Array.prototype.each = function(fun) {
|
||||||
|
for(var i=0;i<this.length;i++) {
|
||||||
|
fun(this[i]);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Array.prototype.collect = function(fun) {
|
||||||
|
var collect = [];
|
||||||
|
for(var i=0;i<this.length;i++) {
|
||||||
|
collect.push(fun(this[i]));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/*** String ***/
|
||||||
|
|
||||||
|
String.prototype.endsWith = function(needle) {
|
||||||
|
var end = this.slice(this.length - needle.length);
|
||||||
|
if(needle === end) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
String.prototype.startsWith = function(needle) {
|
||||||
|
var start = this.slice(0, this.length - needle.length);
|
||||||
|
if(needle === start) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/*** Object ***/
|
||||||
|
|
||||||
|
Object.prototype.isFunction = function(obj) {
|
||||||
|
if(typeof(obj) == 'function') {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user