From fc83487a5d2edcb3978753a82f7ba89f9a0eca60 Mon Sep 17 00:00:00 2001 From: Luke Slater Date: Sun, 25 Nov 2012 17:56:30 +0000 Subject: [PATCH] Addition to the web interface to view currently connected users and interpolate some data. Little messy atm. --- jsbot | 2 +- modules/web.js | 61 +++++++++++++++++++++++++++++++++++++++--- views/channels.jade | 7 +++++ views/connections.jade | 6 +++++ views/index.jade | 1 + views/user.jade | 11 ++++++++ views/users.jade | 7 +++++ 7 files changed, 91 insertions(+), 4 deletions(-) create mode 100644 views/channels.jade create mode 100644 views/connections.jade create mode 100644 views/user.jade create mode 100644 views/users.jade diff --git a/jsbot b/jsbot index 43b90e2..6723ded 160000 --- a/jsbot +++ b/jsbot @@ -1 +1 @@ -Subproject commit 43b90e24b9293029f6ef4362304fb127e4f1530c +Subproject commit 6723ded150692bd157b43ac287a3913abd1d7a99 diff --git a/modules/web.js b/modules/web.js index 3d9ad87..bdfa590 100644 --- a/modules/web.js +++ b/modules/web.js @@ -9,10 +9,65 @@ var webInterface = function(dbot) { app.set('view engine', 'jade'); app.get('/', function(req, res) { - //res.redirect('/quotes'); res.render('index', { 'name': dbot.name }); }); - + + app.get('/connections', function(req, res) { + var connections = Object.keys(dbot.instance.connections); + res.render('connections', { 'name': dbot.name, 'connections': connections }); + }); + + app.get('/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.name, 'connection': connection, 'channels': channels}); + } else { + res.render('error', { 'name': dbot.name, 'message': 'No such connection.' }); + } + }); + + app.get('/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 = connections[connection].channels[channel].nicks; + res.render('users', { 'name': dbot.name, 'connection': connection, + 'channel': channel, 'nicks': nicks }); + } else { + res.render('error', { 'name': dbot.name, 'message': 'No such connection or channel.' }); + } + }); + + app.get('/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(user)) { + var kicks = '0'; + } else { + var kicks = dbot.db.kicks[user]; + } + + if(!dbot.db.kickers.hasOwnProperty(user)) { + var kicked = '0'; + } else { + var kicked = dbot.db.kickers[user]; + } + + res.render('user', { 'name': dbot.name, 'user': req.params.user, + 'channel': channel, 'connection': connection, 'cleanUser': user, + 'quotecount': quoteCount, 'kicks': kicks, 'kicked': kicked }); + }); + // Lists the quote categories app.get('/quotes', function(req, res) { res.render('quotelist', { 'name': dbot.name, 'quotelist': Object.keys(dbot.db.quoteArrs) }); @@ -42,7 +97,7 @@ var webInterface = function(dbot) { // Shows the results of a poll app.get('/polls/:key', function(req, res) { var key = req.params.key.toLowerCase(); - if(dbot.db.polls.hasOwnProperty(key)) { + if(dbot.db.polls.hasOwnProperty(key) && dbot.db.polls[key].hasOwnProperty('description')) { // tally the votes var totalVotes = 0; for( var v in dbot.db.polls[key].votes ) { diff --git a/views/channels.jade b/views/channels.jade new file mode 100644 index 0000000..d0e3faa --- /dev/null +++ b/views/channels.jade @@ -0,0 +1,7 @@ +h3 Channels on #{connection} +div#backlink + a(href='/connections') « Connection List +ul#quotelist + -each channel in channels + a(href='/users/'+connection+'/'+channel.substr(1,channel.length)) + li.quotes #{channel} diff --git a/views/connections.jade b/views/connections.jade new file mode 100644 index 0000000..f4e1531 --- /dev/null +++ b/views/connections.jade @@ -0,0 +1,6 @@ +h3 Current Connections +div#backlink + a(href='/') « Home +#modulelinks + -each connection in connections + a.module(href='/channels/'+connection) #{connection} diff --git a/views/index.jade b/views/index.jade index 8372429..4558fbf 100644 --- a/views/index.jade +++ b/views/index.jade @@ -1,3 +1,4 @@ #modulelinks a.module(href='/quotes') Quotes a.module(href='/polls') Polls + a.module(href='/connections') Users diff --git a/views/user.jade b/views/user.jade new file mode 100644 index 0000000..6b93375 --- /dev/null +++ b/views/user.jade @@ -0,0 +1,11 @@ +h3 #{user}'s profile +div#backlink + a(href='/channels/'+connection+'/'+channel.substr(1,channel.length)) « #{channel} Nick List + +div.quotecount + #{cleanUser} is filled with + a(href='/quotes/'+cleanUser) #{quotecount} quotes + . + +div.kickcount + #{cleanUser} has kicked people #{kicked} times and has been kicked #{kicks} times. diff --git a/views/users.jade b/views/users.jade new file mode 100644 index 0000000..89c6a11 --- /dev/null +++ b/views/users.jade @@ -0,0 +1,7 @@ +h3 Users currently in #{channel} on #{connection} +div#backlink + a(href='/channels/'+connection) « Channel List +ul#quotelist + -each nick in nicks + a(href='/user/'+connection+'/'+channel.substr(1,channel.length)+'/'+nick) + li.quotes #{nick}