diff --git a/libs/Help.js b/libs/Help.js index 3170aba..5c8ebb1 100644 --- a/libs/Help.js +++ b/libs/Help.js @@ -35,7 +35,7 @@ class Help { say(where, 'IRC Radio Bot :: Help') say(where, '!artist {nom à sauvegarder si différent du morceau en cours}') say(where, '!song {nom à sauvegarder si différent du morceau en cours}') - say(where, '!stats ') + say(where, '!stats {artist/song}') say(where, '!when ') say(where, '!list ') say(where, '!help {command}') @@ -84,6 +84,7 @@ class Help { say(where, '!stats lastweek ') 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') } /** diff --git a/libs/Statistics.js b/libs/Statistics.js index f101c9f..4ab9581 100644 --- a/libs/Statistics.js +++ b/libs/Statistics.js @@ -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)