Permalink
Browse files

[refactor] Access rank names and order are now configurable, as is th…

…e list of child hooks to spawn.
  • Loading branch information...
AvianFlu committed Oct 25, 2011
1 parent d2091b8 commit 174b7da3643d5233e8077157b3f4de04a8116690
Showing with 11 additions and 16 deletions.
  1. +11 −16 lib/kohai.js
View
@@ -19,7 +19,7 @@ var Kohai = exports.Kohai = function (options) {
}
Hook.call(this);
var self = this;
- self.hooks = ['irc', 'twitter', 'mailer'];
+ self.hooks = self.config.get('children');
self.on('hook::ready', function () {
if ((process.getuid() === 0) && self.uid) {
process.setuid(self.uid);
@@ -29,6 +29,7 @@ var Kohai = exports.Kohai = function (options) {
});
listeners.init.call(self, null);
self.insults = self.config.get('insults');
+ self.ranks = self.config.get('ranks');
});
}
util.inherits(Kohai, Hook);
@@ -72,14 +73,13 @@ Kohai.prototype.checkAuth = function (data) {
var self = this,
access = self.config.get('access'),
inherit = false;
- if (data.admin || data.employee || data.friend) {
- // If the incoming message has a rank field already,
- // this message is likely hax and can GTFO.
- return false;
- }
- Object.getOwnPropertyNames(access).sort(function (a, b) {
- return rankOf(a) - rankOf(b);
- }).forEach(function (level) {
+ self.ranks.forEach(function (rank) {
+ // No message should have any rank fields prior to this function.
+ if (typeof data[rank] !== 'undefined') {
+ return false;
+ }
+ });
+ self.ranks.forEach(function (level) {
if (inherit) {
data[level] = true;
return;
@@ -91,14 +91,9 @@ Kohai.prototype.checkAuth = function (data) {
}
});
});
- function rankOf (x) {
- return {
- admin : 0,
- employee : 1,
- friend : 2
- }[x]
+ if (data.to === self.nick) {
+ return self._dispatchPM(data);
}
- if (data.to === self.nick) { return self._dispatchPM(data) }
return self._dispatcher(data);
}

0 comments on commit 174b7da

Please sign in to comment.