diff --git a/index.js b/index.js index b6ee398..8322309 100644 --- a/index.js +++ b/index.js @@ -109,4 +109,7 @@ stream.on('metadata', function (data) { artist: artist, title: title }) + + // Notify some people ? + artistSong.notify(botSay, process.env.IRC_CHANNEL, currentSong) }) diff --git a/libs/ArtistSong.js b/libs/ArtistSong.js index f4a0952..c0785a7 100644 --- a/libs/ArtistSong.js +++ b/libs/ArtistSong.js @@ -37,6 +37,50 @@ class ArtistSong { } } + /** + * Fonction permettant de notifier les utilisateurs lorsqu'un bon song est joué + * @param {Function} botSay + * @param {String} where + * @param {Object} currentSong + */ + notify (botSay, where, currentSong) { + this.models.Notifications + .find({ + $or: [ + { + type: 'artist', + value: currentSong.artist + }, + { + type: 'title', + value: currentSong.title + } + ] + }) + .then(list => { + const artist = [] + const song = [] + + for (let i = 0; i < list.length; i += 1) { + if (list[i].type === 'artist') { + artist.push(list[i].user) + } else { + song.push(list[i].user) + } + } + + if (artist.length > 0) { + botSay(where, `Hey ${artist.toString().replace(/,/g, ', ')} ! Y'a ${currentSong.title} ! Monte${artist.length > 1 ? 'z' : ''} le son !`) + } + if (song.length > 0) { + botSay(where, `Hey ${song.toString().replace(/,/g, ', ')} ! Y'a ${song.title} ! Monte${song.length > 1 ? 'z' : ''} le son !`) + } + }) + .catch(err => { + console.log('ERR:', err) + }) + } + /** * Fonction permettant d'ajouter un favoris * @param {Function} botSay