From 6c7e56be1afa32720f9c829bac1007f66f756b14 Mon Sep 17 00:00:00 2001 From: reality Date: Mon, 7 Jan 2013 12:27:24 +0000 Subject: [PATCH] load pages from closer in u/web.js --- modules/users/users.js | 62 ++-------------------------------------- modules/users/web.js | 64 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 59 deletions(-) create mode 100644 modules/users/web.js diff --git a/modules/users/users.js b/modules/users/users.js index 5edca82..2d57193 100644 --- a/modules/users/users.js +++ b/modules/users/users.js @@ -2,6 +2,8 @@ * Name: Users * Description: Track known users */ +var web = require('./web'); + var users = function(dbot) { var knownUsers = dbot.db.knownUsers; var getServerUsers = function(server) { @@ -52,64 +54,6 @@ var users = function(dbot) { }.bind(this)); }); - var pages = { - '/connections': function(req, res) { - var connections = Object.keys(dbot.instance.connections); - res.render('connections', { 'name': dbot.config.name, 'connections': connections }); - }, - - '/channels/:connection': function(req, res) { - var connection = req.params.connection; - if(dbot.instance.connections.hasOwnProperty(connection)) { - var channels = Object.keys(dbot.instance.connections[connection].channels); - res.render('channels', { 'name': dbot.config.name, 'connection': connection, 'channels': channels}); - } else { - res.render_core('error', { 'name': dbot.config.name, 'message': 'No such connection.' }); - } - }, - - '/users/:connection/:channel': function(req, res) { - var connection = req.params.connection; - var channel = '#' + req.params.channel; - var connections = dbot.instance.connections; - - if(connections.hasOwnProperty(connection) && - connections[connection].channels.hasOwnProperty(channel)) { - var nicks = Object.keys(connections[connection].channels[channel].nicks); - res.render('users', { 'name': dbot.config.name, 'connection': connection, - 'channel': channel, 'nicks': nicks }); - } else { - res.render_core('error', { 'name': dbot.config.name, 'message': 'No such connection or channel.' }); - } - }, - - '/user/:connection/:channel/:user': function(req, res) { - var connection = req.params.connection; - var channel = '#' + req.params.channel; - var user = dbot.cleanNick(req.params.user); - - var quoteCount = 'no'; - if(dbot.db.quoteArrs.hasOwnProperty(user)) { - var quoteCount = dbot.db.quoteArrs[user].length; - } - - if(!dbot.db.kicks.hasOwnProperty(req.params.user)) { - var kicks = '0'; - } else { - var kicks = dbot.db.kicks[req.params.user]; - } - - if(!dbot.db.kickers.hasOwnProperty(req.params.user)) { - var kicked = '0'; - } else { - var kicked = dbot.db.kickers[req.params.user]; - } - - res.render('user', { 'name': dbot.config.name, 'user': req.params.user, - 'channel': channel, 'connection': connection, 'cleanUser': user, - 'quotecount': quoteCount, 'kicks': kicks, 'kicked': kicked }); - }, - }; var api = { 'resolveUser': function(server, nick, useLowercase) { @@ -210,7 +154,7 @@ var users = function(dbot) { 'ignorable': false, 'commands': commands, 'api': api, - 'pages': pages, + 'pages': web.getPages(dbot), 'listener': function(event) { var knownUsers = getServerUsers(event.server); diff --git a/modules/users/web.js b/modules/users/web.js new file mode 100644 index 0000000..b6d4ad2 --- /dev/null +++ b/modules/users/web.js @@ -0,0 +1,64 @@ +var pages = function(dbot) { + return { + '/connections': function(req, res) { + var connections = Object.keys(dbot.instance.connections); + res.render('connections', { 'name': dbot.config.name, 'connections': connections }); + }, + + '/channels/:connection': function(req, res) { + var connection = req.params.connection; + if(dbot.instance.connections.hasOwnProperty(connection)) { + var channels = Object.keys(dbot.instance.connections[connection].channels); + res.render('channels', { 'name': dbot.config.name, 'connection': connection, 'channels': channels}); + } else { + res.render_core('error', { 'name': dbot.config.name, 'message': 'No such connection.' }); + } + }, + + '/users/:connection/:channel': function(req, res) { + var connection = req.params.connection; + var channel = '#' + req.params.channel; + var connections = dbot.instance.connections; + + if(connections.hasOwnProperty(connection) && + connections[connection].channels.hasOwnProperty(channel)) { + var nicks = Object.keys(connections[connection].channels[channel].nicks); + res.render('users', { 'name': dbot.config.name, 'connection': connection, + 'channel': channel, 'nicks': nicks }); + } else { + res.render_core('error', { 'name': dbot.config.name, 'message': 'No such connection or channel.' }); + } + }, + + '/user/:connection/:channel/:user': function(req, res) { + var connection = req.params.connection; + var channel = '#' + req.params.channel; + var user = dbot.cleanNick(req.params.user); + + var quoteCount = 'no'; + if(dbot.db.quoteArrs.hasOwnProperty(user)) { + var quoteCount = dbot.db.quoteArrs[user].length; + } + + if(!dbot.db.kicks.hasOwnProperty(req.params.user)) { + var kicks = '0'; + } else { + var kicks = dbot.db.kicks[req.params.user]; + } + + if(!dbot.db.kickers.hasOwnProperty(req.params.user)) { + var kicked = '0'; + } else { + var kicked = dbot.db.kickers[req.params.user]; + } + + res.render('user', { 'name': dbot.config.name, 'user': req.params.user, + 'channel': channel, 'connection': connection, 'cleanUser': user, + 'quotecount': quoteCount, 'kicks': kicks, 'kicked': kicked }); + } + }; +}; + +exports.getPages = function(dbot) { + return pages(dbot); +};