mirror of
https://github.com/reality/dbot.git
synced 2024-12-24 19:52:36 +01:00
Merge branch 'master' of github.com:reality/depressionbot
This commit is contained in:
commit
7b01564149
22
modules/profile/api.js
Normal file
22
modules/profile/api.js
Normal file
@ -0,0 +1,22 @@
|
||||
var _ = require('underscore')._;
|
||||
|
||||
var api = function(dbot) {
|
||||
return {
|
||||
|
||||
/**
|
||||
* Create a profile for a new primary user on a given server.
|
||||
* If the server does not already exist, create it.
|
||||
*/
|
||||
"createProfile": function(server, primary){
|
||||
if(!_.has(this.profiles, server)){
|
||||
this.profiles[server] = {};
|
||||
}
|
||||
this.profiles[server][primary] = {};
|
||||
_.defaults(this.profiles[server][primary], this.config.schema);
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
exports.fetch = function(dbot) {
|
||||
return api(dbot);
|
||||
};
|
28
modules/profile/commands.js
Normal file
28
modules/profile/commands.js
Normal file
@ -0,0 +1,28 @@
|
||||
var _ = require('underscore')._;
|
||||
|
||||
var commands = function(dbot){
|
||||
return {
|
||||
|
||||
"~test_getprop": function(event){
|
||||
if(event.params[1]){
|
||||
var res = dbot.db.profiles[event.server][event.user.toLowerCase()].profile[event.params[1]];
|
||||
if(res){
|
||||
event.reply(res);
|
||||
}
|
||||
else{
|
||||
event.reply("Nope.");
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
"~test_setprop": function(event){
|
||||
if(event.params[1] && event.params[2]){
|
||||
dbot.db.profiles[event.server][event.user.toLowerCase()].profile[event.params[1]] = event.params[2];
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
exports.fetch = function(dbot){
|
||||
return commands(dbot);
|
||||
};
|
18
modules/profile/config.json
Normal file
18
modules/profile/config.json
Normal file
@ -0,0 +1,18 @@
|
||||
{
|
||||
"ignorable": false,
|
||||
"dbKeys": [ "profiles" ],
|
||||
"help": "https://github.com/reality/depressionbot/blob/master/modules/profile/README.md",
|
||||
"schema": {
|
||||
"profile": {
|
||||
"primary": null,
|
||||
"name": null,
|
||||
"tagline": null,
|
||||
"favourites": {
|
||||
"colour": null
|
||||
}
|
||||
},
|
||||
"preferences": {
|
||||
"timezone": null
|
||||
}
|
||||
}
|
||||
}
|
30
modules/profile/pages.js
Normal file
30
modules/profile/pages.js
Normal file
@ -0,0 +1,30 @@
|
||||
var pages = function(dbot) {
|
||||
var _ = require('underscore')._;
|
||||
var connections = dbot.instance.connections;
|
||||
|
||||
return {
|
||||
'/profile/:connection/:user': function(req, res) {
|
||||
var connection = req.params.connection;
|
||||
var user = dbot.cleanNick(req.params.user);
|
||||
|
||||
var primary = dbot.api.users.resolveUser(connection, user, true);
|
||||
//var profile = dbot.api.profile.getProfile(primary);
|
||||
var profile = dbot.db.profiles[connection][primary.toLowerCase()].profile;
|
||||
var stats = dbot.api.stats.getUserChansStats(connection, primary.toLowerCase(), [
|
||||
"lines", "words", "lincent", "wpl", "in_mentions"]
|
||||
);
|
||||
|
||||
res.render('profile', {
|
||||
'name': dbot.config.name,
|
||||
'connection': connection,
|
||||
'primary': primary,
|
||||
'profile': profile,
|
||||
'stats': stats.channels,
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
exports.fetch = function(dbot) {
|
||||
return pages(dbot);
|
||||
};
|
40
modules/profile/profile.js
Normal file
40
modules/profile/profile.js
Normal file
@ -0,0 +1,40 @@
|
||||
var _ = require('underscore')._;
|
||||
|
||||
var profile = function(dbot) {
|
||||
|
||||
this.profiles = dbot.db.profiles;
|
||||
|
||||
/**
|
||||
* Iterate over known user profiles and ensure they contain all the
|
||||
* required properties as defined in the configuation.
|
||||
*/
|
||||
this.onLoad = function(){
|
||||
var schema = this.config.schema;
|
||||
|
||||
// Ensure all known users have a profile
|
||||
_.each(dbot.api.users.getAllUsers(), function(server, serverName){
|
||||
if(!_.has(dbot.db.profiles, serverName)){
|
||||
dbot.db.profiles[serverName] = {}
|
||||
}
|
||||
_.each(server, function(userName){
|
||||
var primary = userName;
|
||||
userName = userName.toLowerCase();
|
||||
if(!_.has(dbot.db.profiles[serverName], userName)){
|
||||
dbot.db.profiles[serverName][userName] = {
|
||||
"profile": {},
|
||||
"preferences": {}
|
||||
};
|
||||
}
|
||||
//TODO(samstudio8) Currently only handles "top-level"
|
||||
_.defaults(dbot.db.profiles[serverName][userName].profile, schema.profile);
|
||||
_.defaults(dbot.db.profiles[serverName][userName].preferences, schema.preferences);
|
||||
dbot.db.profiles[serverName][userName].profile.primary = primary;
|
||||
});
|
||||
});
|
||||
dbot.save();
|
||||
};
|
||||
};
|
||||
|
||||
exports.fetch = function(dbot) {
|
||||
return new profile(dbot);
|
||||
};
|
@ -66,38 +66,6 @@ var pages = function(dbot) {
|
||||
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.config.moduleNames.include('kick')) {
|
||||
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];
|
||||
}
|
||||
} else {
|
||||
var kicks = 'N/A';
|
||||
var kicked = 'N/A';
|
||||
}
|
||||
|
||||
res.render('user', { 'name': dbot.config.name, 'user': req.params.user,
|
||||
'channel': channel, 'connection': connection, 'cleanUser': user,
|
||||
'quotecount': quoteCount, 'kicks': kicks, 'kicked': kicked });
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
|
79
views/profile/profile.jade
Normal file
79
views/profile/profile.jade
Normal file
@ -0,0 +1,79 @@
|
||||
extends ../layout
|
||||
|
||||
block content
|
||||
script(type="text/javascript", src="http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/jquery.dataTables.min.js")
|
||||
|
||||
script
|
||||
$(document).ready(function(){
|
||||
// Allowing forcing of string stats data to sort as numeric
|
||||
jQuery.extend( jQuery.fn.dataTableExt.oSort, {
|
||||
"forcenum-pre": function ( a ) {
|
||||
a = a.replace("\,", "");
|
||||
return parseFloat( a );
|
||||
},
|
||||
|
||||
"forcenum-asc": function ( a, b ) {
|
||||
return a - b;
|
||||
},
|
||||
|
||||
"forcenum-desc": function ( a, b ) {
|
||||
return b - a;
|
||||
}
|
||||
} );
|
||||
|
||||
$('.data').dataTable({
|
||||
"aoColumnDefs": [
|
||||
{ "sType": "forcenum",
|
||||
"asSorting": [ "desc", "asc" ],
|
||||
"aTargets": [ 1, 2, 3, 4, 5 ] }
|
||||
],
|
||||
"bPaginate": false,
|
||||
"bFilter": false,
|
||||
"bLengthChange": false,
|
||||
"oLanguage": {
|
||||
"sInfo": "",
|
||||
"sInfoEmpty": "",
|
||||
"sInfoFiltered": ""
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
div.page-header
|
||||
h1
|
||||
#{primary}
|
||||
|
||||
div#row
|
||||
table.table.table-hover.data
|
||||
thead
|
||||
tr
|
||||
th Channel
|
||||
th Lines
|
||||
th Words
|
||||
th Lincent
|
||||
th Verbosity
|
||||
th Mentions
|
||||
tbody
|
||||
for chan, key in stats
|
||||
if stats.hasOwnProperty(key)
|
||||
tr
|
||||
td
|
||||
a(href='/users/'+connection+'/'+encodeURIComponent(key))
|
||||
#{key}
|
||||
span
|
||||
if chan.online
|
||||
if chan.active
|
||||
span.label.label-success Active
|
||||
else
|
||||
span.label.label-important Inactive
|
||||
else
|
||||
span.label Offline
|
||||
td
|
||||
#{chan.fields.lines.data}
|
||||
td
|
||||
#{chan.fields.words.data}
|
||||
td
|
||||
#{chan.fields.lincent.data}
|
||||
td
|
||||
#{chan.fields.wpl.data}
|
||||
td
|
||||
#{chan.fields.in_mentions.data}
|
@ -25,7 +25,9 @@ block content
|
||||
"aoColumnDefs": [
|
||||
{ "aDataSort": [ 1, 0 ], "asSorting": [ "asc" ], "aTargets": [ 0 ] },
|
||||
{ "bVisible": false, "aTargets": [ 1 ] },
|
||||
{ "sType": "forcenum", "aTargets": [ 2, 3, 4, 5, 6 ] }
|
||||
{ "sType": "forcenum",
|
||||
"asSorting": [ "desc", "asc" ],
|
||||
"aTargets": [ 2, 3, 4, 5, 6 ] }
|
||||
],
|
||||
"bPaginate": false,
|
||||
"bLengthChange": false,
|
||||
@ -55,7 +57,7 @@ block content
|
||||
-each nick in nicks
|
||||
tr
|
||||
td
|
||||
a(href='/user/'+connection+'/'+channel.substr(1,channel.length)+'/'+nick.primary)
|
||||
a(href='/profile/'+connection+'/'+nick.primary)
|
||||
#{nick.display}
|
||||
span
|
||||
if nick.online
|
||||
|
Loading…
Reference in New Issue
Block a user