Permalink
Browse files

[fix] Fixes for Nodejitsu JShint compliance.

  • Loading branch information...
1 parent 6585bee commit 82ac1e45538047f96255b7c8e1559e321a8cd7d3 @AvianFlu AvianFlu committed Oct 28, 2011
Showing with 176 additions and 146 deletions.
  1. +12 −12 lib/channel.js
  2. +17 −19 lib/comments.js
  3. +23 −22 lib/kohai.js
  4. +38 −35 lib/listeners.js
  5. +86 −58 lib/triggers.js
View
@@ -10,25 +10,25 @@ var Channel = exports.Channel = function (options) {
for (var o in options) {
this[o] = options[o];
}
-}
+};
Channel.prototype.part = function () {
this.active = false;
-}
+};
Channel.prototype.join = function () {
this.active = true;
-}
+};
Channel.prototype.startVolume = function () {
this._ircRate();
this._twitRate();
-}
+};
Channel.prototype.stopVolume = function () {
clearInterval(this.ircInterval);
clearInterval(this.twitInterval);
-}
+};
Channel.prototype.config = function (key, value) {
if (typeof value === 'undefined') {
@@ -41,7 +41,7 @@ Channel.prototype.config = function (key, value) {
else {
return false;
}
-}
+};
Channel.prototype._ircRate = function () {
var self = this,
@@ -63,7 +63,7 @@ Channel.prototype._ircRate = function () {
self._volumetrics();
}, 1000);
-}
+};
Channel.prototype._volumetrics = function () {
var self = this;
@@ -73,18 +73,18 @@ Channel.prototype._volumetrics = function () {
self.rate = 10;
}
if ((self.volume < 0) || (typeof self.volume === 'undefined')) {
- self.volume = 0;
+ self.volume = 0;
}
if ((10 - self.rate) <= self.volume) {
self.volume = 10 - self.rate;
- self.lastVolume = self.volume;
+ self.lastVolume = self.volume;
}
else if ((10 - self.rate) > self.volume) {
- self.lastVolume += self.lastVolume +0.05;
+ self.lastVolume += self.lastVolume + 0.05;
self.volume = Math.round(self.lastVolume);
}
}
-}
+};
Channel.prototype._twitRate = function () {
var self = this;
@@ -94,6 +94,6 @@ Channel.prototype._twitRate = function () {
self.currentTweetCount--;
}
}, self.twitPeriod * 1000);
-}
+};
View
@@ -7,23 +7,21 @@
*/
var comments = module.exports = function (data) {
-
- switch(true) {
- case /\bkohai\b.*\bbot\b.*/i.test(data.text):
- this.emit('sendMsg', {
- dest: data.to,
- msg: '\'Bot\' is a derogatory term, and I\'m offended.'
- });
- break;
- case /.*\bkohai:(?:\s|$).*/i.test(data.text):
- this.emit('sendMsg', {
- dest: data.to,
- msg: 'I am Kohai, semi-useful communications-facilitating pseudointelligence!'
- });
- break;
- default:
- // This is the no-match case, do nothing.
- break;
+ switch (true) {
+ case /\bkohai\b[\w\s\d]*\bbot\b[\w\s\d]*/i.test(data.text):
+ this.emit('sendMsg', {
+ dest: data.to,
+ msg: '\'Bot\' is a derogatory term, and I\'m offended.'
+ });
+ break;
+ case /[\w\s\d]*\bkohai:(?:\s|$)[\w\s\d]*/i.test(data.text):
+ this.emit('sendMsg', {
+ dest: data.to,
+ msg: 'I am Kohai, semi-useful communications-facilitating pseudointelligence!'
+ });
+ break;
+ default:
+ // This is the no-match case, do nothing.
+ break;
}
-
-}
+};
View
@@ -14,11 +14,11 @@ var Hook = require('hook.io').Hook,
comments = require('./comments');
var Kohai = exports.Kohai = function (options) {
- for (var o in options) {
+ var self = this;
+ options.forEach(function (o) {
this[o] = options[o];
- }
+ });
Hook.call(this);
- var self = this;
self.hooks = self.config.get('children');
self.on('hook::ready', function () {
if ((process.getuid() === 0) && self.uid) {
@@ -31,7 +31,7 @@ var Kohai = exports.Kohai = function (options) {
self.insults = self.config.get('insults');
self.ranks = self.config.get('ranks');
});
-}
+};
util.inherits(Kohai, Hook);
Kohai.prototype.joinChannel = function (channel) {
@@ -48,26 +48,27 @@ Kohai.prototype.joinChannel = function (channel) {
if (self.channels[channel].autoVolume) {
self.channels[channel].startVolume();
}
-}
+};
Kohai.prototype.gotMessage = function (data) {
var idCheck = this.idCheck ? '\\+' : '',
- trigger = new RegExp('^'
- + idCheck
+ command,
+ trigger = new RegExp('^'
+ + idCheck
+ this.channels[data.to].commandString
+ '\\w+\\s?\\w*.*');
this.channels[data.to].messageCount++;
if (trigger.test(data.text)) {
this.checkAuth(data);
}
else if (/^-!?(help|support)/.test(data.text)) {
- var command = data.text.replace(/-!/, '').split(' ');
+ command = data.text.replace(/-!/, '').split(' ');
triggers[command[0]].call(this, data, command);
}
else {
this.checkComment(data);
}
-}
+};
Kohai.prototype.checkAuth = function (data) {
var self = this,
@@ -79,8 +80,8 @@ Kohai.prototype.checkAuth = function (data) {
return false;
}
});
- self.ranks.forEach(function (level) {
- if (inherit) {
+ self.ranks.forEach(function (level) {
+ if (inherit) {
data[level] = true;
return;
}
@@ -91,25 +92,25 @@ Kohai.prototype.checkAuth = function (data) {
}
});
});
- if (data.to === self.nick) {
+ if (data.to === self.nick) {
return self._dispatchPM(data);
}
return self._dispatcher(data);
-}
+};
Kohai.prototype._dispatcher = function (data) {
var self = this,
- replace = self.idCheck
- ? '+' + self.channels[data.to].commandString
+ replace = self.idCheck
+ ? '+' + self.channels[data.to].commandString
: self.channels[data.to].commandString,
command = data.text.replace(replace, '').split(' ');
- if ((command[0] !== 'config')&&(typeof triggers[command[0]] !== 'undefined')) {
+ if ((command[0] !== 'config') && (typeof triggers[command[0]] !== 'undefined')) {
triggers[command[0]].call(self, data, command);
}
-}
+};
Kohai.prototype._dispatchPM = function (data) {
- var config = /^config\s(add|rm|set|get|save)\s?([\w\d#:._-]*)\s?(.*)$/,
+ var config = /^config\s(add|rm|set|get|save)\s?([\w\d#:\._\-]*)\s?([\w\d\s!:\/\.,&\(\)]*)$/,
text = data.text.replace(/^\+!?/, ''),
command;
if (!config.test(text)) {
@@ -122,15 +123,15 @@ Kohai.prototype._dispatchPM = function (data) {
triggers[command[0]].call(this, data, command);
}
}
- else if (data.admin) {
+ else if (data.admin) {
command = text.match(config);
triggers.config.call(this, data.nick, command[1], command[2], command[3]);
}
-}
+};
Kohai.prototype.checkComment = function (data) {
comments.call(this, data);
-}
+};
Kohai.prototype.sayTweet = function (data) {
var self = this;
@@ -142,5 +143,5 @@ Kohai.prototype.sayTweet = function (data) {
}
}
});
-}
+};
View
@@ -4,6 +4,41 @@ var fs = require('fs');
var listeners = exports;
+function _lazyLoad() {
+ var self = this;
+ fs.readdirSync(__dirname + '/listeners').forEach(function (listener) {
+ var mod;
+ if (/^[\w\d\s]\.js$/.test(listener)) {
+ listener = listener.replace('.js', '');
+ try {
+ mod = require(__dirname + '/listeners/' + listener);
+ switch (typeof mod) {
+ case 'function':
+ mod.call(self);
+ break;
+ case 'object':
+ Object.getOwnPropertyNames(mod).forEach(function (item) {
+ if (typeof mod[item] === 'function') {
+ mod[item].call(self);
+ }
+ else {
+ console.log('Cannot load non-function as event listener: %s.%s', listener, item);
+ }
+ });
+ break;
+ default:
+ console.log('Cannot load non-functions as event listeners.');
+ break;
+ }
+ }
+ catch (err) {
+ console.log('Listener plugin \'%s\' was not loaded due to error: %s', listener, err.message);
+ }
+ }
+ });
+}
+
+
listeners.init = function () {
var self = this;
@@ -41,7 +76,7 @@ listeners.init = function () {
self.on('*::Iparted', function (data) {
if (typeof self.channels[data] !== 'undefined') {
self.channels[data].part();
- self.channels = self.channels.filter( function (item) {
+ self.channels = self.channels.filter(function (item) {
return item !== data;
});
}
@@ -52,38 +87,6 @@ listeners.init = function () {
});
_lazyLoad.call(self);
-}
+};
+
-function _lazyLoad() {
- var self = this;
- fs.readdirSync(__dirname + '/listeners').forEach(function (listener) {
- var mod;
- if (/^.*\.js$/.test(listener)) {
- listener = listener.replace('.js', '');
- try {
- var mod = require(__dirname + '/listeners/' + listener);
- switch(typeof mod) {
- case 'function':
- mod.call(self);
- break;
- case 'object':
- Object.getOwnPropertyNames(mod).forEach(function (item) {
- if (typeof mod[item] === 'function') {
- mod[item].call(self);
- }
- else {
- console.log('Cannot load non-function as event listener: %s.%s', listener, item);
- }
- });
- break;
- default:
- console.log('Cannot load non-functions as event listeners.');
- break;
- }
- }
- catch (err) {
- console.log('Listener plugin \'%s\' was not loaded due to error: %s', listener, err.message);
- }
- }
- });
-}
Oops, something went wrong.

0 comments on commit 82ac1e4

Please sign in to comment.