This repository has been archived by the owner on Dec 21, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check nickserv for user's ident status.
- Loading branch information
Showing
3 changed files
with
84 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,56 @@ | |||
var events = require('events'); | |||
var _ = require('underscore'); | |||
|
|||
|
|||
this.AuthManager = function() { | |||
this.neededLevel = 2; | |||
this.STATUSRE = /^STATUS ([^ ]+) (\d)$/; | |||
this.users = {}; | |||
}; | |||
|
|||
this.AuthManager.prototype._user = function(nick) { | |||
this.users[nick] = _.extend({}, { | |||
auth: null, | |||
emitter: new events.EventEmitter() | |||
}, this.users[nick]); | |||
|
|||
return this.users[nick]; | |||
}; | |||
|
|||
this.AuthManager.prototype.notice = function(nick, message) { | |||
if (nick !== 'nickserv') { | |||
return; | |||
} | |||
var match = this.STATUSRE.exec(message); | |||
if (match) { | |||
var user_nick = match[1]; | |||
var level = match[2]; | |||
var user = this._user(user_nick); | |||
|
|||
if (level >= this.neededLevel) { | |||
user.auth = true; | |||
user.emitter.emit('authorized'); | |||
} else { | |||
user.auth = false; | |||
user.emitter.emit('unauthorized'); | |||
} | |||
} | |||
}; | |||
|
|||
this.AuthManager.prototype.checkUser = function(nick) { | |||
var self = this; | |||
var user = this._user(nick); | |||
process.nextTick(function() { | |||
if (user.auth) { | |||
user.emitter.emit('authorized'); | |||
} else { | |||
self._askNickserv(nick); | |||
} | |||
}); | |||
return user.emitter; | |||
} | |||
|
|||
this.AuthManager.prototype._askNickserv = function(nick) { | |||
var msg = 'status ' + nick; | |||
client.say('nickserv', msg); | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters