forked from GitHub/dbot
Chance in in snippets, valMatch. Reload snippets file. Change youare.
This commit is contained in:
parent
7c023104e3
commit
6072cb0e8b
@ -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 {
|
||||
|
@ -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
5
run.js
@ -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
|
||||
|
21
snippets.js
21
snippets.js
@ -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;
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user