3
0
mirror of https://github.com/reality/dbot.git synced 2024-12-25 04:02:39 +01:00

Chance in in snippets, valMatch. Reload snippets file. Change youare.

This commit is contained in:
Luke Slater 2011-08-25 17:54:59 +01:00
parent 7c023104e3
commit 6072cb0e8b
4 changed files with 29 additions and 4 deletions

View File

@ -34,7 +34,7 @@ var adminCommands = function(dbot) {
'unload': function(data, params) { 'unload': function(data, params) {
console.log(dbot.moduleNames); console.log(dbot.moduleNames);
if(dbot.moduleNames.include(params[1])) { if(dbot.moduleNames.include(params[1])) {
dbot.moduleNames[params[1]] = null; dbot.moduleNames[params[1]] = undefined;
dbot.reloadModules(); dbot.reloadModules();
dbot.say(data.channel, 'Turned off module: ' + params[1]); dbot.say(data.channel, 'Turned off module: ' + params[1]);
} else { } else {

View File

@ -3,10 +3,9 @@ var youAre = function(dbot) {
return { return {
'listener': function(data) { 'listener': function(data) {
var num = Math.floor(Math.random()*4); var key = data.message.valMatch(/(is|are) ([\d\w\s']*)/, 3);
var key = data.message.match(/(is|are) ([\d\w\s']*)/);
if(num == 1 && key != undefined) { if(Number.prototype.chanceIn(1, 3) && key) {
if(key[2].indexOf('and') !== -1) { if(key[2].indexOf('and') !== -1) {
key[2] = key[2].split('and')[0]; key[2] = key[2].split('and')[0];
} // TODO: fix the regex to do this. i hate regex } // TODO: fix the regex to do this. i hate regex

5
run.js
View File

@ -35,6 +35,11 @@ DBot.prototype.reloadModules = function() {
this.rawModules = []; this.rawModules = [];
this.modules = []; this.modules = [];
// Reload snippets
var path = require.resolve('./snippets');
require.cache[path] = undefined;
require('./snippets');
this.moduleNames.each(function(name) { this.moduleNames.each(function(name) {
var cacheKey = require.resolve('./modules/' + name); var cacheKey = require.resolve('./modules/' + name);
require.cache[cacheKey] = undefined; // TODO: snippet to remove element properly require.cache[cacheKey] = undefined; // TODO: snippet to remove element properly

View File

@ -29,6 +29,15 @@ Array.prototype.include = function(value) {
/*** String ***/ /*** String ***/
String.prototype.valMatch = function(regex, expLength) {
var key = this.match(regex);
if(key !== null && key.length == expLength) {
return key;
} else {
return false;
}
};
String.prototype.endsWith = function(needle) { String.prototype.endsWith = function(needle) {
var end = this.slice(this.length - needle.length); var end = this.slice(this.length - needle.length);
if(needle === end) { if(needle === end) {
@ -64,3 +73,15 @@ Object.prototype.isArray = function(obj) {
return false; return false;
} }
}; };
/*** Integer ***/
Number.prototype.chanceIn = function(x, y) {
var num = Math.floor(Math.random() * (y + 1)) / x;
console.log(num);
if(num == 1) {
return true;
} else {
return false;
}
};