From 4bf34185ec02226f186da429ca4f7d8cb666499f Mon Sep 17 00:00:00 2001 From: Billy Rhoades Date: Sat, 18 Nov 2017 15:38:50 -0600 Subject: [PATCH] Made nickserv less async (fixes #95). Changed arrow func to function for logging. Now using regex for nickserv success message tests. --- conf/nickserv.example.json | 4 ++- modules/nickserv.js | 65 ++++++++++++++++++++++++-------------- 2 files changed, 44 insertions(+), 25 deletions(-) diff --git a/conf/nickserv.example.json b/conf/nickserv.example.json index 3c59ab2..19f781d 100644 --- a/conf/nickserv.example.json +++ b/conf/nickserv.example.json @@ -1,3 +1,5 @@ { - "password" : "dicks" + "nickserv": "nickserv", + "password" : "dicks", + "successtext": "^You are now identified for " } diff --git a/modules/nickserv.js b/modules/nickserv.js index e702b58..8fc0363 100644 --- a/modules/nickserv.js +++ b/modules/nickserv.js @@ -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 "); - 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 '); + return; + } + + bot.sayTo(config.nickserv || 'nickserv', 'register', config.password, parts[0]); + reply('Registered!'); +};