From b950426d7b0f542658ea7f05fd5adcba2c0a2b06 Mon Sep 17 00:00:00 2001 From: reality Date: Thu, 4 Sep 2014 08:27:46 +0000 Subject: [PATCH 01/54] well, there's a start --- modules/users/newapi.js | 65 +++++++++++++++++++++++++ modules/users/newcommands.js | 66 +++++++++++++++++++++++++ modules/users/newusers.js | 94 ++++++++++++++++++++++++++++++++++++ 3 files changed, 225 insertions(+) create mode 100644 modules/users/newapi.js create mode 100644 modules/users/newcommands.js create mode 100644 modules/users/newusers.js diff --git a/modules/users/newapi.js b/modules/users/newapi.js new file mode 100644 index 0000000..86f48be --- /dev/null +++ b/modules/users/newapi.js @@ -0,0 +1,65 @@ +var _ = require('underscore')._; + +var api = function(dbot) { + this.api = { + // Retrieve a user record given a server and nickname + 'resolveUser': function(server, nick, callback) { + var id = nick + '.' + server; + this.api.getUser(id, function(err, result) { + if(!err) { + callback(null, result); + } else { + this.db.read('user_aliases', id, function(err, result) { + if(!err) { + this.api.getUser(result.user, callback); + } else { + callback(true, null); + } + }.bind(this)); + } + }.bind(this)); + }, + + // Retrive a user record given its ID + 'getUser': function(id, callback) { + this.db.read('users', id, function(err, result) { + if(!err) { + callback(null, result); + } else { + callback(true, null); + } + }); + }, + + // Retrieve user aliases given a user ID + 'getUserAliases': function(id, callback) { + var aliases = []; + this.db.search('user_aliases', { 'user': id }, function(result) { + aliases.push(result.alias); + }, function(err) { + if(!err) { + callback(null, aliases); + } else { + callback(true, null); + } + }); + }, + + // Retrieve a channel record given a server and a channel name + 'resolveChannel': function(server, channel, callback) { + var id = channel + '.' + server; + this.api.getChannel(id, callback); + }, + + // Retrieve a channel record given its ID + 'getChannel': function(id, callback) { + this.db.read('channels', id, function(err, result) { + if(!err) { + callback(null, result); + } else { + callback(true, null); + } + }); + } + }; +}; diff --git a/modules/users/newcommands.js b/modules/users/newcommands.js new file mode 100644 index 0000000..b4ca3da --- /dev/null +++ b/modules/users/newcommands.js @@ -0,0 +1,66 @@ +var _ = require('underscore')._; + +var commands = function(dbot) { + this.commands = { + '~alias': function(event) { + var nick = event.input[1] || event.user; + this.api.resolveUser(event.server, nick, function(err, user) { + if(user) { + this.api.getUserAliases(user.id, function(err, aliases) { + var including = _.first(aliases, 10).join(', '); + + if(nick === user.primaryNick) { + if(aliases.length === 0) { + event.reply(dbot.t('primary_no_alias', { + 'user': user.primaryNick, + 'currentNick': user.currentNick + })); + } else { + event.reply(dbot.t('primary', { + 'user': user.primaryNick, + 'currentNick': user.currentNick, + 'count': aliases.length, + 'including': including + })); + } + } else { + event.reply(dbot.t('alias', { + 'alias': nick, + 'user': user.primaryNick + })); + } + }); + } else { + event.reply(dbot.t('unknown_alias', { 'alias': nick })); + } + }.bind(this)); + }, + + '~addalias': function(event) { + var nick = event.input[1], + alias = event.input[2]; + + this.api.resolveUser(event.server, nick, function(err, user) { + if(user) { + this.api.resolveUser(event.server, alias, function(err, aUser) { + if(!aUser) { + this.internalAPI.createAlias(alias, user, function(err) { + event.reply(dbot.t('alias_added', { + 'user': user.primaryNick, + 'alias': alias + })); + }); + } else { + event.reply(dbot.t('alias_exists', { + 'alias': alias, + 'user': aUser.primaryNick + })); + } + }); + } else { + event.reply(dbot.t('unknown_alias', { 'alias': nick })); + } + }.bind(this)); + } + }; +}; diff --git a/modules/users/newusers.js b/modules/users/newusers.js new file mode 100644 index 0000000..03603f1 --- /dev/null +++ b/modules/users/newusers.js @@ -0,0 +1,94 @@ +/** + * Name: Users + * Description: Track known users + */ +var _ = require('underscore')._; + +var users = function(dbot) { + /*** Internal API ***/ + + this.internalAPI = { + // Create new user record + 'createUser': function(server, nick, callback) { + var id = nick + '.' + server; + this.db.create('users', id, { + 'id': id, + 'server': server, + 'primaryNick': nick, + 'currentNick': nick + }, function(err, result) { + if(!err) { + dbot.api.event.emit('new_user', [ result ]); + callback(null, result); + } else { + callback(true, null); + } + }); + }, + + // Add new user alias + 'createAlias': function(alias, user, callback) { + var id = alias + '.' + user.server; + this.db.create('user_aliases', id, { + 'id': id, + 'alias': alias, + 'user': user.id + }, function(err, result) { + if(!err) { + dbot.api.event.emit('new_user_alias', [ event.rUser, event.newNick ]); + callback(null, result); + } else { + callback(true, null); + } + }); + }, + + 'updateCurrentNick': function(user, newNick, callback) { + user.currentNick = newNick; + this.db.save('users', user.id, user, function(err, result) { + if(!err) { + dbot.api.event.emit('new_current_nick', [ user, newNick ]); + callback(null, result); + } else { + callback(true, null); + } + }); + } + }; + + /*** Listener ***/ + + // Track nick changes + this.listener = function(event) { + // Update current nick + this.internalAPI.updateCurrentNick(event.rUser, event.newNick, function(){}); + + // Add new alias record if nick is not already claimed + this.api.resolveUser(event.server, event.newNick, function(err, user) { + if(!user) { + this.internalAPI.createAlias(event.newNick, event.rUser, function(){}); + } + }.bind(this)); + }.bind(this); + this.on = ['NICK']; + + /*** Pre-emit ***/ + this.onLoad = function() { + // Create non-existing users and update current nicks + var checkUser = function(done) { + this.api.resolveUser(event.server, event.user, function(err, user) { + if(!user) { + this.internalAPI.createUser(event.server, event.user, done); + } else { + this.internalAPI.updateCurrentNick(user, event.user, done); + } + }.bind(this)); + }; + + dbot.instance.addPreEmitHook(function(event, callback) { + if(event.user && _.include(['JOIN', 'PRIVMSG'], event.action)) { + checkUser(callback); + } + }); + }; +}; From be07c3629499162ea4cf3e66e2df3f2d867daea1 Mon Sep 17 00:00:00 2001 From: reality Date: Thu, 4 Sep 2014 09:30:22 +0000 Subject: [PATCH 02/54] tings --- modules/users/newcommands.js | 51 ++++++++++++++++++++++++++++++++-- modules/users/newusers.js | 54 ++++++++++++++++++++++++++++++++++-- 2 files changed, 99 insertions(+), 6 deletions(-) diff --git a/modules/users/newcommands.js b/modules/users/newcommands.js index b4ca3da..7f1e877 100644 --- a/modules/users/newcommands.js +++ b/modules/users/newcommands.js @@ -3,7 +3,7 @@ var _ = require('underscore')._; var commands = function(dbot) { this.commands = { '~alias': function(event) { - var nick = event.input[1] || event.user; + var nick = event.params[1] || event.user; this.api.resolveUser(event.server, nick, function(err, user) { if(user) { this.api.getUserAliases(user.id, function(err, aliases) { @@ -37,8 +37,8 @@ var commands = function(dbot) { }, '~addalias': function(event) { - var nick = event.input[1], - alias = event.input[2]; + var nick = event.params[1], + alias = event.params[2]; this.api.resolveUser(event.server, nick, function(err, user) { if(user) { @@ -61,6 +61,51 @@ var commands = function(dbot) { event.reply(dbot.t('unknown_alias', { 'alias': nick })); } }.bind(this)); + }, + + '~setaliasparent': function(event) { + var newPrimary = event.params[1]; + this.api.resolveUser(event.server, newPrimary, function(user) { + if(user) { + if(user.primaryNick !== newPrimary) { + this.internalAPI.reparentUser(user, newPrimary, function() { + event.reply(dbot.t('aliasparentset', { + 'newParent': newPrimary, + 'newAlias': user.primaryNick + })); + }); + } else { + event.reply(dbot.t('already_primary', { 'user': newPrimary })); + } + } else { + event.reply(dbot.t('unknown_alias', { 'alias': nick })); + } + }); + }, + + '~rmalias': function(event) { + var alias = event.params[1]; + + this.api.resolveUser(event.server, alias, function(err, user) { + if(user) { // Retrieving user record via alias proves existence of alias record + this.internalAPI.removeAlias(event.server, alias, function(err) { + event.reply(dbot.t('alias_removed', { + 'primary': user.primaryNick, + 'alias': alias + })); + }); + } else { + event.reply(dbot.t('unknown_alias', { 'alias': nick })); + } + }); } }; + this.commands['~setaliasparent'].access = 'moderator'; + this.commands['~addalias'].access = 'moderator'; + this.commands['~rmalias'].access = 'moderator'; + this.commands['~mergeusers'].access = 'moderator'; +}; + +exports.fetch = function(dbot) { + return commands(dbot); }; diff --git a/modules/users/newusers.js b/modules/users/newusers.js index 03603f1..382a00b 100644 --- a/modules/users/newusers.js +++ b/modules/users/newusers.js @@ -43,6 +43,15 @@ var users = function(dbot) { }); }, + // Remove an alias record + 'removeAlias': function(server, alias) { + var id = alias + '.' + server; + this.db.del('user_aliases', id, function(err) { + callback(err); + }); + }, + + // Update current nick of user record 'updateCurrentNick': function(user, newNick, callback) { user.currentNick = newNick; this.db.save('users', user.id, user, function(err, result) { @@ -53,6 +62,35 @@ var users = function(dbot) { callback(true, null); } }); + }, + + // Merge two user records and aliases + 'mergeUsers': function(oldUser, newUser, callback) { + this.db.search('user_aliases', { 'user': oldUser.id }, function(alias) { + alias.user = newUser.id; + this.db.save('user_aliases', alias.id, alias, function(){}); + }.bind(this), function(){}); + + this.db.del('users', oldUser.id, function(err) { + if(!err) { + dbot.api.event.emit('merged_users', [ + oldUser, + newUser + ]); + callback(null); + } else { + callback(true); + } + }); + }, + + // Set a new nick as the parent for a user (so just recreate and merge) + 'reparentUser': function(user, newPrimary, callback) { + this.internalAPI.createUser(user.server, newPrimary, function(err, newUser) { + this.internalAPI.mergeUsers(user, newUser, function(err) { + callback(err); + }); + }.bind(this)); } }; @@ -73,6 +111,7 @@ var users = function(dbot) { this.on = ['NICK']; /*** Pre-emit ***/ + this.onLoad = function() { // Create non-existing users and update current nicks var checkUser = function(done) { @@ -80,15 +119,24 @@ var users = function(dbot) { if(!user) { this.internalAPI.createUser(event.server, event.user, done); } else { - this.internalAPI.updateCurrentNick(user, event.user, done); + if(user.currentNick !== event.user) { + this.internalAPI.updateCurrentNick(user, event.user, done); + } else { + done(null, user); + } } }.bind(this)); }; dbot.instance.addPreEmitHook(function(event, callback) { if(event.user && _.include(['JOIN', 'PRIVMSG'], event.action)) { - checkUser(callback); + checkUser(function(err, user) { + event.rUser = user; + callback(null); + }); + } else { + callback(null); } }); - }; + }.bind(this); }; From 0a4240f3db8559f01dd1fd0ade28ee6a312e76de Mon Sep 17 00:00:00 2001 From: reality Date: Thu, 4 Sep 2014 09:36:57 +0000 Subject: [PATCH 03/54] replace users with new modules --- modules/users/api.js | 209 +++++++-------------------- modules/users/commands.js | 269 +++++++++++----------------------- modules/users/newapi.js | 65 --------- modules/users/newcommands.js | 111 -------------- modules/users/newusers.js | 142 ------------------ modules/users/users.js | 273 ++++++++++++----------------------- 6 files changed, 226 insertions(+), 843 deletions(-) delete mode 100644 modules/users/newapi.js delete mode 100644 modules/users/newcommands.js delete mode 100644 modules/users/newusers.js diff --git a/modules/users/api.js b/modules/users/api.js index 00ec82e..86f48be 100644 --- a/modules/users/api.js +++ b/modules/users/api.js @@ -1,172 +1,65 @@ -var _ = require('underscore')._, - uuid = require('node-uuid'), - databank = require('databank'); +var _ = require('underscore')._; var api = function(dbot) { - var escapeRegexen = function(str) { - return (str+'').replace(/([.?*+^$[\]\\(){}|-])/g, "\\$1"); - }; - - var api = { - // Return a user record given a primary nick or an alias - 'resolveUser': function(server, nick, callback, lc) { - var user = false; - if(lc) nick = nick.toLowerCase(); - if(_.has(this.userCache[server], nick)) { - this.api.getUser(this.userCache[server][nick], callback); - } else { - this.db.search('users', { 'server': server }, function(result) { - if(lc) { - result.primaryNick = result.primaryNick.toLowerCase(); - _.each(result.aliases, function(v, k) { - result.aliases[k] = v.toLowerCase(); - }); - } - - if(result.primaryNick == nick || _.include(result.aliases, nick)) { - user = result; - } - }.bind(this), function(err) { - if(user) { - if(!_.has(this.userCache[server], nick)) { - this.userCache[server][nick] = user.id; - } else if(this.userCache[server][nick] !== user.id) { - this.userCache[server][nick] = user.id; + this.api = { + // Retrieve a user record given a server and nickname + 'resolveUser': function(server, nick, callback) { + var id = nick + '.' + server; + this.api.getUser(id, function(err, result) { + if(!err) { + callback(null, result); + } else { + this.db.read('user_aliases', id, function(err, result) { + if(!err) { + this.api.getUser(result.user, callback); + } else { + callback(true, null); } - } - callback(user); - }.bind(this)); - } - }, - - // Return many user records given primary nicks of aliases - 'resolveUsers': function(server, nicks, callback) { - var users = []; - this.db.search('users', { 'server': server }, function(result) { - var pNicks = result.aliases.slice(0).unshift(result.primaryNick); - for(var i=0;i Date: Thu, 4 Sep 2014 09:51:39 +0000 Subject: [PATCH 04/54] add merge users command and fix up strings --- modules/users/api.js | 4 +++ modules/users/commands.js | 56 +++++++++++++++++++++++++++----------- modules/users/strings.json | 40 +++++++++++---------------- modules/users/users.js | 4 +++ 4 files changed, 64 insertions(+), 40 deletions(-) diff --git a/modules/users/api.js b/modules/users/api.js index 86f48be..1e25abb 100644 --- a/modules/users/api.js +++ b/modules/users/api.js @@ -63,3 +63,7 @@ var api = function(dbot) { } }; }; + +exports.fetch = function(dbot) { + return api(dbot); +}; diff --git a/modules/users/commands.js b/modules/users/commands.js index 7f1e877..82e2445 100644 --- a/modules/users/commands.js +++ b/modules/users/commands.js @@ -9,26 +9,26 @@ var commands = function(dbot) { this.api.getUserAliases(user.id, function(err, aliases) { var including = _.first(aliases, 10).join(', '); - if(nick === user.primaryNick) { - if(aliases.length === 0) { - event.reply(dbot.t('primary_no_alias', { - 'user': user.primaryNick, - 'currentNick': user.currentNick - })); - } else { - event.reply(dbot.t('primary', { - 'user': user.primaryNick, - 'currentNick': user.currentNick, - 'count': aliases.length, - 'including': including - })); - } - } else { + if(nick !== user.primaryNick) { event.reply(dbot.t('alias', { 'alias': nick, 'user': user.primaryNick })); } + + if(aliases.length === 0) { + event.reply(dbot.t('primary_no_alias', { + 'user': user.primaryNick, + 'currentNick': user.currentNick + })); + } else { + event.reply(dbot.t('primary', { + 'user': user.primaryNick, + 'currentNick': user.currentNick, + 'count': aliases.length, + 'including': including + })); + } }); } else { event.reply(dbot.t('unknown_alias', { 'alias': nick })); @@ -69,7 +69,7 @@ var commands = function(dbot) { if(user) { if(user.primaryNick !== newPrimary) { this.internalAPI.reparentUser(user, newPrimary, function() { - event.reply(dbot.t('aliasparentset', { + event.reply(dbot.t('alias_parent_set', { 'newParent': newPrimary, 'newAlias': user.primaryNick })); @@ -98,6 +98,30 @@ var commands = function(dbot) { event.reply(dbot.t('unknown_alias', { 'alias': nick })); } }); + }, + + '~mergeusers': function(event) { + var oldNick = event.params[1], + newNick = event.params[2]; + + this.api.resolveUser(event.server, oldNick, function(err, oldUser) { + if(oldUser) { + this.api.resolveUser(event.server, newNick, function(err, newUser) { + if(newUser) { + this.internalAPI.mergeUsers(oldUser, newUser, function() { + event.reply(dbot.t('merged_users', { + 'old_user': secondaryUser, + 'new_user': primaryUser + })); + }); + } else { + event.reply(dbot.t('unknown_alias', { 'alias': newNick })); + } + }.bind(this)); + } else { + event.reply(dbot.t('unknown_alias', { 'alias': oldNick })); + } + }.bind(this)); } }; this.commands['~setaliasparent'].access = 'moderator'; diff --git a/modules/users/strings.json b/modules/users/strings.json index 1a95747..a6b43fa 100644 --- a/modules/users/strings.json +++ b/modules/users/strings.json @@ -8,22 +8,23 @@ "fr": "{alias} est un alias de {user}", "it": "{alias} è un alias di {user}" }, - "added_mobile_alias": { - "en": "{alias} added as a mobile alias.", - "de": "{alias} als mobiler Benutzer hinzugefügt." - }, - "already_mobile": { - "en": "{alias} is already a mobile alias.", - "de": "{alias} ist bereits ein mobiler Benutzer." - }, "primary": { - "en": "{user} (currently {currentNick}) is a primary user with {count} aliases, ", - "na'vi": "{user} ({currentNick}) lu txin ulte {count}a stxo lu poru, ", - "nl": "{user} ({currentNick}) is een primaire gebruiker met {count} aliassen, ", + "en": "{user} (currently {currentNick}) is a primary user with {count} aliases, including {including}.", + "na'vi": "{user} ({currentNick}) lu txin ulte {count}a stxo lu poru, {including}", + "nl": "{user} ({currentNick}) is een primaire gebruiker met {count} aliassen, {including}", "cy": "Mae {user} ({currentNick}) yn ddefnyddiwr gynradd gyda {count} enwau eraill, ", - "de": "{user} ({currentNick}) ist ein Benutzer mit {count} Nicknamen, ", - "fr": "{user} (actuellement {currentNick}) est un utilisateur primaire avec {count} alias, ", - "it": "{user} (attualmente {currentNick}) è un utente primario con {count} alias, " + "de": "{user} ({currentNick}) ist ein Benutzer mit {count} Nicknamen, {including}", + "fr": "{user} (actuellement {currentNick}) est un utilisateur primaire avec {count} alias, {including}", + "it": "{user} (attualmente {currentNick}) è un utente primario con{count} alias, {including}" + }, + "primary_no_alias": { + "en": "{user} (currently {currentNick}) is a primary user.", + "na'vi": "{user} ({currentNick}) lu txin ulte", + "nl": "{user} ({currentNick}) is een primaire gebruiker", + "cy": "Mae {user} ({currentNick}) yn ddefnyddiwr gynradd", + "de": "{user} ({currentNick}) ist ein Benutzer", + "fr": "{user} (actuellement {currentNick}) est un utilisateur primaire", + "it": "{user} (attualmente {currentNick}) è un utente primario" }, "unknown_alias": { "en": "{alias} does not currently exist as an alias or known user.", @@ -39,7 +40,7 @@ "de": "Alias {alias} von {primary} entfernt.", "it": "Tolto alias {alias} da {primary}." }, - "aliasparentset": { + "alias_parent_set": { "en": "{newParent} is now the parent user, and {newAlias} is an alias.", "na'vi": "{newParent} lu sa'sem set ulte {newAlias} lu stxo set nìteng.", "cy": "Mae {newParent} ydy defnyddiwr rhiant nawr, a {alias} ydy enw arall.", @@ -48,15 +49,6 @@ "fr": "{newParent} est maintenant le même utilisateur parent, et {newAlias} est un alias.", "it": "{newParent} è adesso l' utente genitore e {newAlias} è un alias." }, - "unprimary_error": { - "en": "{nick} isn't recorded as a primary user.", - "na'vi": "fo sute txin ke lu.", - "cy": "Nid yw un o'r defnyddwyr hynny yn cael ei gofnodi ar hyn o bryd fel defnyddiwr gynradd.", - "nl": "Een van deze gebruikers is nog niet bekend als een primaire gebruiker.", - "de": "Einer dieser Benutzer ist nicht als Hauptbenutzer gespeichert.", - "fr": "{nick} n'est pas enregistré en tant qu'utilisateur primaire.", - "it": "{nick} non è registrato come utente principale." - }, "merged_users": { "en": "{old_user} and their aliases have been merged into {new_user}.", "na'vi": "{old_user} ulte stxo alahe {new_user} lu set.", diff --git a/modules/users/users.js b/modules/users/users.js index 382a00b..7fae6ca 100644 --- a/modules/users/users.js +++ b/modules/users/users.js @@ -140,3 +140,7 @@ var users = function(dbot) { }); }.bind(this); }; + +exports.fetch = function(dbot) { + return new users(dbot); +}; From 8ba4db33a7647c9062b796035984c5be683925d5 Mon Sep 17 00:00:00 2001 From: reality Date: Thu, 4 Sep 2014 10:15:52 +0000 Subject: [PATCH 05/54] some bug fixes --- modules/users/api.js | 4 +++- modules/users/commands.js | 12 +++++++----- modules/users/users.js | 18 +++++++++--------- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/modules/users/api.js b/modules/users/api.js index 1e25abb..af6a644 100644 --- a/modules/users/api.js +++ b/modules/users/api.js @@ -1,7 +1,7 @@ var _ = require('underscore')._; var api = function(dbot) { - this.api = { + var api = { // Retrieve a user record given a server and nickname 'resolveUser': function(server, nick, callback) { var id = nick + '.' + server; @@ -62,6 +62,8 @@ var api = function(dbot) { }); } }; + + return api; }; exports.fetch = function(dbot) { diff --git a/modules/users/commands.js b/modules/users/commands.js index 82e2445..2d4cd41 100644 --- a/modules/users/commands.js +++ b/modules/users/commands.js @@ -1,7 +1,7 @@ var _ = require('underscore')._; var commands = function(dbot) { - this.commands = { + var commands = { '~alias': function(event) { var nick = event.params[1] || event.user; this.api.resolveUser(event.server, nick, function(err, user) { @@ -124,10 +124,12 @@ var commands = function(dbot) { }.bind(this)); } }; - this.commands['~setaliasparent'].access = 'moderator'; - this.commands['~addalias'].access = 'moderator'; - this.commands['~rmalias'].access = 'moderator'; - this.commands['~mergeusers'].access = 'moderator'; + commands['~setaliasparent'].access = 'moderator'; + commands['~addalias'].access = 'moderator'; + commands['~rmalias'].access = 'moderator'; + commands['~mergeusers'].access = 'moderator'; + + return commands; }; exports.fetch = function(dbot) { diff --git a/modules/users/users.js b/modules/users/users.js index 7fae6ca..1cbf32f 100644 --- a/modules/users/users.js +++ b/modules/users/users.js @@ -24,7 +24,7 @@ var users = function(dbot) { callback(true, null); } }); - }, + }.bind(this), // Add new user alias 'createAlias': function(alias, user, callback) { @@ -41,7 +41,7 @@ var users = function(dbot) { callback(true, null); } }); - }, + }.bind(this), // Remove an alias record 'removeAlias': function(server, alias) { @@ -49,7 +49,7 @@ var users = function(dbot) { this.db.del('user_aliases', id, function(err) { callback(err); }); - }, + }.bind(this), // Update current nick of user record 'updateCurrentNick': function(user, newNick, callback) { @@ -62,7 +62,7 @@ var users = function(dbot) { callback(true, null); } }); - }, + }.bind(this), // Merge two user records and aliases 'mergeUsers': function(oldUser, newUser, callback) { @@ -82,7 +82,7 @@ var users = function(dbot) { callback(true); } }); - }, + }.bind(this), // Set a new nick as the parent for a user (so just recreate and merge) 'reparentUser': function(user, newPrimary, callback) { @@ -91,7 +91,7 @@ var users = function(dbot) { callback(err); }); }.bind(this)); - } + }.bind(this) }; /*** Listener ***/ @@ -114,7 +114,7 @@ var users = function(dbot) { this.onLoad = function() { // Create non-existing users and update current nicks - var checkUser = function(done) { + var checkUser = function(event, done) { this.api.resolveUser(event.server, event.user, function(err, user) { if(!user) { this.internalAPI.createUser(event.server, event.user, done); @@ -126,11 +126,11 @@ var users = function(dbot) { } } }.bind(this)); - }; + }.bind(this); dbot.instance.addPreEmitHook(function(event, callback) { if(event.user && _.include(['JOIN', 'PRIVMSG'], event.action)) { - checkUser(function(err, user) { + checkUser(event, function(err, user) { event.rUser = user; callback(null); }); From 1037070bff607584eac142f974d125cd09d339ef Mon Sep 17 00:00:00 2001 From: reality Date: Thu, 4 Sep 2014 12:15:11 +0000 Subject: [PATCH 06/54] fixes for merge and setaliasparent, basic sstats functionality --- modules/sstats/commands.js | 69 ++++++++++++++++++-------------------- modules/sstats/sstats.js | 37 ++++++++++---------- modules/users/commands.js | 12 +++---- modules/users/users.js | 29 ++++++++++------ 4 files changed, 73 insertions(+), 74 deletions(-) diff --git a/modules/sstats/commands.js b/modules/sstats/commands.js index 7176198..20e71c9 100644 --- a/modules/sstats/commands.js +++ b/modules/sstats/commands.js @@ -5,46 +5,41 @@ var _ = require('underscore')._, var commands = function(dbot) { var commands = { '~words': function(event) { - var getWords = function(user) { - this.api.getUserStats(user.id, function(uStats) { - if(uStats) { - var output = dbot.t('sstats_uwords', { - 'user': user.primaryNick, - 'words': uStats.words, - 'curses': uStats.curses, - 'capitals': uStats.capitals, - 'date': moment(uStats.creation).format('DD/MM/YYYY') - }); - if(event.rChannel && _.has(uStats.channels, event.rChannel.id)) { - ucStats = uStats.channels[event.rChannel.id]; - output += dbot.t('sstats_ucwords', { - 'channel': event.channel, - 'words': ucStats.words, - 'curses': ucStats.curses, - 'capitals': ucStats.capitals - }); - } - event.reply(output); - } else { - event.reply(dbot.t('sstats_noustats')); - } - }); - }.bind(this); - + var id = event.rUser.primaryNick + '.' + event.server, + user = event.rUser.currentNick, + cId = event.channel + '.' + event.server; if(event.params[1]) { - dbot.api.users.resolveUser(event.server, event.params[1], function(user) { - if(user) { - getWords(user); - } else { - event.reply(dbot.t('sstats_unknown_user')); - } - }); - } else { - getWords(event.rUser); + id = event.params[1] + '.' + event.server; + user = event.params[1]; } + + this.api.getUserStats(id, function(uStats) { + if(uStats) { + var output = dbot.t('sstats_uwords', { + 'user': user, + 'words': uStats.words, + 'curses': uStats.curses, + 'capitals': uStats.capitals, + 'date': moment(uStats.creation).format('DD/MM/YYYY') + }); + if(_.has(uStats.channels, cId)) { + ucStats = uStats.channels[cId]; + output += dbot.t('sstats_ucwords', { + 'channel': event.channel, + 'words': ucStats.words, + 'curses': ucStats.curses, + 'capitals': ucStats.capitals + }); + } + event.reply(output); + } else { + event.reply(dbot.t('sstats_noustats')); + } + }); }, '~lines': function(event) { + var cId = event.channel + '.' + event.server; var getLines = function(user) { this.api.getUserStats(user.id, function(uStats) { if(uStats) { @@ -53,10 +48,10 @@ var commands = function(dbot) { 'lines': uStats.lines, 'date': moment(uStats.creation).format('DD/MM/YYYY') }); - if(event.rChannel && _.has(uStats.channels, event.rChannel.id)) { + if(_.has(uStats.channels, cId)) { output += dbot.t('sstats_uclines', { 'channel': event.channel, - 'lines': uStats.channels[event.rChannel.id].lines + 'lines': uStats.channels[cId].lines }); } event.reply(output); diff --git a/modules/sstats/sstats.js b/modules/sstats/sstats.js index cc9e70b..504c24f 100644 --- a/modules/sstats/sstats.js +++ b/modules/sstats/sstats.js @@ -44,7 +44,7 @@ var sstats = function(dbot) { .value(); async.eachSeries(pCounts, function(pCount, next) { - dbot.api.users.getUser(pCount[0], function(user) { + dbot.api.users.getUser(pCount[0], function(err, user) { pCount[0] = user.primaryNick; next(); }); }, function() { @@ -54,14 +54,9 @@ var sstats = function(dbot) { }.bind(this), 'channelHighscore': function(key, server, channel, property, callback) { - dbot.api.users.resolveChannel(server, channel, function(channel) { - if(channel) { - var newProperty = 'channels.' + channel.id + '.' + property; - this.internalAPI.highscore(key, newProperty, callback); - } else { - callback(null); - } - }.bind(this)); + var cId = channel + '.' + server; + var newProperty = 'channels.' + cId + '.' + property; + this.internalAPI.highscore(key, newProperty, callback); }.bind(this), 'formatHighscore': function(string, pCounts) { @@ -78,6 +73,7 @@ var sstats = function(dbot) { event.uStats.lines++; var message = event.message.replace(/[\.,-\/#!$%\^&\*;:{}=\-_`~()]/g, ""); + var cId = event.channel + '.' + event.server; var words = message.split(' '), wCount = words.length, capitals = 0, @@ -98,18 +94,18 @@ var sstats = function(dbot) { event.cStats.capitals += capitals; event.cStats.curses += curses; - if(!_.has(event.uStats.channels, event.rChannel.id)) { - event.uStats.channels[event.rChannel.id] = { + if(!_.has(event.uStats.channels, cId)) { + event.uStats.channels[cId] = { 'lines': 1, 'words': wCount, 'capitals': capitals, 'curses': curses }; } else { - event.uStats.channels[event.rChannel.id].lines++; - event.uStats.channels[event.rChannel.id].words += wCount; - event.uStats.channels[event.rChannel.id].capitals += capitals; - event.uStats.channels[event.rChannel.id].curses += curses; + event.uStats.channels[cId].lines++; + event.uStats.channels[cId].words += wCount; + event.uStats.channels[cId].capitals += capitals; + event.uStats.channels[cId].curses += curses; } // Look for tracked words. @@ -124,9 +120,9 @@ var sstats = function(dbot) { this.api.getTrackedWord(word, function(tWord) { if(tWord) { tWord.total += count; - if(!_.has(tWord.channels, event.rChannel.id)) tWord.channels[event.rChannel.id] = 0; + if(!_.has(tWord.channels, cId)) tWord.channels[cId] = 0; if(!_.has(tWord.users, event.rUser.id)) tWord.users[event.rUser.id] = 0; - tWord.channels[event.rChannel.id] += count; + tWord.channels[cId] += count; tWord.users[event.rUser.id] += count; this.db.save('tracked_words', word, tWord, function() {}); } @@ -158,13 +154,14 @@ var sstats = function(dbot) { // Preload channel stats dbot.instance.addPreEmitHook(function(event, callback) { - if(!event.rChannel) return callback(); - this.api.getChannelStats(event.rChannel.id, function(cStats) { + if(!event.channel) return callback(); + var id = event.channel + '.' + event.server; + this.api.getChannelStats(id, function(cStats) { if(cStats) { event.cStats = cStats; callback(); } else { - this.api.createChannelStats(event.rChannel.id, function(cStats) { + this.api.createChannelStats(id, function(cStats) { event.cStats = cStats; callback(); }); diff --git a/modules/users/commands.js b/modules/users/commands.js index 2d4cd41..0bfcb14 100644 --- a/modules/users/commands.js +++ b/modules/users/commands.js @@ -65,7 +65,7 @@ var commands = function(dbot) { '~setaliasparent': function(event) { var newPrimary = event.params[1]; - this.api.resolveUser(event.server, newPrimary, function(user) { + this.api.resolveUser(event.server, newPrimary, function(err, user) { if(user) { if(user.primaryNick !== newPrimary) { this.internalAPI.reparentUser(user, newPrimary, function() { @@ -78,9 +78,9 @@ var commands = function(dbot) { event.reply(dbot.t('already_primary', { 'user': newPrimary })); } } else { - event.reply(dbot.t('unknown_alias', { 'alias': nick })); + event.reply(dbot.t('unknown_alias', { 'alias': newPrimary })); } - }); + }.bind(this)); }, '~rmalias': function(event) { @@ -107,11 +107,11 @@ var commands = function(dbot) { this.api.resolveUser(event.server, oldNick, function(err, oldUser) { if(oldUser) { this.api.resolveUser(event.server, newNick, function(err, newUser) { - if(newUser) { + if(newUser && newUser.id !== oldUser.id) { this.internalAPI.mergeUsers(oldUser, newUser, function() { event.reply(dbot.t('merged_users', { - 'old_user': secondaryUser, - 'new_user': primaryUser + 'old_user': oldNick, + 'new_user': newNick })); }); } else { diff --git a/modules/users/users.js b/modules/users/users.js index 1cbf32f..ad76cfc 100644 --- a/modules/users/users.js +++ b/modules/users/users.js @@ -35,7 +35,7 @@ var users = function(dbot) { 'user': user.id }, function(err, result) { if(!err) { - dbot.api.event.emit('new_user_alias', [ event.rUser, event.newNick ]); + dbot.api.event.emit('new_user_alias', [ user, alias ]); callback(null, result); } else { callback(true, null); @@ -67,9 +67,15 @@ var users = function(dbot) { // Merge two user records and aliases 'mergeUsers': function(oldUser, newUser, callback) { this.db.search('user_aliases', { 'user': oldUser.id }, function(alias) { - alias.user = newUser.id; - this.db.save('user_aliases', alias.id, alias, function(){}); - }.bind(this), function(){}); + if(alias.alias === newUser.primaryNick) { + this.db.del('user_aliases', alias.id, function(){}); + } else { + alias.user = newUser.id; + this.db.save('user_aliases', alias.id, alias, function(){}); + } + }.bind(this), function(){ + this.internalAPI.createAlias(oldUser.primaryNick, newUser, function(){}); + }.bind(this)); this.db.del('users', oldUser.id, function(err) { if(!err) { @@ -99,13 +105,14 @@ var users = function(dbot) { // Track nick changes this.listener = function(event) { // Update current nick - this.internalAPI.updateCurrentNick(event.rUser, event.newNick, function(){}); - - // Add new alias record if nick is not already claimed - this.api.resolveUser(event.server, event.newNick, function(err, user) { - if(!user) { - this.internalAPI.createAlias(event.newNick, event.rUser, function(){}); - } + this.api.resolveUser(event.server, event.user, function(err, user) { + console.log(user); + this.internalAPI.updateCurrentNick(user, event.newNick, function(){}); + this.api.resolveUser(event.server, event.newNick, function(err, eUser) { + if(!eUser) { + this.internalAPI.createAlias(event.newNick, user, function(){}); + } + }.bind(this)); }.bind(this)); }.bind(this); this.on = ['NICK']; From 34acae025b07430b046d09e323cf5917c50e9a96 Mon Sep 17 00:00:00 2001 From: reality Date: Thu, 4 Sep 2014 13:04:15 +0000 Subject: [PATCH 07/54] fix most of the sstats stuff, still got to do merge trigger --- modules/sstats/commands.js | 2 +- modules/sstats/sstats.js | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/modules/sstats/commands.js b/modules/sstats/commands.js index 20e71c9..fb61f1e 100644 --- a/modules/sstats/commands.js +++ b/modules/sstats/commands.js @@ -155,7 +155,7 @@ var commands = function(dbot) { }, '~last': function(event) { - dbot.api.users.resolveUser(event.server, event.params[1], function(user) { + dbot.api.users.resolveUser(event.server, event.params[1], function(err, user) { if(user) { this.api.getUserStats(user.id, function(uStats) { if(uStats && uStats.last) { diff --git a/modules/sstats/sstats.js b/modules/sstats/sstats.js index 504c24f..71a4ac8 100644 --- a/modules/sstats/sstats.js +++ b/modules/sstats/sstats.js @@ -20,7 +20,10 @@ var sstats = function(dbot) { // repetition 'highscore': function(key, property, callback) { var pList = {}, + pPointer = property; + if(!_.isArray(pPointer)) { pPointer = property.split('.'); + } this.db.scan(key, function(item) { var id = item.id; @@ -55,7 +58,7 @@ var sstats = function(dbot) { 'channelHighscore': function(key, server, channel, property, callback) { var cId = channel + '.' + server; - var newProperty = 'channels.' + cId + '.' + property; + var newProperty = ['channels', cId, property]; this.internalAPI.highscore(key, newProperty, callback); }.bind(this), From b18a61ebd148fb016557381d6aed2d5bde7ada5a Mon Sep 17 00:00:00 2001 From: reality Date: Thu, 4 Sep 2014 13:43:53 +0000 Subject: [PATCH 08/54] fix reports and warning --- modules/report/api.js | 3 --- modules/warning/warning.js | 6 +++--- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/modules/report/api.js b/modules/report/api.js index a14f905..6967c96 100644 --- a/modules/report/api.js +++ b/modules/report/api.js @@ -41,9 +41,6 @@ var api = function(dbot) { this.db.read('nunsubs', channel.id, function(err, nunsubs) { async.eachSeries(ops, function(nick, next) { dbot.api.users.resolveUser(server, nick, function(user) { - if(!_.include(user.mobile, user.currentNick)) { - perOps = _.without(perOps, user.id); - } if(nunsubs && _.include(nunsubs.users, user.id)) { ops = _.without(ops, user.currentNick); } diff --git a/modules/warning/warning.js b/modules/warning/warning.js index 0525b3c..e5f1a89 100644 --- a/modules/warning/warning.js +++ b/modules/warning/warning.js @@ -6,7 +6,7 @@ var warning = function(dbot) { 'warn': function(server, warner, user, reason, channel, callback) { var adminChannel = dbot.config.servers[server].admin_channel || channel.name; - dbot.api.users.resolveUser(server, user, function(warnee) { + dbot.api.users.resolveUser(server, user, function(err, warnee) { if(warnee) { var id = uuid.v4(); this.db.save('warnings', id, { @@ -52,7 +52,7 @@ var warning = function(dbot) { '~rmwarning': function(event) { var warning = null; - dbot.api.users.resolveUser(event.server, event.input[1], function(warnee) { + dbot.api.users.resolveUser(event.server, event.input[1], function(err, warnee) { if(warnee) { this.db.search('warnings', { 'warnee': warnee.id, 'reason': event.input[2] }, function(result) { warning = result; @@ -75,7 +75,7 @@ var warning = function(dbot) { var warnee = event.params[1], server = event.server; - dbot.api.users.resolveUser(server, warnee, function(warnee) { + dbot.api.users.resolveUser(server, warnee, function(err, warnee) { var warnings = 0; this.db.search('warnings', { 'server': server, From 78057dca3c16b430df0d6b22756c7610bf4619d7 Mon Sep 17 00:00:00 2001 From: reality Date: Thu, 4 Sep 2014 14:19:23 +0000 Subject: [PATCH 09/54] update web to use new express version --- modules/warning/pages.js | 3 +-- modules/web/web.js | 20 +++++++++++--------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/modules/warning/pages.js b/modules/warning/pages.js index 0c4cf08..298db12 100644 --- a/modules/warning/pages.js +++ b/modules/warning/pages.js @@ -39,7 +39,7 @@ var pages = function(dbot) { var server = req.params.server, user = req.params.uid; - dbot.api.users.resolveUser(server, user, function(user) { + dbot.api.users.resolveUser(server, user, function(err, user) { var warnings = []; this.db.search('warnings', { 'server': server, @@ -54,7 +54,6 @@ var pages = function(dbot) { callback(false); }); }, function(err) { - console.log(warnings); res.render('warnings', { 'name': dbot.config.name, 'server': server, diff --git a/modules/web/web.js b/modules/web/web.js index f15f41d..b7f458d 100644 --- a/modules/web/web.js +++ b/modules/web/web.js @@ -4,7 +4,11 @@ var express = require('express'), flash = require('connect-flash'), _ = require('underscore')._, fs = require('fs'), - LocalStrategy = require('passport-local').Strategy; + LocalStrategy = require('passport-local').Strategy, + cookieParser = require('cookie-parser'); + bodyParser = require('body-parser'); + expressSession = require('express-session'); + methodOverride = require('method-override'); var webInterface = function(dbot) { this.config = dbot.config.modules.web; @@ -14,15 +18,14 @@ var webInterface = function(dbot) { this.app.use(express.static(this.pub)); this.app.set('view engine', 'jade'); - this.app.use(express.cookieParser()); - this.app.use(express.bodyParser()); - this.app.use(express.methodOverride()); - this.app.use(express.session({ 'secret': 'wat' })); + this.app.use(cookieParser()); + this.app.use(methodOverride()); + this.app.use(expressSession({ 'secret': 'wat' })); + this.app.use(bodyParser()); this.app.use(flash()); this.app.use(passport.initialize()); this.app.use(passport.session()); - this.app.use(this.app.router); passport.serializeUser(function(user, done) { done(null, user.id); @@ -46,7 +49,7 @@ var webInterface = function(dbot) { 'Please provide a valid server (Servers: ' + _.keys(dbot.config.servers).join(', ') + ')' }); - dbot.api.users.resolveUser(server, username, function(user) { + dbot.api.users.resolveUser(server, username, function(err, user) { if(user) { this.api.getWebUser(user.id, function(webUser) { if(webUser) { @@ -95,8 +98,7 @@ var webInterface = function(dbot) { this.onLoad = function() { this.reloadPages(); - - var routes = _.pluck(dbot.modules.web.app.routes.get, 'path'), + var routes = _.pluck(_.without(_.pluck(this.app._router.stack, 'route'), undefined), 'path'), moduleNames = _.keys(dbot.modules); _.each(moduleNames, function(moduleName) { From c519727b6cb61f0f582648b2978f1456926b6bcd Mon Sep 17 00:00:00 2001 From: reality Date: Thu, 4 Sep 2014 14:41:57 +0000 Subject: [PATCH 10/54] fix login --- modules/web/web.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/modules/web/web.js b/modules/web/web.js index b7f458d..08ce4d9 100644 --- a/modules/web/web.js +++ b/modules/web/web.js @@ -4,11 +4,11 @@ var express = require('express'), flash = require('connect-flash'), _ = require('underscore')._, fs = require('fs'), - LocalStrategy = require('passport-local').Strategy, - cookieParser = require('cookie-parser'); - bodyParser = require('body-parser'); - expressSession = require('express-session'); - methodOverride = require('method-override'); + cookieParser = require('cookie-parser'), + bodyParser = require('body-parser'), + expressSession = require('express-session'), + methodOverride = require('method-override'), + LocalStrategy = require('passport-local').Strategy; var webInterface = function(dbot) { this.config = dbot.config.modules.web; @@ -19,9 +19,10 @@ var webInterface = function(dbot) { this.app.use(express.static(this.pub)); this.app.set('view engine', 'jade'); this.app.use(cookieParser()); + this.app.use(bodyParser.json()); + this.app.use(bodyParser.urlencoded({ 'extended': true })); this.app.use(methodOverride()); this.app.use(expressSession({ 'secret': 'wat' })); - this.app.use(bodyParser()); this.app.use(flash()); this.app.use(passport.initialize()); @@ -32,7 +33,7 @@ var webInterface = function(dbot) { }); passport.deserializeUser(function(id, done) { - dbot.api.users.getUser(id, function(user) { + dbot.api.users.getUser(id, function(err, user) { done(null, user); }); }); From e096daa605c491481d3e5bbe02bb72dae635d837 Mon Sep 17 00:00:00 2001 From: reality Date: Thu, 4 Sep 2014 14:48:20 +0000 Subject: [PATCH 11/54] fix getUser calls --- modules/lastfm/lastfm.js | 6 +++--- modules/poll/pages.js | 2 +- modules/profile/pages.js | 4 ++-- modules/report/pages.js | 8 ++++---- modules/warning/pages.js | 5 ++--- 5 files changed, 12 insertions(+), 13 deletions(-) diff --git a/modules/lastfm/lastfm.js b/modules/lastfm/lastfm.js index 489e88c..77b7f8a 100644 --- a/modules/lastfm/lastfm.js +++ b/modules/lastfm/lastfm.js @@ -187,7 +187,7 @@ var lastfm = function(dbot) { .value(); async.each(scrobbliest, function(item, done) { - dbot.api.users.getUser(item.user, function(user) { + dbot.api.users.getUser(item.user, function(err, user) { item.user = user; done(); }); @@ -327,9 +327,9 @@ var lastfm = function(dbot) { async.each(tastiest, function(pair, done) { if(!_.isObject(pair.p1)) { // fix this - dbot.api.users.getUser(pair.p1, function(user) { + dbot.api.users.getUser(pair.p1, function(err, user) { pair.p1 = user; - dbot.api.users.getUser(pair.p2, function(user) { + dbot.api.users.getUser(pair.p2, function(err, user) { pair.p2 = user; done(); }); diff --git a/modules/poll/pages.js b/modules/poll/pages.js index a4df4db..b3b77cc 100644 --- a/modules/poll/pages.js +++ b/modules/poll/pages.js @@ -15,7 +15,7 @@ var pages = function(dbot) { var voterNicks = []; async.each(_.keys(poll.votees), function(id, done) { - dbot.api.users.getUser(id, function(user) { + dbot.api.users.getUser(id, function(err, user) { voterNicks.push(user.primaryNick); done(); }); diff --git a/modules/profile/pages.js b/modules/profile/pages.js index 73b4c08..309b36e 100644 --- a/modules/profile/pages.js +++ b/modules/profile/pages.js @@ -7,7 +7,7 @@ var pages = function(dbot) { var connection = req.params.connection; var nick = req.params.user; - dbot.api.users.resolveUser(connection, nick, function(user){ + dbot.api.users.resolveUser(connection, nick, function(err, user){ if(user){ dbot.api.profile.getProfile(connection, user.primaryNick, function(err, user, profile){ if(!err){ @@ -45,7 +45,7 @@ var pages = function(dbot) { dbot.api.profile.getAllProfiles(function(profiles){ var thumbnails = []; _.each(profiles, function(profile){ - var nick = dbot.api.users.getUser(profile.id, function(user){ + var nick = dbot.api.users.getUser(profile.id, function(err, user){ if(user){ /*TODO(@tmenari / @samstudio8) diff --git a/modules/report/pages.js b/modules/report/pages.js index 3c17030..07d814f 100644 --- a/modules/report/pages.js +++ b/modules/report/pages.js @@ -33,7 +33,7 @@ var pages = function(dbot) { }); async.eachSeries(userCount, function(userCount, next) { - dbot.api.users.getUser(userCount.id, function(user) { + dbot.api.users.getUser(userCount.id, function(err, user) { if(user) { userCount['name'] = user.primaryNick; users.push(userCount); @@ -72,7 +72,7 @@ var pages = function(dbot) { }); }.bind(this), function() { async.each(notifications, function(notify, done) { - dbot.api.users.getUser(notify.user, function(user) { + dbot.api.users.getUser(notify.user, function(err, user) { if(user) notify.user = user.primaryNick; done(); }); @@ -138,7 +138,7 @@ var pages = function(dbot) { var pNickCache = {}; async.eachSeries(notifies, function(notify, next) { if(!_.has(pNickCache, notify.user)) { - dbot.api.users.getUser(notify.user, function(user) { + dbot.api.users.getUser(notify.user, function(err, user) { pNickCache[notify.user] = user.primaryNick; notify.user = user.primaryNick; next(); @@ -163,7 +163,7 @@ var pages = function(dbot) { } else { var username = req.params.item; - dbot.api.users.resolveUser(server, username, function(user) { + dbot.api.users.resolveUser(server, username, function(err, user) { this.db.search('notifies', { 'user': user.id }, function(notify) { diff --git a/modules/warning/pages.js b/modules/warning/pages.js index 298db12..cb105fa 100644 --- a/modules/warning/pages.js +++ b/modules/warning/pages.js @@ -21,7 +21,7 @@ var pages = function(dbot) { if(!_.include(userIds, warning.warnee)) userIds.push(warning.warnee); }, function(err) { async.eachSeries(userIds, function(id, callback) { - dbot.api.users.getUser(id, function(user) { + dbot.api.users.getUser(id, function(err, user) { userNicks.push(user.primaryNick); callback(false); }); @@ -47,9 +47,8 @@ var pages = function(dbot) { }, function(warning) { warnings.push(warning); }, function(err) { - console.log(warnings); async.eachSeries(warnings, function(warning, callback) { - dbot.api.users.getUser(warning.warner, function(user) { + dbot.api.users.getUser(warning.warner, function(err, user) { warning.warner = user.primaryNick; callback(false); }); From ef250fbc056346d8f0c9d3f4670adc3301fe9de7 Mon Sep 17 00:00:00 2001 From: reality Date: Thu, 4 Sep 2014 14:54:49 +0000 Subject: [PATCH 12/54] fix resolveuser references --- modules/kick/commands.js | 2 +- modules/profile/api.js | 2 +- modules/radio/radio.js | 2 +- modules/report/api.js | 2 ++ modules/report/commands.js | 4 ++-- 5 files changed, 7 insertions(+), 5 deletions(-) diff --git a/modules/kick/commands.js b/modules/kick/commands.js index 6621e2e..577cc58 100644 --- a/modules/kick/commands.js +++ b/modules/kick/commands.js @@ -28,7 +28,7 @@ var commands = function(dbot) { this.api.voice(server, quietee, channel); } - dbot.api.users.resolveUser(server, dbot.config.name, function(user) { + dbot.api.users.resolveUser(server, dbot.config.name, function(err, user) { dbot.api.report.notify('unquiet', server, user, channel, dbot.t('unquiet_notify', { 'unquieter': dbot.config.name, diff --git a/modules/profile/api.js b/modules/profile/api.js index 9324270..25a6c9c 100644 --- a/modules/profile/api.js +++ b/modules/profile/api.js @@ -28,7 +28,7 @@ var api = function(dbot) { }, 'getProfile': function(server, nick, callback){ - dbot.api.users.resolveUser(server, nick, function(user){ + dbot.api.users.resolveUser(server, nick, function(err, user){ if(user){ this.db.read('profiles', user.id, function(err, profile){ if(!err){ diff --git a/modules/radio/radio.js b/modules/radio/radio.js index e4ad617..b46f73d 100644 --- a/modules/radio/radio.js +++ b/modules/radio/radio.js @@ -54,7 +54,7 @@ var radio = function(dbot) { var dj = this.data['icy-description'], song = event.input[1]; - dbot.api.users.resolveUser(event.server, dj, function(user) { + dbot.api.users.resolveUser(event.server, dj, function(err, user) { if(user) { dbot.say(event.server, user.currentNick, dbot.t('radio_request',{ 'user': event.user, diff --git a/modules/report/api.js b/modules/report/api.js index 6967c96..93b1515 100644 --- a/modules/report/api.js +++ b/modules/report/api.js @@ -33,6 +33,7 @@ var api = function(dbot) { }, this); ops = _.pluck(ops, 'name'); +/** TODO dbot.api.users.resolveChannel(server, cName, function(channel) { if(channel) { var perOps = channel.op; @@ -71,6 +72,7 @@ var api = function(dbot) { }.bind(this)); } }.bind(this)); +**/ }, 'notifyUsers': function(server, users, message) { diff --git a/modules/report/commands.js b/modules/report/commands.js index b966a24..7b33b50 100644 --- a/modules/report/commands.js +++ b/modules/report/commands.js @@ -85,7 +85,7 @@ var commands = function(dbot) { if(reason.charAt(reason.length - 1) != '.') reason += '.'; - dbot.api.users.resolveUser(event.server, nick, function(reportee) { + dbot.api.users.resolveUser(event.server, nick, function(err, reportee) { if(_.has(event.allChannels, channelName)) { if(reportee) { this.api.notify('report', event.server, event.rUser, @@ -114,7 +114,7 @@ var commands = function(dbot) { if(_.has(event.allChannels, channelName)) { if(this.config.firstHost) { var first = message.split(' ')[0]; - dbot.api.users.resolveUser(event.server, first, function(user) { + dbot.api.users.resolveUser(event.server, first, function(err, user) { if(user && _.include(this.config.host_lookup, channelName)) { dbot.api.nickserv.getUserHost(event.server, first, function(host) { message = message.replace(first, first + ' [' + host + ']'); From 8dfe1a37c4fca0779477bb3329d90d02d72161df Mon Sep 17 00:00:00 2001 From: reality Date: Thu, 4 Sep 2014 15:25:21 +0000 Subject: [PATCH 13/54] remove getchannel stuff --- modules/report/api.js | 2 -- modules/report/commands.js | 3 ++- modules/users/api.js | 17 ----------------- 3 files changed, 2 insertions(+), 20 deletions(-) diff --git a/modules/report/api.js b/modules/report/api.js index 93b1515..6967c96 100644 --- a/modules/report/api.js +++ b/modules/report/api.js @@ -33,7 +33,6 @@ var api = function(dbot) { }, this); ops = _.pluck(ops, 'name'); -/** TODO dbot.api.users.resolveChannel(server, cName, function(channel) { if(channel) { var perOps = channel.op; @@ -72,7 +71,6 @@ var api = function(dbot) { }.bind(this)); } }.bind(this)); -**/ }, 'notifyUsers': function(server, users, message) { diff --git a/modules/report/commands.js b/modules/report/commands.js index 7b33b50..c6b358e 100644 --- a/modules/report/commands.js +++ b/modules/report/commands.js @@ -75,9 +75,10 @@ var commands = function(dbot) { }, '~report': function(event) { - var channelName = (event.input[1].trim() || event.channel), + var channelName = (event.input[1] || event.channel.toString()), nick = event.input[2], reason = event.input[3].trim(); + channelName = channelName.trim(); if(channelName == event.user) { channelName = dbot.config.servers[event.server].admin_channel; diff --git a/modules/users/api.js b/modules/users/api.js index af6a644..6c7fdfa 100644 --- a/modules/users/api.js +++ b/modules/users/api.js @@ -43,23 +43,6 @@ var api = function(dbot) { callback(true, null); } }); - }, - - // Retrieve a channel record given a server and a channel name - 'resolveChannel': function(server, channel, callback) { - var id = channel + '.' + server; - this.api.getChannel(id, callback); - }, - - // Retrieve a channel record given its ID - 'getChannel': function(id, callback) { - this.db.read('channels', id, function(err, result) { - if(!err) { - callback(null, result); - } else { - callback(true, null); - } - }); } }; From e83b4af33f6966f9866a79db8e6dee11fce777a0 Mon Sep 17 00:00:00 2001 From: reality Date: Thu, 4 Sep 2014 15:26:28 +0000 Subject: [PATCH 14/54] move charybdis module to atheme --- modules/{charybdis/charybdis.js => atheme/atheme.js} | 8 ++++---- modules/{charybdis => atheme}/config.json | 0 2 files changed, 4 insertions(+), 4 deletions(-) rename modules/{charybdis/charybdis.js => atheme/atheme.js} (82%) rename modules/{charybdis => atheme}/config.json (100%) diff --git a/modules/charybdis/charybdis.js b/modules/atheme/atheme.js similarity index 82% rename from modules/charybdis/charybdis.js rename to modules/atheme/atheme.js index 4e3f936..ba78e31 100644 --- a/modules/charybdis/charybdis.js +++ b/modules/atheme/atheme.js @@ -4,7 +4,7 @@ */ var _ = require('underscore')._; -var charybdis = function(dbot) { +var atheme = function(dbot) { this.commands = { '~chanserv': function(event) { if(_.has(this.config.chanserv, event.input[1])) { @@ -22,10 +22,10 @@ var charybdis = function(dbot) { } } }; - this.commands['~chanserv'].regex = [/^chanserv (\+.)/, 2] - this.commands['~chanmode'].regex = [/^chanmode (\+.)/, 2] + this.commands['~chanserv'].regex = [/^chanserv (\+.)/, 2]; + this.commands['~chanmode'].regex = [/^chanmode (\+.)/, 2]; }; exports.fetch = function(dbot) { - return new charybdis(dbot); + return new atheme(dbot); }; diff --git a/modules/charybdis/config.json b/modules/atheme/config.json similarity index 100% rename from modules/charybdis/config.json rename to modules/atheme/config.json From 24d14e70054d501a430abf8fe9fd0ec21c0ff184 Mon Sep 17 00:00:00 2001 From: reality Date: Fri, 5 Sep 2014 08:51:48 +0000 Subject: [PATCH 15/54] read flags --- modules/atheme/atheme.js | 45 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/modules/atheme/atheme.js b/modules/atheme/atheme.js index ba78e31..acb6732 100644 --- a/modules/atheme/atheme.js +++ b/modules/atheme/atheme.js @@ -5,6 +5,32 @@ var _ = require('underscore')._; var atheme = function(dbot) { + this.flagStack = {}; + + this.api = { + 'getChannelFlags': function(server, channel, callback) { + if(!_.has(this.flagStack, server)) this.flagStack[server] = {}; + if(_.has(flagStack[server], channel)) { // Already an active flag call + this.flagStack[server][channel].callbacks.push(callback); + } else { + this.flagStack[server][channel] = { + 'flags': {}, + 'callbacks': [ callback ] + }; + } + + dbot.say(server, 'chanserv', 'FLAGS ' + channel); + setTimeout(function() { // Delete callback if no response + if(_.has(this.flagStack[server], channel)) { + _.each(this.flagStack[server][channel].callbacks, function(callback) { + callback(true, null); + }); + delete this.flagStack[server][channel]; + } + }.bind(this), 10000); + } + }; + this.commands = { '~chanserv': function(event) { if(_.has(this.config.chanserv, event.input[1])) { @@ -24,6 +50,25 @@ var atheme = function(dbot) { }; this.commands['~chanserv'].regex = [/^chanserv (\+.)/, 2]; this.commands['~chanmode'].regex = [/^chanmode (\+.)/, 2]; + + this.listener = function(event) { + if(event.user === 'chanserv') { + var flags = event.message.match(/(\d+)\s+([^ ]+)\s+(\+\w+)\s+\((\#.+)\)/), + end = event.message.match(/End of (\#.+) FLAGS listing./); + + if(flags && _.has(this.flagStack[event.server], flags[4])) { + this.flagStack[event.server][flags[4]].flags[flags[2]] = flags[3]; + } else if(end) { + if(_.has(this.flagStack[event.server], end[1])) { + _.each(this.flagStack[event.server][end[1]].callbacks, function(callback) { + callback(null, this.flagStack[event.server][end[1]].flags); + }); + delete this.flagStack[event.server][end[1]]; + } + } + } + }.bind(this); + this.on = 'NOTICE'; }; exports.fetch = function(dbot) { From 7cb53a8b5a02d878209657f0cfec110a31c94dd3 Mon Sep 17 00:00:00 2001 From: reality Date: Fri, 5 Sep 2014 09:15:05 +0000 Subject: [PATCH 16/54] now it works --- modules/atheme/atheme.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/atheme/atheme.js b/modules/atheme/atheme.js index acb6732..c57e287 100644 --- a/modules/atheme/atheme.js +++ b/modules/atheme/atheme.js @@ -10,7 +10,7 @@ var atheme = function(dbot) { this.api = { 'getChannelFlags': function(server, channel, callback) { if(!_.has(this.flagStack, server)) this.flagStack[server] = {}; - if(_.has(flagStack[server], channel)) { // Already an active flag call + if(_.has(this.flagStack[server], channel)) { // Already an active flag call this.flagStack[server][channel].callbacks.push(callback); } else { this.flagStack[server][channel] = { @@ -52,9 +52,9 @@ var atheme = function(dbot) { this.commands['~chanmode'].regex = [/^chanmode (\+.)/, 2]; this.listener = function(event) { - if(event.user === 'chanserv') { - var flags = event.message.match(/(\d+)\s+([^ ]+)\s+(\+\w+)\s+\((\#.+)\)/), - end = event.message.match(/End of (\#.+) FLAGS listing./); + if(event.user === 'ChanServ') { + var flags = event.params.match(/(\d+)\s+([^ ]+)\s+(\+\w+)\s+\((\#\w+)\)/), + end = event.params.match(/end of \u0002(\#\w+)\u0002 flags listing/i); if(flags && _.has(this.flagStack[event.server], flags[4])) { this.flagStack[event.server][flags[4]].flags[flags[2]] = flags[3]; @@ -62,7 +62,7 @@ var atheme = function(dbot) { if(_.has(this.flagStack[event.server], end[1])) { _.each(this.flagStack[event.server][end[1]].callbacks, function(callback) { callback(null, this.flagStack[event.server][end[1]].flags); - }); + }.bind(this)); delete this.flagStack[event.server][end[1]]; } } From 8c5e87164008660d58a99adca006360f024d2925 Mon Sep 17 00:00:00 2001 From: reality Date: Fri, 5 Sep 2014 10:42:30 +0000 Subject: [PATCH 17/54] report report (it works) --- modules/report/api.js | 136 ++++++++++++++++++++++++++++------------- modules/users/api.js | 20 ++++++ modules/users/users.js | 15 ++--- 3 files changed, 120 insertions(+), 51 deletions(-) diff --git a/modules/report/api.js b/modules/report/api.js index 6967c96..f80be88 100644 --- a/modules/report/api.js +++ b/modules/report/api.js @@ -24,53 +24,101 @@ var api = function(dbot) { }); var channel = dbot.instance.connections[server].channels[cName]; - var ops = _.filter(channel.nicks, function(user) { - if(this.config.notifyVoice) { - return user.op || user.voice; - } else { - return user.op; - } - }, this); - ops = _.pluck(ops, 'name'); + if(_.has(dbot.modules, 'atheme')) { + dbot.api.atheme.getChannelFlags(server, cName, function(err, flags) { + var ops = _.map(flags, function(f, k) { + var staff = (f.indexOf('O') !== -1); + if(this.config.notifyVoice && !staff) { + staff = (f.indexOf('V') !== -1); + } + if(staff) { + return k; + } + }.bind(this)); - dbot.api.users.resolveChannel(server, cName, function(channel) { - if(channel) { - var perOps = channel.op; - if(this.config.notifyVoice) perOps = _.union(perOps, channel.voice); + var offlineOps = {}; + async.each(ops, function(op, done) { + dbot.api.users.isOnline(server, cName, op, function(err, user, online) { + if(!err && !online) offlineOps[op] = user; + if(user.currentNick !== op) { + ops = _.without(ops, op); + ops.push(user.currentNick); + } + done(); + }); + }, function() { + // Queue notifies for offline ops + _.each(offlineOps, function(op) { + if(!this.pending[op.id]) this.pending[op.id] = []; + this.pending[op.id].push({ + 'time': new Date().getTime(), + 'channel': cName, + 'user': op.id, + 'message': message + }); + this.pNotify[op.id] = true; + }, this); - this.db.read('nunsubs', channel.id, function(err, nunsubs) { - async.eachSeries(ops, function(nick, next) { - dbot.api.users.resolveUser(server, nick, function(user) { - if(nunsubs && _.include(nunsubs.users, user.id)) { - ops = _.without(ops, user.currentNick); - } - next(); - }); - }, function() { - offlineUsers = perOps; - if(!_.include(this.config.noMissingChans, cName)) { - _.each(offlineUsers, function(id) { - if(!this.pending[id]) this.pending[id] = []; - this.pending[id].push({ - 'time': new Date().getTime(), - 'channel': cName, - 'user': user.primaryNick, - 'message': message - }); - this.pNotify[id] = true; - }.bind(this)); - } - - message = this.internalAPI.formatNotify(type, server, - user, cName, message); - this.internalAPI.notify(server, ops, message); - if(_.has(this.config.chan_redirs, cName)) { - dbot.say(server, this.config.chan_redirs[cName], message); - } - }.bind(this)); + // Send notifies to online ops + ops = _.difference(ops, _.keys(offlineOps)); + message = this.internalAPI.formatNotify(type, server, + user, cName, message); + this.internalAPI.notify(server, ops, message); + if(_.has(this.config.chan_redirs, cName)) { + dbot.say(server, this.config.chan_redirs[cName], message); + } }.bind(this)); - } - }.bind(this)); + }.bind(this)); + } else { + var channel = dbot.instance.connections[server].channels[cName]; + var ops = _.filter(channel.nicks, function(user) { + if(this.config.notifyVoice) { + return user.op || user.voice; + } else { + return user.op; + } + }, this); + ops = _.pluck(ops, 'name'); + + dbot.api.users.resolveChannel(server, cName, function(channel) { + if(channel) { + var perOps = channel.op; + if(this.config.notifyVoice) perOps = _.union(perOps, channel.voice); + + this.db.read('nunsubs', channel.id, function(err, nunsubs) { + async.eachSeries(ops, function(nick, next) { + dbot.api.users.resolveUser(server, nick, function(user) { + if(nunsubs && _.include(nunsubs.users, user.id)) { + ops = _.without(ops, user.currentNick); + } + next(); + }); + }, function() { + offlineUsers = perOps; + if(!_.include(this.config.noMissingChans, cName)) { + _.each(offlineUsers, function(id) { + if(!this.pending[id]) this.pending[id] = []; + this.pending[id].push({ + 'time': new Date().gettime(), + 'channel': cname, + 'user': user.primarynick, + 'message': message + }); + this.pnotify[id] = true; + }.bind(this)); + } + + message = this.internalAPI.formatNotify(type, server, + user, cName, message); + this.internalAPI.notify(server, ops, message); + if(_.has(this.config.chan_redirs, cName)) { + dbot.say(server, this.config.chan_redirs[cName], message); + } + }.bind(this)); + }.bind(this)); + } + }.bind(this)); + } }, 'notifyUsers': function(server, users, message) { diff --git a/modules/users/api.js b/modules/users/api.js index 6c7fdfa..bbc171d 100644 --- a/modules/users/api.js +++ b/modules/users/api.js @@ -43,6 +43,26 @@ var api = function(dbot) { callback(true, null); } }); + }, + + // Check if a nick is online under a given alias + 'isOnline': function(server, channel, nick, callback) { + this.api.resolveUser(server, nick, function(err, user) { + if(user) { + this.api.getUserAliases(user.id, function(err, aliases) { + aliases.push(nick); + + var onlineNicks = _.keys(dbot.instance.connections[server].channels[channel].nicks); + var isOnline = _.any(onlineNicks, function(nick) { + return _.include(aliases, nick); + }, this); + + callback(null, user, isOnline); + }); + } else { + callback(true, null, null); + } + }.bind(this)); } }; diff --git a/modules/users/users.js b/modules/users/users.js index ad76cfc..c6de710 100644 --- a/modules/users/users.js +++ b/modules/users/users.js @@ -106,13 +106,14 @@ var users = function(dbot) { this.listener = function(event) { // Update current nick this.api.resolveUser(event.server, event.user, function(err, user) { - console.log(user); - this.internalAPI.updateCurrentNick(user, event.newNick, function(){}); - this.api.resolveUser(event.server, event.newNick, function(err, eUser) { - if(!eUser) { - this.internalAPI.createAlias(event.newNick, user, function(){}); - } - }.bind(this)); + if(user) { + this.internalAPI.updateCurrentNick(user, event.newNick, function(){}); + this.api.resolveUser(event.server, event.newNick, function(err, eUser) { + if(!eUser) { + this.internalAPI.createAlias(event.newNick, user, function(){}); + } + }.bind(this)); + } }.bind(this)); }.bind(this); this.on = ['NICK']; From bea3283b0531f55d220610b525a5eb14b91371f0 Mon Sep 17 00:00:00 2001 From: reality Date: Fri, 5 Sep 2014 11:29:25 +0000 Subject: [PATCH 18/54] no offline messages support for those using anything but my changes to atheme. gg -.- --- modules/report/api.js | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/modules/report/api.js b/modules/report/api.js index f80be88..6586853 100644 --- a/modules/report/api.js +++ b/modules/report/api.js @@ -94,20 +94,6 @@ var api = function(dbot) { next(); }); }, function() { - offlineUsers = perOps; - if(!_.include(this.config.noMissingChans, cName)) { - _.each(offlineUsers, function(id) { - if(!this.pending[id]) this.pending[id] = []; - this.pending[id].push({ - 'time': new Date().gettime(), - 'channel': cname, - 'user': user.primarynick, - 'message': message - }); - this.pnotify[id] = true; - }.bind(this)); - } - message = this.internalAPI.formatNotify(type, server, user, cName, message); this.internalAPI.notify(server, ops, message); From 8d9ef6365eb5b1f65276006062567b9fdee80293 Mon Sep 17 00:00:00 2001 From: Luke Slater Date: Fri, 5 Sep 2014 12:38:33 +0100 Subject: [PATCH 19/54] Update atheme.js --- modules/atheme/atheme.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/atheme/atheme.js b/modules/atheme/atheme.js index c57e287..d3d61f4 100644 --- a/modules/atheme/atheme.js +++ b/modules/atheme/atheme.js @@ -1,6 +1,6 @@ /** - * Module Name: charybdis - * Description: charybdis and atheme mode references + * Module Name: atheme + * Description: atheme mode references & retrieve channel flags */ var _ = require('underscore')._; From 64cdd374bce735804a6348ef7ac9d77bd2a03898 Mon Sep 17 00:00:00 2001 From: reality Date: Fri, 5 Sep 2014 12:06:10 +0000 Subject: [PATCH 20/54] fix profiles. also the fact it was getting all the users onLoad is probably a badthing --- modules/profile/api.js | 30 +++++++++++++++++++----------- modules/profile/profile.js | 18 ++---------------- modules/users/api.js | 2 +- 3 files changed, 22 insertions(+), 28 deletions(-) diff --git a/modules/profile/api.js b/modules/profile/api.js index 25a6c9c..b19a693 100644 --- a/modules/profile/api.js +++ b/modules/profile/api.js @@ -14,11 +14,7 @@ var api = function(dbot) { 'id': user.id, 'profile': this.config.schema.profile, 'preferences': this.config.schema.preferences - }, function(err, result){ - if(err){ - console.log(err); - } - }); + }, callback); } }, @@ -32,11 +28,17 @@ var api = function(dbot) { if(user){ this.db.read('profiles', user.id, function(err, profile){ if(!err){ - callback(false, user, profile); + if(profile) { + callback(false, user, profile); + } else { + this.api.createProfile(user, function(err, profile) { + callback(null, user, profile); + }); + } } else { callback(true, user, null); } - }); + }.bind(this)); } else{ callback(true, null, null); @@ -44,10 +46,16 @@ var api = function(dbot) { }.bind(this)); }, - 'getProfileByUUID': function(uuid, callback){ - this.db.read('profiles', uuid, function(err, profile){ - callback(profile); - }); + 'getProfileByUser': function(user, callback){ + this.db.read('profiles', user.id, function(err, profile){ + if(profile) { + callback(profile); + } else { + this.api.createProfile(user, function(err, profile) { + callback(profile); + }); + } + }.bind(this)); }, 'getAllProfiles': function(callback){ diff --git a/modules/profile/profile.js b/modules/profile/profile.js index c2f264c..9b9a6ef 100644 --- a/modules/profile/profile.js +++ b/modules/profile/profile.js @@ -5,30 +5,16 @@ var profile = function(dbot) { this.onLoad = function(){ var schema = this.config.schema; - // Ensure all users have a profile - dbot.api.users.getAllUsers(function(users){ - if(users){ - _.each(users, function(user){ - this.api.getProfileByUUID(user.id, function(err, uuid, profile){ - // If function returns an error and uuid, create a new profile - if(err && uuid){ - this.api.createProfile(user); - } - }.bind(this)); - }.bind(this)); - } - }.bind(this)); - // Add API Hooks dbot.api.event.addHook('new_user', this.api.createProfile); dbot.instance.addPreEmitHook(function(event, callback) { if(!event.rUser) return callback(); - this.api.getProfileByUUID(event.rUser.id, function(uProfile) { + this.api.getProfileByUser(event.rUser, function(uProfile) { if(uProfile) { event.rProfile = uProfile.profile; - callback(); } + callback(); }.bind(this)); }.bind(this)); diff --git a/modules/users/api.js b/modules/users/api.js index bbc171d..c35878e 100644 --- a/modules/users/api.js +++ b/modules/users/api.js @@ -44,7 +44,7 @@ var api = function(dbot) { } }); }, - + // Check if a nick is online under a given alias 'isOnline': function(server, channel, nick, callback) { this.api.resolveUser(server, nick, function(err, user) { From 64e7294233f13d56c2d941a1da8a3f5692a30871 Mon Sep 17 00:00:00 2001 From: reality Date: Fri, 5 Sep 2014 13:51:51 +0000 Subject: [PATCH 21/54] final fixes --- modules/profile/api.js | 1 + modules/warning/pages.js | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/modules/profile/api.js b/modules/profile/api.js index b19a693..781ce12 100644 --- a/modules/profile/api.js +++ b/modules/profile/api.js @@ -9,6 +9,7 @@ var api = function(dbot) { * TODO(@samstudio8) Migrate to internalAPI */ "createProfile": function(user, callback){ + if(!callback) callback = function(){}; if(user){ this.db.create('profiles', user.id, { 'id': user.id, diff --git a/modules/warning/pages.js b/modules/warning/pages.js index cb105fa..cb24623 100644 --- a/modules/warning/pages.js +++ b/modules/warning/pages.js @@ -22,7 +22,11 @@ var pages = function(dbot) { }, function(err) { async.eachSeries(userIds, function(id, callback) { dbot.api.users.getUser(id, function(err, user) { - userNicks.push(user.primaryNick); + if(user) { + userNicks.push(user.primaryNick); + } else { + userNicks.push(id); + } callback(false); }); }, function(err) { From 1d9765c95b6e75387f0d6c15437ad91661ead941 Mon Sep 17 00:00:00 2001 From: reality Date: Sat, 6 Sep 2014 12:01:32 +0000 Subject: [PATCH 22/54] correct user ids --- modules/report/api.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/report/api.js b/modules/report/api.js index 6586853..7cb78a1 100644 --- a/modules/report/api.js +++ b/modules/report/api.js @@ -53,7 +53,7 @@ var api = function(dbot) { this.pending[op.id].push({ 'time': new Date().getTime(), 'channel': cName, - 'user': op.id, + 'user': user.id, 'message': message }); this.pNotify[op.id] = true; From 57742d13f25621436a593fe7f22afdff30cea682 Mon Sep 17 00:00:00 2001 From: reality Date: Sat, 6 Sep 2014 18:43:26 +0000 Subject: [PATCH 23/54] fix flag regex --- modules/atheme/atheme.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/atheme/atheme.js b/modules/atheme/atheme.js index d3d61f4..1f87a83 100644 --- a/modules/atheme/atheme.js +++ b/modules/atheme/atheme.js @@ -53,7 +53,7 @@ var atheme = function(dbot) { this.listener = function(event) { if(event.user === 'ChanServ') { - var flags = event.params.match(/(\d+)\s+([^ ]+)\s+(\+\w+)\s+\((\#\w+)\)/), + var flags = event.params.match(/(\d+)\s+([^ ]+)\s+(\+\w+)\s+\((\#[\w\.]+)\)/), end = event.params.match(/end of \u0002(\#\w+)\u0002 flags listing/i); if(flags && _.has(this.flagStack[event.server], flags[4])) { From 63ded5b1972958ef34f5ff656d3f9e5637147ac7 Mon Sep 17 00:00:00 2001 From: reality Date: Mon, 8 Sep 2014 10:41:09 +0000 Subject: [PATCH 24/54] that should do it --- modules/quotes/quotes.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/modules/quotes/quotes.js b/modules/quotes/quotes.js index 004d4a0..66d565f 100644 --- a/modules/quotes/quotes.js +++ b/modules/quotes/quotes.js @@ -16,11 +16,14 @@ var quotes = function(dbot) { if(quoteRefs) { var ref = this.internalAPI.cleanRef(quoteRefs[0].replace(/^~~/,'').replace(/~~$/,'').trim()); if(ref === '-nicks-') { - dbot.api.users.getRandomChannelUser(server, channel, function(user) { - quote = quote.replace('~~' + ref + '~~', user); + if(_.has(dbot.instance.connections[server].channels, channel)) { + var nicks = + _.keys(dbot.instance.connections[server].channels[channel].nicks); + var randomUser = nicks[_.random(0, nicks.length -1)]; + quote = quote.replace('~~' + ref + '~~', randomUser); this.internalAPI.interpolatedQuote(server, channel, username, key, quote, callback); - }.bind(this)); + } } else if(ref === '-nick-') { quote = quote.replace('~~' + ref + '~~', username); this.internalAPI.interpolatedQuote(server, channel, From 03bab4e7dba658654ab276efae28fe13e4f0ea9a Mon Sep 17 00:00:00 2001 From: Luke Slater Date: Mon, 8 Sep 2014 10:42:59 +0000 Subject: [PATCH 25/54] some fixes --- modules/atheme/atheme.js | 2 +- modules/lastfm/lastfm.js | 2 +- modules/quotes/strings.json | 2 +- modules/users/commands.js | 2 +- modules/users/users.js | 2 +- modules/web/api.js | 2 ++ 6 files changed, 7 insertions(+), 5 deletions(-) diff --git a/modules/atheme/atheme.js b/modules/atheme/atheme.js index 1f87a83..ba8ddcd 100644 --- a/modules/atheme/atheme.js +++ b/modules/atheme/atheme.js @@ -54,7 +54,7 @@ var atheme = function(dbot) { this.listener = function(event) { if(event.user === 'ChanServ') { var flags = event.params.match(/(\d+)\s+([^ ]+)\s+(\+\w+)\s+\((\#[\w\.]+)\)/), - end = event.params.match(/end of \u0002(\#\w+)\u0002 flags listing/i); + end = event.params.match(/end of \u0002(\#[\w\.]+)\u0002 flags listing/i); if(flags && _.has(this.flagStack[event.server], flags[4])) { this.flagStack[event.server][flags[4]].flags[flags[2]] = flags[3]; diff --git a/modules/lastfm/lastfm.js b/modules/lastfm/lastfm.js index 77b7f8a..e0ab247 100644 --- a/modules/lastfm/lastfm.js +++ b/modules/lastfm/lastfm.js @@ -15,7 +15,7 @@ var lastfm = function(dbot) { 'getLastFM': function(server, nick, callback) { dbot.api.profile.getProfile(server, nick, function(err, user, profile) { if(user) { - if(profile && _.has(profile.profile, 'lastfm')) { + if(profile && _.has(profile.profile, 'lastfm') && _.isString(profile.profile.lastfm)) { callback(user, profile.profile.lastfm.toLowerCase()); } else { callback(user, null); diff --git a/modules/quotes/strings.json b/modules/quotes/strings.json index b489fc0..9feaaa2 100644 --- a/modules/quotes/strings.json +++ b/modules/quotes/strings.json @@ -1,6 +1,6 @@ { "category_not_found": { - "en": "Nobody loves {category}", + "en": "Everyone is rather ambivalent towards the matter of {category}", "es": "Nadie ama a {category}", "na'vi": "{category} yawne ke lu kawturu.", "cy": "Does neb yn caru {category}", diff --git a/modules/users/commands.js b/modules/users/commands.js index 0bfcb14..8c914c0 100644 --- a/modules/users/commands.js +++ b/modules/users/commands.js @@ -97,7 +97,7 @@ var commands = function(dbot) { } else { event.reply(dbot.t('unknown_alias', { 'alias': nick })); } - }); + }.bind(this)); }, '~mergeusers': function(event) { diff --git a/modules/users/users.js b/modules/users/users.js index c6de710..0656b23 100644 --- a/modules/users/users.js +++ b/modules/users/users.js @@ -44,7 +44,7 @@ var users = function(dbot) { }.bind(this), // Remove an alias record - 'removeAlias': function(server, alias) { + 'removeAlias': function(server, alias, callback) { var id = alias + '.' + server; this.db.del('user_aliases', id, function(err) { callback(err); diff --git a/modules/web/api.js b/modules/web/api.js index 1d02a77..79680ed 100644 --- a/modules/web/api.js +++ b/modules/web/api.js @@ -1,3 +1,5 @@ +var _ = require('underscore')._; + var api = function(dbot) { return { 'getUrl': function(path) { From a49652604974cd54cd3db5206f41d8b47d53ff4a Mon Sep 17 00:00:00 2001 From: reality Date: Mon, 8 Sep 2014 21:02:10 +0000 Subject: [PATCH 26/54] fix ignore behaviour with command/module clash --- modules/ignore/ignore.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ignore/ignore.js b/modules/ignore/ignore.js index 46c43f9..7646ad5 100644 --- a/modules/ignore/ignore.js +++ b/modules/ignore/ignore.js @@ -16,7 +16,7 @@ var ignore = function(dbot) { this.api.getUserIgnores(user, function(err, ignores) { var isImpeded = false; if(!err && ignores) { - if(_.has(dbot.commands, item)) { + if(_.has(dbot.commands, item) && !_.include(ignores[by], item)) { item = dbot.commands[item].module; } if(_.include(ignores[by], item)) { From 402c8e80f4d9f2b5ce6a808a44ad9b750c781fbc Mon Sep 17 00:00:00 2001 From: reality Date: Mon, 8 Sep 2014 21:08:28 +0000 Subject: [PATCH 27/54] missing err in readUser on reload ignore repopulation --- modules/ignore/ignore.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ignore/ignore.js b/modules/ignore/ignore.js index 7646ad5..8b25814 100644 --- a/modules/ignore/ignore.js +++ b/modules/ignore/ignore.js @@ -273,7 +273,7 @@ var ignore = function(dbot) { dbot.instance.clearIgnores(); this.db.scan('ignores', function(ignores) { - dbot.api.users.getUser(ignores.id, function(user) { + dbot.api.users.getUser(ignores.id, function(err, user) { if(user) { _.each(ignores.ignores, function(module) { dbot.instance.ignoreTag(user.currentNick, module); From 77d99970096a6119b3e37de8476bc39736bfb4bf Mon Sep 17 00:00:00 2001 From: reality Date: Tue, 9 Sep 2014 09:52:45 +0000 Subject: [PATCH 28/54] fix nickstealing --- modules/users/users.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/users/users.js b/modules/users/users.js index 0656b23..214603f 100644 --- a/modules/users/users.js +++ b/modules/users/users.js @@ -107,10 +107,12 @@ var users = function(dbot) { // Update current nick this.api.resolveUser(event.server, event.user, function(err, user) { if(user) { - this.internalAPI.updateCurrentNick(user, event.newNick, function(){}); this.api.resolveUser(event.server, event.newNick, function(err, eUser) { if(!eUser) { this.internalAPI.createAlias(event.newNick, user, function(){}); + this.internalAPI.updateCurrentNick(user, event.newNick, function(){}); + } else if(user.id === eUser.id) { + this.internalAPI.updateCurrentNick(user, event.newNick, function(){}); } }.bind(this)); } From 9a7827448d4cf236cc978ff9fcd4817f593da680 Mon Sep 17 00:00:00 2001 From: reality Date: Fri, 12 Sep 2014 14:52:45 +0000 Subject: [PATCH 29/54] fix flashy --- views/flashy/flashy.jade | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/views/flashy/flashy.jade b/views/flashy/flashy.jade index ba7271b..7aa7d20 100644 --- a/views/flashy/flashy.jade +++ b/views/flashy/flashy.jade @@ -1,4 +1,4 @@ -!!! 5 +doctype html html(lang='en') head meta(charset='utf-8') From ac603c3b9c7462cb4c17699904985ca39b5b4a51 Mon Sep 17 00:00:00 2001 From: reality Date: Fri, 12 Sep 2014 14:53:41 +0000 Subject: [PATCH 30/54] alignment is important mmkay? --- views/flashy/flashy.jade | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/views/flashy/flashy.jade b/views/flashy/flashy.jade index 7aa7d20..76558c6 100644 --- a/views/flashy/flashy.jade +++ b/views/flashy/flashy.jade @@ -8,4 +8,4 @@ html(lang='en') div.container blink [ span.flash(style='color: #'+colour+';') #{text} - ] + ] From b660d9ce217fe7458a118dcf9847b34bfb906c25 Mon Sep 17 00:00:00 2001 From: reality Date: Fri, 12 Sep 2014 14:56:34 +0000 Subject: [PATCH 31/54] ok --- views/flashy/flashy.jade | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/views/flashy/flashy.jade b/views/flashy/flashy.jade index 76558c6..232b3c3 100644 --- a/views/flashy/flashy.jade +++ b/views/flashy/flashy.jade @@ -6,6 +6,4 @@ html(lang='en') title #{name} web interface body div.container - blink [ - span.flash(style='color: #'+colour+';') #{text} - ] + blink [ span.flash(style='color: #'+colour+';') #{text} span ] From 0ebdb2dbde00e332e48a866e6a74357111bcb614 Mon Sep 17 00:00:00 2001 From: reality Date: Sat, 13 Sep 2014 19:23:00 +0000 Subject: [PATCH 32/54] put udp bind in onload so it has this --- modules/udp/udp.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/udp/udp.js b/modules/udp/udp.js index 52caac6..6a4b5a7 100644 --- a/modules/udp/udp.js +++ b/modules/udp/udp.js @@ -14,7 +14,9 @@ var udp = function(dbot) { dbot.say(this.config.server, this.config.channel, message); } }.bind(this)); - server.bind(this.config.port); + this.onLoad = function() { + server.bind(this.config.port); + }.bind(this); }; exports.fetch = function(dbot) { From 2570eb99a6bb8b42e9279ac09cd6355adfa60444 Mon Sep 17 00:00:00 2001 From: reality Date: Sat, 13 Sep 2014 19:40:59 +0000 Subject: [PATCH 33/54] remove tilde prefix for command usage --- run.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/run.js b/run.js index deaefa3..e8af57e 100644 --- a/run.js +++ b/run.js @@ -329,6 +329,14 @@ DBot.prototype.reloadModules = function() { this.commands[cName.substring(1)] = command; } }, this); + + _.each(this.usage, function(command, cName) { + if(cName.charAt(0) == '~') { + delete this.usage[cName]; + this.usage[cName.substring(1)] = command; + } + }, this); + }.bind(this)); this.save(); From e3a6f5353735dab6a2a4103584a6bb437c0969ff Mon Sep 17 00:00:00 2001 From: reality Date: Sat, 13 Sep 2014 19:48:28 +0000 Subject: [PATCH 34/54] regex for usage --- modules/command/commands.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/modules/command/commands.js b/modules/command/commands.js index b5860cc..d5d5bbb 100644 --- a/modules/command/commands.js +++ b/modules/command/commands.js @@ -2,7 +2,7 @@ var _ = require('underscore')._, request = require('request'); var commands = function(dbot) { - return { + var commands = { 'usage': function(event) { var commandName = event.params[1]; if(_.has(dbot.usage, commandName)) { @@ -60,6 +60,9 @@ var commands = function(dbot) { } } }; + commands['usage'].regex = [/usage ([^ ]+)/, 2]; + + return commands; }; exports.fetch = function(dbot) { From 2660995aeef8475486006cb7af86b4c38ae78e3c Mon Sep 17 00:00:00 2001 From: reality Date: Sat, 13 Sep 2014 19:52:01 +0000 Subject: [PATCH 35/54] usage for crypto --- modules/crypto/usage.json | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 modules/crypto/usage.json diff --git a/modules/crypto/usage.json b/modules/crypto/usage.json new file mode 100644 index 0000000..bbec8f2 --- /dev/null +++ b/modules/crypto/usage.json @@ -0,0 +1,6 @@ +{ + "~md5": "~md5 [text]", + "~sha1": "~sha1 [text]", + "~sha256": "~sha256 [text]", + "~aes": "~aes \"[text]\" \"[key]\"" +} From 5560f967440cdb05f81de77026aadfee56b92616 Mon Sep 17 00:00:00 2001 From: reality Date: Sun, 14 Sep 2014 19:02:45 +0000 Subject: [PATCH 36/54] get users with given vhost --- modules/atheme/atheme.js | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/modules/atheme/atheme.js b/modules/atheme/atheme.js index ba8ddcd..fc81d76 100644 --- a/modules/atheme/atheme.js +++ b/modules/atheme/atheme.js @@ -6,6 +6,7 @@ var _ = require('underscore')._; var atheme = function(dbot) { this.flagStack = {}; + this.hostStack = {}; this.api = { 'getChannelFlags': function(server, channel, callback) { @@ -28,6 +29,28 @@ var atheme = function(dbot) { delete this.flagStack[server][channel]; } }.bind(this), 10000); + }, + + 'getVHosts': function(server, mask, callback) { + if(!_.has(this.hostStack, server)) this.hostStack[server] = {}; + if(_.has(this.hostStack[server], mask)) { // Already an active host call + this.hostStack[server][channel].callbacks.push(callback); + } else { + this.hostStack[server][mask] = { + 'users': [], + 'callbacks': [ callback ] + }; + } + + dbot.say(server, 'hostserv', 'LISTVHOST ' + mask); + setTimeout(function() { // Delete callback if no response + if(_.has(this.hostStack[server], mask)) { + _.each(this.hostStack[server][mask].callbacks, function(callback) { + callback(true, null); + }); + delete this.hostStack[server][mask]; + } + }.bind(this), 10000); } }; @@ -66,6 +89,22 @@ var atheme = function(dbot) { delete this.flagStack[event.server][end[1]]; } } + } else if(event.user === 'HostServ') { + _.each(this.hostStack[event.server], function(el, mask) { + if(event.params.match(mask)) { + var user = event.params.match(/- ([^ ]+)/), + end = event.params.match(/matches for pattern/); + + if(user) { + this.hostStack[event.server][mask].users.push(user[1]); + } else if(end) { + _.each(this.hostStack[event.server][mask].callbacks, function(callback) { + callback(null, this.hostStack[event.server][mask].users); + }, this); + delete this.hostStack[event.server][mask]; + } + } + }, this); } }.bind(this); this.on = 'NOTICE'; From 83e5a3567775a44166884d54705edc79177ed351 Mon Sep 17 00:00:00 2001 From: reality Date: Sun, 14 Sep 2014 19:31:22 +0000 Subject: [PATCH 37/54] expand flags from hosts --- modules/atheme/atheme.js | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/modules/atheme/atheme.js b/modules/atheme/atheme.js index fc81d76..f76fe3d 100644 --- a/modules/atheme/atheme.js +++ b/modules/atheme/atheme.js @@ -2,7 +2,8 @@ * Module Name: atheme * Description: atheme mode references & retrieve channel flags */ -var _ = require('underscore')._; +var _ = require('underscore')._, + async = require('async'); var atheme = function(dbot) { this.flagStack = {}; @@ -28,7 +29,7 @@ var atheme = function(dbot) { }); delete this.flagStack[server][channel]; } - }.bind(this), 10000); + }.bind(this), 20000); }, 'getVHosts': function(server, mask, callback) { @@ -50,7 +51,7 @@ var atheme = function(dbot) { }); delete this.hostStack[server][mask]; } - }.bind(this), 10000); + }.bind(this), 2000); } }; @@ -83,10 +84,31 @@ var atheme = function(dbot) { this.flagStack[event.server][flags[4]].flags[flags[2]] = flags[3]; } else if(end) { if(_.has(this.flagStack[event.server], end[1])) { - _.each(this.flagStack[event.server][end[1]].callbacks, function(callback) { - callback(null, this.flagStack[event.server][end[1]].flags); + // Parse wildcard hostmasks to nicks + var allFlags = this.flagStack[event.server][end[1]].flags, + hostMasks = {}; + + _.each(allFlags, function(f, u) { // TODO: combine to one loop + if(u.indexOf('*!*@') !== -1) { + hostMasks[u] = f; + delete allFlags[u]; + } + }); + + async.each(_.keys(hostMasks), function(hostMask, done) { + this.api.getVHosts(event.server, hostMask.split('@')[1], function(err, users) { + _.each(users, function(user) { + allFlags[user] = hostMasks[hostMask]; + }); + done(); + }); + }.bind(this), function() { + console.log('DONE'); + _.each(this.flagStack[event.server][end[1]].callbacks, function(callback) { + callback(null, this.flagStack[event.server][end[1]].flags); + }.bind(this)); + delete this.flagStack[event.server][end[1]]; }.bind(this)); - delete this.flagStack[event.server][end[1]]; } } } else if(event.user === 'HostServ') { From 84ddfb90a61c10f225181d24d174b7b9f4093839 Mon Sep 17 00:00:00 2001 From: reality Date: Mon, 15 Sep 2014 21:12:30 +0000 Subject: [PATCH 38/54] repair nunsub --- modules/report/api.js | 71 ++++++++++++++++++------------- modules/report/commands.js | 86 +++++++++++++++++++------------------- 2 files changed, 83 insertions(+), 74 deletions(-) diff --git a/modules/report/api.js b/modules/report/api.js index 7cb78a1..bd64206 100644 --- a/modules/report/api.js +++ b/modules/report/api.js @@ -36,37 +36,48 @@ var api = function(dbot) { } }.bind(this)); - var offlineOps = {}; - async.each(ops, function(op, done) { - dbot.api.users.isOnline(server, cName, op, function(err, user, online) { - if(!err && !online) offlineOps[op] = user; - if(user.currentNick !== op) { - ops = _.without(ops, op); - ops.push(user.currentNick); - } - done(); - }); - }, function() { - // Queue notifies for offline ops - _.each(offlineOps, function(op) { - if(!this.pending[op.id]) this.pending[op.id] = []; - this.pending[op.id].push({ - 'time': new Date().getTime(), - 'channel': cName, - 'user': user.id, - 'message': message + this.db.read('nunsubs', cName + '.' + server, function(err, nunsubs) { + if(nunsubs) { + _.each(nunsubs.users, function(user) { + var uPart = user.split('.')[0]; + if(_.include(ops, uPart)) { + ops = _.without(ops, uPart); + } }); - this.pNotify[op.id] = true; - }, this); - - // Send notifies to online ops - ops = _.difference(ops, _.keys(offlineOps)); - message = this.internalAPI.formatNotify(type, server, - user, cName, message); - this.internalAPI.notify(server, ops, message); - if(_.has(this.config.chan_redirs, cName)) { - dbot.say(server, this.config.chan_redirs[cName], message); } + + var offlineOps = {}; + async.each(ops, function(op, done) { + dbot.api.users.isOnline(server, cName, op, function(err, user, online) { + if(!err && !online) offlineOps[op] = user; + if(user.currentNick !== op) { + ops = _.without(ops, op); + ops.push(user.currentNick); + } + done(); + }); + }, function() { + // Queue notifies for offline ops + _.each(offlineOps, function(op) { + if(!this.pending[op.id]) this.pending[op.id] = []; + this.pending[op.id].push({ + 'time': new Date().getTime(), + 'channel': cName, + 'user': user.id, + 'message': message + }); + this.pNotify[op.id] = true; + }, this); + + // Send notifies to online ops + ops = _.difference(ops, _.keys(offlineOps)); + message = this.internalAPI.formatNotify(type, server, + user, cName, message); + this.internalAPI.notify(server, ops, message); + if(_.has(this.config.chan_redirs, cName)) { + dbot.say(server, this.config.chan_redirs[cName], message); + } + }.bind(this)); }.bind(this)); }.bind(this)); } else { @@ -85,7 +96,7 @@ var api = function(dbot) { var perOps = channel.op; if(this.config.notifyVoice) perOps = _.union(perOps, channel.voice); - this.db.read('nunsubs', channel.id, function(err, nunsubs) { + this.db.read('nunsubs', cName + '.' + server, function(err, nunsubs) { async.eachSeries(ops, function(nick, next) { dbot.api.users.resolveUser(server, nick, function(user) { if(nunsubs && _.include(nunsubs.users, user.id)) { diff --git a/modules/report/commands.js b/modules/report/commands.js index c6b358e..d5d28e7 100644 --- a/modules/report/commands.js +++ b/modules/report/commands.js @@ -139,56 +139,54 @@ var commands = function(dbot) { }, '~nunsub': function(event) { - var cName = event.input[1]; + var cName = event.input[1], + cId = event.input[1] + '.' + event.server; - dbot.api.users.resolveChannel(event.server, cName, function(channel) { - if(channel) { - this.db.read('nunsubs', channel.id, function(err, nunsubs) { - if(!nunsubs) { - var nunsubs = { - 'id': channel.id, - 'users': [] - } - } - - if(!_.include(nunsubs, event.rUser.id)) { - nunsubs.users.push(event.rUser.id); - this.db.save('nunsubs', channel.id, nunsubs, function() { - var reply = dbot.t('nunsubbed', { 'cName': cName }) - if(_.has(this.config.chan_redirs, cName)) { - reply += dbot.t('n_also_found', { 'afaName' : this.config.chan_redirs[cName] }); - } - event.reply(reply); - }.bind(this)); - } else { - event.reply(dbot.t('already_nunsubbed', { 'cName': cName })); + if(_.has(dbot.instance.connections[event.server].channels, cName)) { + this.db.read('nunsubs', cId, function(err, nunsubs) { + if(!nunsubs) { + var nunsubs = { + 'id': cId, + 'users': [] } - }.bind(this)); - } else { - event.reply('Channel not known.'); - } - }.bind(this)); + } + + if(!_.include(nunsubs, event.rUser.id)) { + nunsubs.users.push(event.rUser.id); + this.db.save('nunsubs', cId, nunsubs, function() { + var reply = dbot.t('nunsubbed', { 'cName': cName }) + if(_.has(this.config.chan_redirs, cName)) { + reply += dbot.t('n_also_found', { 'afaName' : this.config.chan_redirs[cName] }); + } + event.reply(reply); + }.bind(this)); + } else { + event.reply(dbot.t('already_nunsubbed', { 'cName': cName })); + } + }.bind(this)); + } else { + event.reply('Channel not known.'); + } }, '~ununsub': function(event) { - var cName = event.input[1]; + var cName = event.input[1], + cId = event.input[1] + '.' + event.server; - dbot.api.users.resolveChannel(event.server, cName, function(channel) { - if(channel) { - this.db.read('nunsubs', channel.id, function(err, nunsubs) { - if(!_.isUndefined(nunsubs) && _.include(nunsubs.users, event.rUser.id)) { - nunsubs.users = _.without(nunsubs.users, event.rUser.id); - this.db.save('nunsubs', channel.id, nunsubs, function() { - event.reply(dbot.t('ununsubbed', { 'cName': cName })); - }); - } else { - event.reply(dbot.t('not_nunsubbed', { 'cName': cName })); - } - }.bind(this)); - } else { - event.reply('Channel not known.'); - } - }.bind(this)); + if(_.has(dbot.instance.connections[event.server].channels, cName)) { + this.db.read('nunsubs', cId, function(err, nunsubs) { + if(!_.isUndefined(nunsubs) && _.include(nunsubs.users, event.rUser.id)) { + nunsubs.users = _.without(nunsubs.users, event.rUser.id); + this.db.save('nunsubs', cId, nunsubs, function() { + event.reply(dbot.t('ununsubbed', { 'cName': cName })); + }); + } else { + event.reply(dbot.t('not_nunsubbed', { 'cName': cName })); + } + }.bind(this)); + } else { + event.reply('Channel not known.'); + } } }; commands['~report'].regex = /^report (#[^ ]+ )?([^ ]+) (.*)$/; From d184a251e43e3855bd2950155013d6b350263b07 Mon Sep 17 00:00:00 2001 From: Luke Slater Date: Mon, 15 Sep 2014 21:19:41 +0000 Subject: [PATCH 39/54] whoops --- jsbot | 2 +- modules/atheme/atheme.js | 3 ++- modules/report/api.js | 2 +- modules/users/api.js | 3 +++ 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/jsbot b/jsbot index 606d0cd..139a3aa 160000 --- a/jsbot +++ b/jsbot @@ -1 +1 @@ -Subproject commit 606d0cdcddfda9d7328cfa0b65bb4a3079d77d9e +Subproject commit 139a3aad5a8b5c71dfe43fdc3f04d29d8b4104df diff --git a/modules/atheme/atheme.js b/modules/atheme/atheme.js index f76fe3d..b315414 100644 --- a/modules/atheme/atheme.js +++ b/modules/atheme/atheme.js @@ -51,7 +51,7 @@ var atheme = function(dbot) { }); delete this.hostStack[server][mask]; } - }.bind(this), 2000); + }.bind(this), 5000); } }; @@ -104,6 +104,7 @@ var atheme = function(dbot) { }); }.bind(this), function() { console.log('DONE'); +console.log(allFlags); _.each(this.flagStack[event.server][end[1]].callbacks, function(callback) { callback(null, this.flagStack[event.server][end[1]].flags); }.bind(this)); diff --git a/modules/report/api.js b/modules/report/api.js index 7cb78a1..e8cf9ae 100644 --- a/modules/report/api.js +++ b/modules/report/api.js @@ -40,7 +40,7 @@ var api = function(dbot) { async.each(ops, function(op, done) { dbot.api.users.isOnline(server, cName, op, function(err, user, online) { if(!err && !online) offlineOps[op] = user; - if(user.currentNick !== op) { + if(user && user.currentNick !== op) { ops = _.without(ops, op); ops.push(user.currentNick); } diff --git a/modules/users/api.js b/modules/users/api.js index c35878e..b9368bc 100644 --- a/modules/users/api.js +++ b/modules/users/api.js @@ -66,6 +66,9 @@ var api = function(dbot) { } }; + api['getUserAliases'].external = true; + api['getUserAliases'].extMap = [ 'id', 'callback' ]; + return api; }; From e1732ff26a46fddda053fde3756480c78b71c26c Mon Sep 17 00:00:00 2001 From: reality Date: Thu, 18 Sep 2014 03:29:20 +0000 Subject: [PATCH 40/54] blah --- modules/radio/radio.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/radio/radio.js b/modules/radio/radio.js index b46f73d..b98e484 100644 --- a/modules/radio/radio.js +++ b/modules/radio/radio.js @@ -32,7 +32,7 @@ var radio = function(dbot) { stream.on('metadata', function(metadata) { var title = icecast.parseMetadata(metadata).StreamTitle; - if(title != 'undefined') { // sowwy jesus + if(!_.isUndefined(title)) { // sowwy jesus _.each(this.config.announce, function(a) { dbot.say(a.server, a.name, dbot.t('now_playing', { 'name': this.data['icy-name'], From 6b5214124563bb0cadb592fab3c8ba70dd294bf5 Mon Sep 17 00:00:00 2001 From: reality Date: Thu, 18 Sep 2014 03:31:59 +0000 Subject: [PATCH 41/54] try again --- modules/radio/radio.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/radio/radio.js b/modules/radio/radio.js index b98e484..50428d7 100644 --- a/modules/radio/radio.js +++ b/modules/radio/radio.js @@ -32,7 +32,7 @@ var radio = function(dbot) { stream.on('metadata', function(metadata) { var title = icecast.parseMetadata(metadata).StreamTitle; - if(!_.isUndefined(title)) { // sowwy jesus + if(!_.isUndefined(title) && this.data['icy-name']) { // sowwy jesus _.each(this.config.announce, function(a) { dbot.say(a.server, a.name, dbot.t('now_playing', { 'name': this.data['icy-name'], From 9733fa6185fafa724651302d70915edc8bae1540 Mon Sep 17 00:00:00 2001 From: reality Date: Thu, 18 Sep 2014 03:33:40 +0000 Subject: [PATCH 42/54] pls --- modules/radio/radio.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/modules/radio/radio.js b/modules/radio/radio.js index 50428d7..d2239c0 100644 --- a/modules/radio/radio.js +++ b/modules/radio/radio.js @@ -21,13 +21,15 @@ var radio = function(dbot) { stream.on('response', function(res) { this.data = res.headers; - _.each(this.config.announce, function(a) { - dbot.say(a.server, a.name, dbot.t('now_online', { - 'name': res.headers['icy-name'], - 'desc': res.headers['icy-description'], - 'url': res.headers['icy-url'] - })); - }); + if(res.headers['icy-name']) { + _.each(this.config.announce, function(a) { + dbot.say(a.server, a.name, dbot.t('now_online', { + 'name': res.headers['icy-name'], + 'desc': res.headers['icy-description'], + 'url': res.headers['icy-url'] + })); + }); + } }.bind(this)); stream.on('metadata', function(metadata) { From fb3ddf2da8fd5bff23dec08474746f002de3ac42 Mon Sep 17 00:00:00 2001 From: Luke Slater Date: Sun, 28 Sep 2014 18:48:36 +0100 Subject: [PATCH 43/54] Update commands.js --- modules/quotes/commands.js | 51 +++++++++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 15 deletions(-) diff --git a/modules/quotes/commands.js b/modules/quotes/commands.js index 3821a82..8448ba2 100644 --- a/modules/quotes/commands.js +++ b/modules/quotes/commands.js @@ -14,11 +14,18 @@ var commands = function(dbot) { this.api.addQuote(key, quote, event.user, function(newCount) { if(newCount) { dbot.api.event.emit('~qadd', [ key, quote ]); - event.reply(dbot.t('quote_saved', { - 'category': key, - 'count': newCount, - 'link': dbot.api.web.getUrl('quotes/' + encodeURIComponent(key)) - })); + if(_.has(dbot.modules, 'web')) { + event.reply(dbot.t('quote_saved', { + 'category': key, + 'count': newCount, + 'link': dbot.api.web.getUrl('quotes/' + encodeURIComponent(key)) + })); + } else { + event.reply(dbot.t('quote_saved', { + 'category': key, + 'count': newCount + })); + } } else { event.reply(dbot.t('quote_exists')); } @@ -103,11 +110,18 @@ var commands = function(dbot) { removedQuote; var quoteRemoved = function(err) { this.internalAPI.resetRemoveTimer(event, key, removedQuote); - event.reply(dbot.t('removed_from', { - 'quote': removedQuote, - 'category': key, - 'link': dbot.api.web.getUrl('quotes/' + encodeURIComponent(key)) - })); + if(_.has(dbot.modules, 'web')) { + event.reply(dbot.t('removed_from', { + 'quote': removedQuote, + 'category': key, + 'link': dbot.api.web.getUrl('quotes/' + encodeURIComponent(key)) + })); + } else { + event.reply(dbot.t('removed_from', { + 'quote': removedQuote, + 'category': key + })); + } }.bind(this); this.db.search('quote_category', { 'name': key }, function(result) { @@ -137,11 +151,18 @@ var commands = function(dbot) { category = false; var quoteRemoved = function(err) { this.internalAPI.resetRemoveTimer(event, key, quote); - event.reply(dbot.t('removed_from', { - 'category': key, - 'quote': quote, - 'link': dbot.api.web.getUrl('quotes/' + encodeURIComponent(key)) - })); + if(_.has(dbot.modules, 'web')) { + event.reply(dbot.t('removed_from', { + 'category': key, + 'quote': quote, + 'link': dbot.api.web.getUrl('quotes/' + encodeURIComponent(key)) + })); + } else { + event.reply(dbot.t('removed_from', { + 'category': key, + 'quote': quote + })); + } }.bind(this); this.db.search('quote_category', { 'name': key }, function(result) { From 6d8224bdf12240160a40f64e767dff7b4afe5799 Mon Sep 17 00:00:00 2001 From: reality Date: Wed, 1 Oct 2014 00:28:32 +0000 Subject: [PATCH 44/54] leafly --- modules/leafly/config.json | 5 ++++ modules/leafly/leafly.js | 47 +++++++++++++++++++++++++++++++++++++ modules/leafly/strings.json | 8 +++++++ 3 files changed, 60 insertions(+) create mode 100644 modules/leafly/config.json create mode 100644 modules/leafly/leafly.js create mode 100644 modules/leafly/strings.json diff --git a/modules/leafly/config.json b/modules/leafly/config.json new file mode 100644 index 0000000..8cbabb5 --- /dev/null +++ b/modules/leafly/config.json @@ -0,0 +1,5 @@ +{ + "outputPrefix": "\u00033weed\u000f", + "app_key": "", + "app_id": "" +} diff --git a/modules/leafly/leafly.js b/modules/leafly/leafly.js new file mode 100644 index 0000000..22c4929 --- /dev/null +++ b/modules/leafly/leafly.js @@ -0,0 +1,47 @@ +/** + * Module name: Leafly + * Description: Information from leafly + */ + +var _ = require('underscore')._, + request = require('request'); + +var leafly = function(dbot) { + var ApiRoot = 'http://data.leafly.com/'; + + this.commands = { + '~strain': function(event) { + request.post(ApiRoot + 'strains', { + 'headers': { + 'app_key': this.config.app_key, + 'app_id': this.config.app_id + }, + 'body': { + 'page': 0, + 'take': 1, + 'sort': 'rating', + 'search': event.input[1] + }, + 'json': true + }, function(error, response, body) { + if(_.isObject(body) && _.has(body, 'Strains') && body.Strains.length > 0) { + var strain = body.Strains[0], + flavours = _.pluck(strain.Flavors, 'Name').join(', '); + + event.reply(dbot.t('strain', { + 'name': strain.Name, + 'flavours': flavours, + 'link': strain.permalink + })); + } else { + event.reply(dbot.t('no_strains')); + } + }.bind(this)); + } + }; + this.commands['~strain'].regex = [/^strain (.+)$/, 2]; +}; + +exports.fetch = function(dbot) { + return new leafly(dbot); +}; diff --git a/modules/leafly/strings.json b/modules/leafly/strings.json new file mode 100644 index 0000000..9494b80 --- /dev/null +++ b/modules/leafly/strings.json @@ -0,0 +1,8 @@ +{ + "strain": { + "en": "{name} tastes of {flavours} - {link}" + }, + "no_strains": { + "en": "No strains found :(" + } +} From a7ccb5ff1449824925eff133fe9b62913b47eba9 Mon Sep 17 00:00:00 2001 From: reality Date: Fri, 3 Oct 2014 20:42:41 +0000 Subject: [PATCH 45/54] akill --- modules/atheme/atheme.js | 104 ++++++++++++++++++++++----------------- 1 file changed, 58 insertions(+), 46 deletions(-) diff --git a/modules/atheme/atheme.js b/modules/atheme/atheme.js index f76fe3d..c421689 100644 --- a/modules/atheme/atheme.js +++ b/modules/atheme/atheme.js @@ -76,60 +76,72 @@ var atheme = function(dbot) { this.commands['~chanmode'].regex = [/^chanmode (\+.)/, 2]; this.listener = function(event) { - if(event.user === 'ChanServ') { - var flags = event.params.match(/(\d+)\s+([^ ]+)\s+(\+\w+)\s+\((\#[\w\.]+)\)/), - end = event.params.match(/end of \u0002(\#[\w\.]+)\u0002 flags listing/i); + if(event.action === 'NOTICE') { + if(event.user === 'ChanServ') { + var flags = event.params.match(/(\d+)\s+([^ ]+)\s+(\+\w+)\s+\((\#[\w\.]+)\)/), + end = event.params.match(/end of \u0002(\#[\w\.]+)\u0002 flags listing/i); - if(flags && _.has(this.flagStack[event.server], flags[4])) { - this.flagStack[event.server][flags[4]].flags[flags[2]] = flags[3]; - } else if(end) { - if(_.has(this.flagStack[event.server], end[1])) { - // Parse wildcard hostmasks to nicks - var allFlags = this.flagStack[event.server][end[1]].flags, - hostMasks = {}; + if(flags && _.has(this.flagStack[event.server], flags[4])) { + this.flagStack[event.server][flags[4]].flags[flags[2]] = flags[3]; + } else if(end) { + if(_.has(this.flagStack[event.server], end[1])) { + // Parse wildcard hostmasks to nicks + var allFlags = this.flagStack[event.server][end[1]].flags, + hostMasks = {}; - _.each(allFlags, function(f, u) { // TODO: combine to one loop - if(u.indexOf('*!*@') !== -1) { - hostMasks[u] = f; - delete allFlags[u]; - } - }); - - async.each(_.keys(hostMasks), function(hostMask, done) { - this.api.getVHosts(event.server, hostMask.split('@')[1], function(err, users) { - _.each(users, function(user) { - allFlags[user] = hostMasks[hostMask]; - }); - done(); + _.each(allFlags, function(f, u) { // TODO: combine to one loop + if(u.indexOf('*!*@') !== -1) { + hostMasks[u] = f; + delete allFlags[u]; + } }); - }.bind(this), function() { - console.log('DONE'); - _.each(this.flagStack[event.server][end[1]].callbacks, function(callback) { - callback(null, this.flagStack[event.server][end[1]].flags); - }.bind(this)); - delete this.flagStack[event.server][end[1]]; - }.bind(this)); - } - } - } else if(event.user === 'HostServ') { - _.each(this.hostStack[event.server], function(el, mask) { - if(event.params.match(mask)) { - var user = event.params.match(/- ([^ ]+)/), - end = event.params.match(/matches for pattern/); - if(user) { - this.hostStack[event.server][mask].users.push(user[1]); - } else if(end) { - _.each(this.hostStack[event.server][mask].callbacks, function(callback) { - callback(null, this.hostStack[event.server][mask].users); - }, this); - delete this.hostStack[event.server][mask]; + async.each(_.keys(hostMasks), function(hostMask, done) { + this.api.getVHosts(event.server, hostMask.split('@')[1], function(err, users) { + _.each(users, function(user) { + allFlags[user] = hostMasks[hostMask]; + }); + done(); + }); + }.bind(this), function() { + console.log('DONE'); + _.each(this.flagStack[event.server][end[1]].callbacks, function(callback) { + callback(null, this.flagStack[event.server][end[1]].flags); + }.bind(this)); + delete this.flagStack[event.server][end[1]]; + }.bind(this)); } } - }, this); + } else if(event.user === 'HostServ') { + _.each(this.hostStack[event.server], function(el, mask) { + if(event.params.match(mask)) { + var user = event.params.match(/- ([^ ]+)/), + end = event.params.match(/matches for pattern/); + + if(user) { + this.hostStack[event.server][mask].users.push(user[1]); + } else if(end) { + _.each(this.hostStack[event.server][mask].callbacks, function(callback) { + callback(null, this.hostStack[event.server][mask].users); + }, this); + delete this.hostStack[event.server][mask]; + } + } + }, this); + } + } else { // PRIVMSG + var akill = event.message.match(/([^ ]+) AKILL:ADD: ([^ ]+) \(reason: (.+)(\) )\(duration: ([^,)]+)/); + if(event.channel === '#services' && akill) { + var channel = dbot.config.servers[server].admin_channel; + dbot.api.report.notify('ban', 'tripsit', akill[1], channel, dbot.t('akill', { + 'host': akill[2], + 'reason': akill[3], + 'duration': akill[4] + })); + } } }.bind(this); - this.on = 'NOTICE'; + this.on = ['NOTICE', 'PRIVMSG']; }; exports.fetch = function(dbot) { From 5289efc72c055cc5b3e88cce70001798fb6650a1 Mon Sep 17 00:00:00 2001 From: Luke Slater Date: Fri, 3 Oct 2014 20:54:30 +0000 Subject: [PATCH 46/54] blah --- modules/atheme/atheme.js | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/modules/atheme/atheme.js b/modules/atheme/atheme.js index 3cbd818..b4ee42f 100644 --- a/modules/atheme/atheme.js +++ b/modules/atheme/atheme.js @@ -95,25 +95,20 @@ var atheme = function(dbot) { delete allFlags[u]; } }); - - async.each(_.keys(hostMasks), function(hostMask, done) { + async.each(_.keys(hostMasks), function(hostMask, done) { this.api.getVHosts(event.server, hostMask.split('@')[1], function(err, users) { _.each(users, function(user) { allFlags[user] = hostMasks[hostMask]; }); done(); }); - done(); - }); - }.bind(this), function() { - _.each(this.flagStack[event.server][end[1]].callbacks, function(callback) { - callback(null, this.flagStack[event.server][end[1]].flags); }.bind(this), function() { + console.log('DONE'); _.each(this.flagStack[event.server][end[1]].callbacks, function(callback) { callback(null, this.flagStack[event.server][end[1]].flags); }.bind(this)); delete this.flagStack[event.server][end[1]]; - }.bind(this)); + }.bind(this)); } } } else if(event.user === 'HostServ') { From 881f828f346af7bdaa80655aedd55487b3bfc95b Mon Sep 17 00:00:00 2001 From: reality Date: Fri, 3 Oct 2014 20:56:11 +0000 Subject: [PATCH 47/54] no strict match on chan --- modules/atheme/atheme.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/atheme/atheme.js b/modules/atheme/atheme.js index c421689..93afbd7 100644 --- a/modules/atheme/atheme.js +++ b/modules/atheme/atheme.js @@ -131,7 +131,7 @@ var atheme = function(dbot) { } } else { // PRIVMSG var akill = event.message.match(/([^ ]+) AKILL:ADD: ([^ ]+) \(reason: (.+)(\) )\(duration: ([^,)]+)/); - if(event.channel === '#services' && akill) { + if(event.channel == '#services' && akill) { var channel = dbot.config.servers[server].admin_channel; dbot.api.report.notify('ban', 'tripsit', akill[1], channel, dbot.t('akill', { 'host': akill[2], From a68108df0710e3d69f8556ac10a08c7484b664f3 Mon Sep 17 00:00:00 2001 From: reality Date: Fri, 3 Oct 2014 21:00:57 +0000 Subject: [PATCH 48/54] remember to commit new files --- jsbot | 2 +- modules/atheme/strings.json | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 modules/atheme/strings.json diff --git a/jsbot b/jsbot index 139a3aa..606d0cd 160000 --- a/jsbot +++ b/jsbot @@ -1 +1 @@ -Subproject commit 139a3aad5a8b5c71dfe43fdc3f04d29d8b4104df +Subproject commit 606d0cdcddfda9d7328cfa0b65bb4a3079d77d9e diff --git a/modules/atheme/strings.json b/modules/atheme/strings.json new file mode 100644 index 0000000..bd4725a --- /dev/null +++ b/modules/atheme/strings.json @@ -0,0 +1,5 @@ +{ + "akill": { + "en": "{host} has been AKilled for {duration} due to \"{reason}\"" + } +} From 9705f308fd60aef95c9329b78456c32c903be327 Mon Sep 17 00:00:00 2001 From: reality Date: Thu, 16 Oct 2014 16:08:58 +0000 Subject: [PATCH 49/54] fix wordusers --- modules/sstats/commands.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/sstats/commands.js b/modules/sstats/commands.js index fb61f1e..356eab3 100644 --- a/modules/sstats/commands.js +++ b/modules/sstats/commands.js @@ -213,7 +213,7 @@ var commands = function(dbot) { .value(); async.eachSeries(pCounts, function(pCount, next) { - dbot.api.users.getUser(pCount[0], function(user) { + dbot.api.users.getUser(pCount[0], function(err, user) { pCount[0] = user.primaryNick; next(); }); }, function() { From c4828f7ef43b051c544baa9f5671f5968e1cec48 Mon Sep 17 00:00:00 2001 From: Luke Slater Date: Sun, 19 Oct 2014 23:55:45 +0100 Subject: [PATCH 50/54] Update web.js --- modules/web/web.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/web/web.js b/modules/web/web.js index 08ce4d9..46367e6 100644 --- a/modules/web/web.js +++ b/modules/web/web.js @@ -129,7 +129,8 @@ var webInterface = function(dbot) { this.app.post('/login', passport.authenticate('local', { 'failureRedirect': '/login', - 'failureFlash': true + 'failureFlash': true, + 'routes': dbot.modules.web.indexLinks }), function(req, res) { if(req.body.redirect) { res.redirect(req.body.redirect); From cd92f0c4de2bda2285f66bbdd9b90cb7807ae2d9 Mon Sep 17 00:00:00 2001 From: Luke Slater Date: Tue, 21 Oct 2014 15:08:26 +0000 Subject: [PATCH 51/54] updates --- modules/atheme/atheme.js | 16 ++++++++++------ modules/users/users.js | 2 +- modules/web/api.js | 4 +++- modules/web/web.js | 8 +++++--- 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/modules/atheme/atheme.js b/modules/atheme/atheme.js index 6bbbc96..9ab1502 100644 --- a/modules/atheme/atheme.js +++ b/modules/atheme/atheme.js @@ -129,14 +129,18 @@ var atheme = function(dbot) { }, this); } } else { // PRIVMSG +console.log(event.message); var akill = event.message.match(/([^ ]+) AKILL:ADD: ([^ ]+) \(reason: (.+)(\) )\(duration: ([^,)]+)/); if(event.channel == '#services' && akill) { - var channel = dbot.config.servers[server].admin_channel; - dbot.api.report.notify('ban', 'tripsit', akill[1], channel, dbot.t('akill', { - 'host': akill[2], - 'reason': akill[3], - 'duration': akill[4] - })); +console.log(akill); + var channel = dbot.config.servers[event.server].admin_channel; + dbot.api.users.getUser(akill[1] + '.' + event.server, function(err, user) { + dbot.api.report.notify('ban', 'tripsit', user, channel, dbot.t('akill', { + 'host': akill[2], + 'reason': akill[3], + 'duration': akill[5] + })); + }); } } }.bind(this); diff --git a/modules/users/users.js b/modules/users/users.js index 214603f..f0e6bb2 100644 --- a/modules/users/users.js +++ b/modules/users/users.js @@ -35,7 +35,7 @@ var users = function(dbot) { 'user': user.id }, function(err, result) { if(!err) { - dbot.api.event.emit('new_user_alias', [ user, alias ]); + dbot.api.event.emit('new_user_alias', [ result, alias ]); callback(null, result); } else { callback(true, null); diff --git a/modules/web/api.js b/modules/web/api.js index 79680ed..a168f44 100644 --- a/modules/web/api.js +++ b/modules/web/api.js @@ -28,6 +28,7 @@ var api = function(dbot) { accessNeeded, allowedNicks; +console.log('haxess called'); if(mConfig.requireWebLogin == true) { if(req.isAuthenticated()) { if(_.has(mConfig, 'pageAccess') && _.has(mConfig.pageAccess, path)) { @@ -56,7 +57,8 @@ var api = function(dbot) { } else { res.render('login', { 'message': 'You need to log in to access this module.', - 'redirect': req.originalUrl + 'redirect': req.originalUrl, + 'routes': dbot.modules.web.indexLinks }); } } else { diff --git a/modules/web/web.js b/modules/web/web.js index 46367e6..597f115 100644 --- a/modules/web/web.js +++ b/modules/web/web.js @@ -78,6 +78,7 @@ var webInterface = function(dbot) { var func = pages[p], mod = func.module; +console.log('adding ' + p); this.app.get(p, this.api.hasAccess, (function(req, resp) { // Crazy shim to seperate module views. var shim = Object.create(resp); @@ -123,14 +124,15 @@ var webInterface = function(dbot) { this.app.get('/login', function(req, res) { res.render('login', { 'user': req.user, - 'message': req.flash('error') + 'message': req.flash('error'), + 'routes': this.indexLinks }); - }); + }.bind(this)); this.app.post('/login', passport.authenticate('local', { 'failureRedirect': '/login', 'failureFlash': true, - 'routes': dbot.modules.web.indexLinks + 'routes': this.indexLinks }), function(req, res) { if(req.body.redirect) { res.redirect(req.body.redirect); From d7939a59ccf048308deda80f1027c4d41bf6a555 Mon Sep 17 00:00:00 2001 From: Luke Slater Date: Tue, 21 Oct 2014 15:08:55 +0000 Subject: [PATCH 52/54] changes --- modules/warning/pages.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/modules/warning/pages.js b/modules/warning/pages.js index cb24623..9af21f5 100644 --- a/modules/warning/pages.js +++ b/modules/warning/pages.js @@ -10,6 +10,7 @@ var pages = function(dbot) { 'name': dbot.config.name, 'servers': _.keys(dbot.config.servers) }); +console.log('YE'); }, '/warning/:server': function(req, res) { @@ -42,9 +43,11 @@ var pages = function(dbot) { '/warning/:server/:uid': function(req, res) { var server = req.params.server, user = req.params.uid; +console.log('YE YE'); dbot.api.users.resolveUser(server, user, function(err, user) { var warnings = []; + if(user) { this.db.search('warnings', { 'server': server, 'warnee': user.id @@ -64,6 +67,7 @@ var pages = function(dbot) { }); }); }); + } }.bind(this)); } }; From 977de65914ffd443d4f1fed5c0fd1e21cf35019a Mon Sep 17 00:00:00 2001 From: reality Date: Tue, 21 Oct 2014 21:25:50 +0000 Subject: [PATCH 53/54] web changes for posting --- modules/web/api.js | 3 +-- modules/web/web.js | 18 +++++++++++++++--- views/layout.jade | 1 + 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/modules/web/api.js b/modules/web/api.js index a168f44..446012d 100644 --- a/modules/web/api.js +++ b/modules/web/api.js @@ -28,7 +28,6 @@ var api = function(dbot) { accessNeeded, allowedNicks; -console.log('haxess called'); if(mConfig.requireWebLogin == true) { if(req.isAuthenticated()) { if(_.has(mConfig, 'pageAccess') && _.has(mConfig.pageAccess, path)) { @@ -49,7 +48,7 @@ console.log('haxess called'); } } - if(_.include(allowedUsers, req.user.primaryNick)) { + if(_.include(accessNeeded(), req.user.primaryNick)) { return next(); } else { res.redirect('/'); diff --git a/modules/web/web.js b/modules/web/web.js index 597f115..5ef33af 100644 --- a/modules/web/web.js +++ b/modules/web/web.js @@ -34,6 +34,18 @@ var webInterface = function(dbot) { passport.deserializeUser(function(id, done) { dbot.api.users.getUser(id, function(err, user) { + // Get user access level. Sigh. + if(user) { + user.access = 'user'; + if(_.include(dbot.config.admins, user.primaryNick)) { + user.access = 'admin'; + } else if(_.include(dbot.config.moderators, user.primaryNick)) { + user.access = 'moderator'; + } else if(_.include(dbot.config.power_users, user.primaryNick)) { + user.access = 'power_user'; + } + } + console.log(user); done(null, user); }); }); @@ -76,10 +88,10 @@ var webInterface = function(dbot) { for(var p in pages) { if(_.has(pages, p)) { var func = pages[p], - mod = func.module; + mod = func.module, + type = func.type || 'get'; -console.log('adding ' + p); - this.app.get(p, this.api.hasAccess, (function(req, resp) { + this.app[type](p, this.api.hasAccess, (function(req, resp) { // Crazy shim to seperate module views. var shim = Object.create(resp); shim.render = (function(view, one, two) { diff --git a/views/layout.jade b/views/layout.jade index dfb3649..b1b22d7 100644 --- a/views/layout.jade +++ b/views/layout.jade @@ -3,6 +3,7 @@ html(lang='en') head meta(charset='utf-8') script(type="text/javascript", src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js") + script(type="text/javascript", src="/fs_edit.js") link(rel="stylesheet", type="text/css", href="http://fonts.googleapis.com/css?family=Source+Sans+Pro") link(rel="stylesheet", type="text/css", href="/bootstrap/css/bootstrap.min.css") link(rel='stylesheet', type='text/css', href='/styles.css') From f309348e25bdf851efd33e4ab1bc5ba796cba2ed Mon Sep 17 00:00:00 2001 From: Luke Slater Date: Wed, 22 Oct 2014 03:10:24 +0100 Subject: [PATCH 54/54] Update run.js --- run.js | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/run.js b/run.js index e8af57e..d900ed2 100644 --- a/run.js +++ b/run.js @@ -44,13 +44,10 @@ var DBot = function() { this.instance.addConnection(name, server.server, server.port, this.config.admin, function(event) { var server = this.config.servers[event.server]; - - async.eachSeries(server.channels, function(channel, next) { - setTimeout(function() { - this.instance.join(event, channel); - next(); - }.bind(this), 5000); - }.bind(this)); + + _.each(server.channels, function(channel) { + this.instance.join(event, channel); + }, this); }.bind(this), server.nickserv, server.password); }, this);