Added notification when good song is played

This commit is contained in:
dbroqua 2019-12-24 16:41:18 +01:00
parent 68f821b933
commit 063c0eb267
2 changed files with 47 additions and 0 deletions

View File

@ -109,4 +109,7 @@ stream.on('metadata', function (data) {
artist: artist,
title: title
})
// Notify some people ?
artistSong.notify(botSay, process.env.IRC_CHANNEL, currentSong)
})

View File

@ -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