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) {
console.log(dbot.moduleNames);
if(dbot.moduleNames.include(params[1])) {
dbot.moduleNames[params[1]] = null;
dbot.moduleNames[params[1]] = undefined;
dbot.reloadModules();
dbot.say(data.channel, 'Turned off module: ' + params[1]);
} else {

View File

@ -3,10 +3,9 @@ var youAre = function(dbot) {
return {
'listener': function(data) {
var num = Math.floor(Math.random()*4);
var key = data.message.match(/(is|are) ([\d\w\s']*)/);
var key = data.message.valMatch(/(is|are) ([\d\w\s']*)/, 3);
if(num == 1 && key != undefined) {
if(Number.prototype.chanceIn(1, 3) && key) {
if(key[2].indexOf('and') !== -1) {
key[2] = key[2].split('and')[0];
} // 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.modules = [];
// Reload snippets
var path = require.resolve('./snippets');
require.cache[path] = undefined;
require('./snippets');
this.moduleNames.each(function(name) {
var cacheKey = require.resolve('./modules/' + name);
require.cache[cacheKey] = undefined; // TODO: snippet to remove element properly

View File

@ -29,6 +29,15 @@ Array.prototype.include = function(value) {
/*** 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) {
var end = this.slice(this.length - needle.length);
if(needle === end) {
@ -64,3 +73,15 @@ Object.prototype.isArray = function(obj) {
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;
}
};