Added notification when good song is played
This commit is contained in:
parent
68f821b933
commit
063c0eb267
2 changed files with 47 additions and 0 deletions
3
index.js
3
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)
|
||||
})
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue