Updated stats command

This commit is contained in:
dbroqua 2020-01-07 16:14:50 +01:00
parent f140943545
commit 68217fac15
2 changed files with 43 additions and 7 deletions

View File

@ -35,7 +35,7 @@ class Help {
say(where, 'IRC Radio Bot :: Help')
say(where, '!artist <add/del> {nom à sauvegarder si différent du morceau en cours}')
say(where, '!song <add/del> {nom à sauvegarder si différent du morceau en cours}')
say(where, '!stats <period> <artist/song>')
say(where, '!stats <period> {artist/song}')
say(where, '!when <period> <artist/song>')
say(where, '!list <period> <artist/song>')
say(where, '!help {command}')
@ -84,6 +84,7 @@ class Help {
say(where, '!stats lastweek <title>')
say(where, '!stats lastmonth <title>')
say(where, '!stats lastyear <title>')
say(where, 'Si <title> n\'est pas spécifie la stats concerne le nombre d\'artistes différents pour cette période')
}
/**

View File

@ -14,8 +14,8 @@ class When extends Queries {
*/
action (botSay, where, line) {
let isOk = true
if (line.length < 4) {
botSay(where, 'Tu as oublié la période et ou l\'artiste/titre !')
if (line.length < 3) {
botSay(where, 'Tu as oublié la période !')
return false
}
@ -45,18 +45,53 @@ class When extends Queries {
return false
}
if (line.length === 3) {
this.getCountGroups(botSay, where)
} else {
this.models.Histories
.find(filter)
.sort({
createdAt: 'desc'
})
.then(items => {
if (items.length === '0') {
botSay(where, `${this.getValue()} n'a pas était joué pour cette période sur ${process.env.RADIO_ALIAS}`)
return true
}
botSay(where, `Pour cette période ${this.getValue()} a été entendu ${items.length} fois`)
})
.catch(err => {
console.error('ERR:', err)
botSay(where, 'Impossible de te répondre pour le moment, j\'ai buggé...')
})
}
}
getCountGroups (botSay, where) {
const artists = []
const songs = []
this.models.Histories
.find(filter)
.find(this.filter)
.sort({
createdAt: 'desc'
artist: 'desc'
})
.then(items => {
if (items.length === '0') {
botSay(where, `${this.getValue()} n'a pas était joué pour cette période sur ${process.env.RADIO_ALIAS}`)
botSay(where, 'Je n\'ai absolu rien entendu pendant cette période !')
return true
}
botSay(where, `Pour cette période ${this.getValue()} a été entendu ${items.length} fois`)
for (let i = 1; i < items.length; i + 1) {
if (artists.indexOf(items[i].artist) === -1) {
artists.push(items[i].artist)
}
if (songs.indexOf(items[i].title) === -1) {
songs.push(items[i].title)
}
}
botSay(where, `Pour cette période tu as pu entendre ${artists.length} différents pour un total de ${songs.length} morceaux différents !`)
})
.catch(err => {
console.error('ERR:', err)