Skip to content

Commit

Permalink
module/nickserv: Made nickserv less async (fixes #95). (#172)
Browse files Browse the repository at this point in the history
Changed arrow func to function for logging.

Now using regex for nickserv success message tests.
  • Loading branch information
brhoades authored and LinuxMercedes committed Nov 19, 2017
1 parent 3117144 commit 5a84066
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 25 deletions.
4 changes: 3 additions & 1 deletion conf/nickserv.example.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{
"password" : "dicks"
"nickserv": "nickserv",
"password" : "dicks",
"successtext": "^You are now identified for "
}
65 changes: 41 additions & 24 deletions modules/nickserv.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,48 @@
var config = null;
var bot = null;
let config = null;
let bot = null;
let log = null;

module.exports.init = function(b) {
bot = b;
// Only respond to a nickserv notice once.
let identified = false;

bot.getConfig('nickserv.json', function(err, conf) {
console.log(err);
if(err) return;
module.exports.init = function (b) {
bot = b;
log = this.log;

config = conf;
bot.getConfig('nickserv.json', (err, conf) => {
if (err) {
log.error(err);
return;
}

bot.sayTo(config.nickserv || 'nickserv', 'identify', bot.client.nick, config.password);
});
}
config = conf;

module.exports.run_register = function(r, parts, reply) {
console.log(config);
if(config === null) {
reply("Please configure a password");
return;
}
bot.sayTo(config.nickserv || 'nickserv', 'identify', bot.client.nick, config.password);
});
};

if(parts.length < 1) {
reply("Usage: !register <email address>");
return;
}
module.exports.pmnotice = (text, from) => {
const nickServText = config.nickservsuccess || '^You are now identified for ';

bot.sayTo(config.nickserv || 'nickserv', 'register', config.password, parts[0]);
reply("Registered!");
}
if (!identified && from.toLowerCase() === (config.nickserv || 'nickserv')
&& new RegExp(nickServText, 'i').test(text)) {
bot.joinChannels();
identified = true;
log.info('Identified with nickserv, rejoining channels.');
}
};

module.exports.run_register = (r, parts, reply) => {
if (config === null) {
reply('Please configure a password');
return;
}

if (parts.length < 1) {
reply('Usage: !register <email address>');
return;
}

bot.sayTo(config.nickserv || 'nickserv', 'register', config.password, parts[0]);
reply('Registered!');
};

0 comments on commit 5a84066

Please sign in to comment.