-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaseen.js
35 lines (31 loc) · 1.2 KB
/
aseen.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
var moment = require('moment');
var format = require('util').format;
function aseen(knex) {
return {
knex: knex,
find: find
};
};
function find(targetNick, targetChannel) {
return this.knex('message').where({
FromNick: targetNick,
Channel: targetChannel
}).orderBy('Timestamp', 'desc').first()
.then(function(row) {
if (row) {
var now = moment(new Date());
var timeAgoMessage = moment(row.Timestamp).from(now);
if (row.MessageType === 'privmsg') {
return format('Last activity in %s %s: "%s".', targetChannel, timeAgoMessage, row.Message);
}
if (!row.Message) {
return format('Last activity in %s was a %s %s.', targetChannel, row.MessageType, timeAgoMessage);
}
return format('Last activity in %s was a %s %s: "%s".', targetChannel, row.MessageType, timeAgoMessage, row.Message);
}
else {
return ('I have never seen any client activity from ' + targetNick + ' in ' + targetChannel);
}
});
};
module.exports = aseen;