mirror of
https://github.com/reality/dbot.git
synced 2025-01-24 02:54:16 +01:00
words data
This commit is contained in:
parent
ffd60654b1
commit
2cd538e1eb
@ -13,6 +13,9 @@ var api = function(dbot) {
|
|||||||
var uStats = {
|
var uStats = {
|
||||||
'id': id,
|
'id': id,
|
||||||
'lines': 0,
|
'lines': 0,
|
||||||
|
'words': 0,
|
||||||
|
'capitals': 0,
|
||||||
|
'curses': 0,
|
||||||
'channels': {},
|
'channels': {},
|
||||||
'creation': new Date().getTime()
|
'creation': new Date().getTime()
|
||||||
};
|
};
|
||||||
@ -31,6 +34,9 @@ var api = function(dbot) {
|
|||||||
var cStats = {
|
var cStats = {
|
||||||
'id': id,
|
'id': id,
|
||||||
'lines': 0,
|
'lines': 0,
|
||||||
|
'words': 0,
|
||||||
|
'capitals': 0,
|
||||||
|
'curses': 0,
|
||||||
'creation': new Date().getTime()
|
'creation': new Date().getTime()
|
||||||
};
|
};
|
||||||
this.db.save('channel_stats', id, cStats, function(err, cStats) {
|
this.db.save('channel_stats', id, cStats, function(err, cStats) {
|
||||||
|
@ -2,6 +2,45 @@ var _ = require('underscore')._;
|
|||||||
|
|
||||||
var commands = function(dbot) {
|
var commands = function(dbot) {
|
||||||
var commands = {
|
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
|
||||||
|
});
|
||||||
|
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);
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
'~lines': function(event) {
|
'~lines': function(event) {
|
||||||
var getLines = function(user) {
|
var getLines = function(user) {
|
||||||
this.api.getUserStats(user.id, function(uStats) {
|
this.api.getUserStats(user.id, function(uStats) {
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
{
|
{
|
||||||
"dbType": "redis",
|
"dbType": "redis",
|
||||||
"dependencies": [ "users" ]
|
"dependencies": [ "users" ],
|
||||||
|
"curses": [ "shit", "piss", "fuck", "cunt", "cocksucker", "motherfucker", "tits" ]
|
||||||
}
|
}
|
||||||
|
@ -7,15 +7,45 @@ var _ = require('underscore')._;
|
|||||||
var sstats = function(dbot) {
|
var sstats = function(dbot) {
|
||||||
if(!_.has(dbot.db, 'ssinception')) dbot.db.ssinception = new Date().getTime();
|
if(!_.has(dbot.db, 'ssinception')) dbot.db.ssinception = new Date().getTime();
|
||||||
|
|
||||||
|
this.isUpperCase = function(word) {
|
||||||
|
return _.all(word.split(''), function(c) {
|
||||||
|
return c == c.toUpperCase();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
this.listener = function(event) {
|
this.listener = function(event) {
|
||||||
event.cStats.lines++;
|
event.cStats.lines++;
|
||||||
event.uStats.lines++;
|
event.uStats.lines++;
|
||||||
|
|
||||||
|
var words = event.message.split(' '),
|
||||||
|
wCount = words.length,
|
||||||
|
capitals = 0,
|
||||||
|
curses = 0;
|
||||||
|
_.each(words, function(word) {
|
||||||
|
if(this.isUpperCase(word)) capitals++;
|
||||||
|
if(_.include(this.config.curses, word)) curses++;
|
||||||
|
}, this);
|
||||||
|
|
||||||
|
event.uStats.words += wCount;
|
||||||
|
event.uStats.capitals += capitals;
|
||||||
|
event.uStats.curses += curses;
|
||||||
|
|
||||||
|
event.cStats.words += wCount;
|
||||||
|
event.cStats.capitals += capitals;
|
||||||
|
event.cStats.curses += curses;
|
||||||
|
|
||||||
if(!_.has(event.uStats.channels, event.rChannel.id)) {
|
if(!_.has(event.uStats.channels, event.rChannel.id)) {
|
||||||
event.uStats.channels[event.rChannel.id] = {
|
event.uStats.channels[event.rChannel.id] = {
|
||||||
'lines': 1
|
'lines': 1,
|
||||||
|
'words': wCount,
|
||||||
|
'capitals': capitals,
|
||||||
|
'curses': curses
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
event.uStats.channels[event.rChannel.id].lines++;
|
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;
|
||||||
}
|
}
|
||||||
this.db.save('channel_stats', event.cStats.id, event.cStats, function() {});
|
this.db.save('channel_stats', event.cStats.id, event.cStats, function() {});
|
||||||
this.db.save('user_stats', event.uStats.id, event.uStats, function() {});
|
this.db.save('user_stats', event.uStats.id, event.uStats, function() {});
|
||||||
|
@ -13,5 +13,11 @@
|
|||||||
},
|
},
|
||||||
"sstats_clines": {
|
"sstats_clines": {
|
||||||
"en": "{lines} lines posted in {channel}."
|
"en": "{lines} lines posted in {channel}."
|
||||||
|
},
|
||||||
|
"sstats_uwords": {
|
||||||
|
"en": "{user} has used {words} words ({curses} curses, {capitals} capitalised words)"
|
||||||
|
},
|
||||||
|
"sstats_ucwords": {
|
||||||
|
"en": " - {words} words, {curses} curses, {capitals} capitalised words in {channel}"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user