Fixed bug for duplicate song (heavy1)
This commit is contained in:
parent
c7655bf6c9
commit
9e5437f360
1 changed files with 19 additions and 9 deletions
28
index.js
28
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
|
||||
|
|
Loading…
Reference in a new issue