forked from zozs/a-wild-button-appears
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstats.js
73 lines (62 loc) · 1.75 KB
/
stats.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
const db = require('./db')
const msToSec = ms => (ms / 1000).toFixed(2)
module.exports = {
async statsBlocks (instanceRef) {
const [wins, fastestClickTimes, slowestClickTimes, streaks] = await Promise.all([
db.clicksPerUser(instanceRef),
db.fastestClickTimes(instanceRef, 5),
db.slowestClickTimes(instanceRef, 5),
db.winningStreaks(instanceRef, 5)
])
const headerBlock = {
type: 'section',
text: {
type: 'mrkdwn',
text: '*Some wild STATISTICS appears!* :bar_chart:'
}
}
const winsBlock = {
type: 'mrkdwn',
text: '*Number of wins*\n' + wins.map(u => `${u.count} <@${u.user}>`).join('\n')
}
const streakBlock = {
type: 'mrkdwn',
text: '*Longest winning streak*\n' +
streaks.map(u => `${u.streak} <@${u.user}>`).join('\n')
}
const fastestBlock = {
type: 'mrkdwn',
text: '*Fastest wins*\n' +
fastestClickTimes.map(u => `${msToSec(u.time)} s <@${u.user}>`).join('\n')
}
const slowestBlock = {
type: 'mrkdwn',
text: '*Slowest wins*\n' +
slowestClickTimes.map(u => `${msToSec(u.time)} s <@${u.user}>`).join('\n')
}
const countBlock = {
type: 'section',
fields: [
winsBlock,
streakBlock
]
}
const fastestSlowestBlock = {
type: 'section',
fields: [
fastestBlock,
slowestBlock
]
}
return [headerBlock, countBlock, fastestSlowestBlock]
},
async statsCommand (res, instanceRef) {
console.debug('Returning stats.')
const message = {
text: 'Some wild STATISTICS appears!',
blocks: await module.exports.statsBlocks(instanceRef)
}
res.send(message)
console.debug('Returned stats.')
}
}