diff --git a/index.js b/index.js index e446765..af69bbc 100644 --- a/index.js +++ b/index.js @@ -32,10 +32,16 @@ let currentSong = { artist: null, title: null } -let previousSong = { - artist: null, - title: null -} +const previousSongs = [ + { + artist: null, + title: null + }, + { + artist: null, + title: null + } +] // Initialisation du bot IRC 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] }) -const checkCurrentSong = () => { - previousSong = currentSong +const displayCurrentSong = () => { // Just for debug console.info(`Now playing: ${currentSong.artist} - ${currentSong.title}`) @@ -89,7 +94,7 @@ if (!process.env.STREAM_TYPE || process.env.STREAM_TYPE === 'radio') { artist: artist } - checkCurrentSong() + displayCurrentSong() }) } else { setInterval(() => { @@ -137,8 +142,13 @@ if (!process.env.STREAM_TYPE || process.env.STREAM_TYPE === 'radio') { break } - if (currentSong.title && currentSong.artist && previousSong.title !== currentSong.title && previousSong.artist !== currentSong.artist) { - checkCurrentSong() + if (currentSong.title && currentSong.artist && + (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) { error = e