Updated stats command
This commit is contained in:
parent
f140943545
commit
68217fac15
2 changed files with 43 additions and 7 deletions
|
@ -35,7 +35,7 @@ class Help {
|
||||||
say(where, 'IRC Radio Bot :: Help')
|
say(where, 'IRC Radio Bot :: Help')
|
||||||
say(where, '!artist <add/del> {nom à sauvegarder si différent du morceau en cours}')
|
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, '!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, '!when <period> <artist/song>')
|
||||||
say(where, '!list <period> <artist/song>')
|
say(where, '!list <period> <artist/song>')
|
||||||
say(where, '!help {command}')
|
say(where, '!help {command}')
|
||||||
|
@ -84,6 +84,7 @@ class Help {
|
||||||
say(where, '!stats lastweek <title>')
|
say(where, '!stats lastweek <title>')
|
||||||
say(where, '!stats lastmonth <title>')
|
say(where, '!stats lastmonth <title>')
|
||||||
say(where, '!stats lastyear <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')
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -14,8 +14,8 @@ class When extends Queries {
|
||||||
*/
|
*/
|
||||||
action (botSay, where, line) {
|
action (botSay, where, line) {
|
||||||
let isOk = true
|
let isOk = true
|
||||||
if (line.length < 4) {
|
if (line.length < 3) {
|
||||||
botSay(where, 'Tu as oublié la période et ou l\'artiste/titre !')
|
botSay(where, 'Tu as oublié la période !')
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,6 +45,9 @@ class When extends Queries {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (line.length === 3) {
|
||||||
|
this.getCountGroups(botSay, where)
|
||||||
|
} else {
|
||||||
this.models.Histories
|
this.models.Histories
|
||||||
.find(filter)
|
.find(filter)
|
||||||
.sort({
|
.sort({
|
||||||
|
@ -63,6 +66,38 @@ class When extends Queries {
|
||||||
botSay(where, 'Impossible de te répondre pour le moment, j\'ai buggé...')
|
botSay(where, 'Impossible de te répondre pour le moment, j\'ai buggé...')
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
getCountGroups (botSay, where) {
|
||||||
|
const artists = []
|
||||||
|
const songs = []
|
||||||
|
this.models.Histories
|
||||||
|
.find(this.filter)
|
||||||
|
.sort({
|
||||||
|
artist: 'desc'
|
||||||
|
})
|
||||||
|
.then(items => {
|
||||||
|
if (items.length === '0') {
|
||||||
|
botSay(where, 'Je n\'ai absolu rien entendu pendant cette période !')
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
botSay(where, 'Impossible de te répondre pour le moment, j\'ai buggé...')
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = When
|
module.exports = When
|
||||||
|
|
Loading…
Reference in a new issue