forked from GitHub/dbot
Addition to the web interface to view currently connected users and interpolate some data. Little messy atm.
This commit is contained in:
parent
047c2e45e5
commit
fc83487a5d
2
jsbot
2
jsbot
@ -1 +1 @@
|
||||
Subproject commit 43b90e24b9293029f6ef4362304fb127e4f1530c
|
||||
Subproject commit 6723ded150692bd157b43ac287a3913abd1d7a99
|
@ -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 ) {
|
||||
|
7
views/channels.jade
Normal file
7
views/channels.jade
Normal file
@ -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}
|
6
views/connections.jade
Normal file
6
views/connections.jade
Normal file
@ -0,0 +1,6 @@
|
||||
h3 Current Connections
|
||||
div#backlink
|
||||
a(href='/') « Home
|
||||
#modulelinks
|
||||
-each connection in connections
|
||||
a.module(href='/channels/'+connection) #{connection}
|
@ -1,3 +1,4 @@
|
||||
#modulelinks
|
||||
a.module(href='/quotes') Quotes
|
||||
a.module(href='/polls') Polls
|
||||
a.module(href='/connections') Users
|
||||
|
11
views/user.jade
Normal file
11
views/user.jade
Normal file
@ -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.
|
7
views/users.jade
Normal file
7
views/users.jade
Normal file
@ -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}
|
Loading…
Reference in New Issue
Block a user