Added !stats command
This commit is contained in:
parent
08b2d46a43
commit
ef694b116f
7 changed files with 201 additions and 78 deletions
36
libs/When.js
36
libs/When.js
|
@ -1,9 +1,10 @@
|
|||
const setPeriod = require('../helpers/dates').setPeriod
|
||||
const formatString = require('../helpers/strings').formatString
|
||||
const Queries = require('./Queries')
|
||||
const moment = require('moment')
|
||||
|
||||
class When {
|
||||
class When extends Queries {
|
||||
constructor (models) {
|
||||
super()
|
||||
this.models = models
|
||||
}
|
||||
|
||||
|
@ -19,23 +20,11 @@ class When {
|
|||
return false
|
||||
}
|
||||
|
||||
const period = line[2]
|
||||
let value = ''
|
||||
for (let i = 3; i < line.length; i += 1) {
|
||||
value += ' ' + line[i]
|
||||
}
|
||||
value = value.replace(' ', '')
|
||||
let isOk = true
|
||||
const filter = {
|
||||
$or: [
|
||||
{
|
||||
artist: formatString(value)
|
||||
},
|
||||
{
|
||||
title: formatString(value)
|
||||
}
|
||||
]
|
||||
}
|
||||
this.setBaseFilter(line, 3)
|
||||
|
||||
const period = line[2]
|
||||
const filter = this.getFilter()
|
||||
|
||||
switch (period) {
|
||||
case 'day':
|
||||
|
@ -65,23 +54,20 @@ class When {
|
|||
.limit(1)
|
||||
.then(item => {
|
||||
if (!item) {
|
||||
botSay(where, `${value} n'a pas était joué pour cette période sur ${process.env.RADIO_ALIAS}`)
|
||||
botSay(where, `${this.getValue()} n'a pas était joué pour cette période sur ${process.env.RADIO_ALIAS}`)
|
||||
return true
|
||||
}
|
||||
|
||||
if (item.artist.toLowerCase() === value.toLowerCase()) {
|
||||
botSay(where, `Pour cette période ${value} a été entendu pour la dernière fois le ${moment(item.createdAt).format('DD/MM/YYYY à HH:mm')} avec ${item.title}`)
|
||||
if (item.artist.toLowerCase() === this.getValue().toLowerCase()) {
|
||||
botSay(where, `Pour cette période ${this.getValue()} a été entendu pour la dernière fois le ${moment(item.createdAt).format('DD/MM/YYYY à HH:mm')} avec ${item.title}`)
|
||||
} else {
|
||||
botSay(where, `Pour cette période ${value} a été entendu pour la dernière fois le ${moment(item.createdAt).format('DD/MM/YYYY à HH:mm')}`)
|
||||
botSay(where, `Pour cette période ${this.getValue()} a été entendu pour la dernière fois le ${moment(item.createdAt).format('DD/MM/YYYY à HH:mm')}`)
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
console.log('ERR:', err)
|
||||
botSay(where, 'Impossible de te répondre pour le moment, j\'ai buggé...')
|
||||
})
|
||||
|
||||
console.log('PERIOD:', period, 'SONG:', value)
|
||||
console.log('FILTER:', filter)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue