Fixed bug for duplicate song (heavy1)

This commit is contained in:
dbroqua 2020-01-28 10:10:50 +01:00
parent c7655bf6c9
commit 9e5437f360

View file

@ -32,10 +32,16 @@ let currentSong = {
artist: null, artist: null,
title: null title: null
} }
let previousSong = { const previousSongs = [
{
artist: null,
title: null
},
{
artist: null, artist: null,
title: null title: null
} }
]
// Initialisation du bot IRC // Initialisation du bot IRC
const bot = new irc.Client(process.env.IRC_SERVER, process.env.IRC_NICKNAME, { const bot = new irc.Client(process.env.IRC_SERVER, process.env.IRC_NICKNAME, {
@ -45,8 +51,7 @@ const bot = new irc.Client(process.env.IRC_SERVER, process.env.IRC_NICKNAME, {
channels: [process.env.IRC_CHANNEL] channels: [process.env.IRC_CHANNEL]
}) })
const checkCurrentSong = () => { const displayCurrentSong = () => {
previousSong = currentSong
// Just for debug // Just for debug
console.info(`Now playing: ${currentSong.artist} - ${currentSong.title}`) console.info(`Now playing: ${currentSong.artist} - ${currentSong.title}`)
@ -89,7 +94,7 @@ if (!process.env.STREAM_TYPE || process.env.STREAM_TYPE === 'radio') {
artist: artist artist: artist
} }
checkCurrentSong() displayCurrentSong()
}) })
} else { } else {
setInterval(() => { setInterval(() => {
@ -137,8 +142,13 @@ if (!process.env.STREAM_TYPE || process.env.STREAM_TYPE === 'radio') {
break break
} }
if (currentSong.title && currentSong.artist && previousSong.title !== currentSong.title && previousSong.artist !== currentSong.artist) { if (currentSong.title && currentSong.artist &&
checkCurrentSong() (previousSongs[0].title !== currentSong.title && previousSongs[0].artist !== currentSong.artist) &&
(previousSongs[1].title !== currentSong.title && previousSongs[1].artist !== currentSong.artist)
) {
previousSongs[1] = previousSongs[0]
previousSongs[0] = currentSong
displayCurrentSong()
} }
} catch (e) { } catch (e) {
error = e error = e