spotify control
This commit is contained in:
@@ -1,9 +1,10 @@
|
|||||||
TODO:
|
TODO:
|
||||||
☐ Spotify integration
|
☐ Spotify integration
|
||||||
☐ !song -- display current song + link
|
✔ !song -- display current song + link @done (18-12-04 11:24)
|
||||||
☐ !skip -- mods auto-skip, voting for regs
|
✔ !playlist -- display current context / album @done (18-12-04 11:24)
|
||||||
|
✔ !skip -- mods auto-skip @done (18-12-04 11:47)
|
||||||
☐ !volume -- volume adjustment
|
☐ !volume -- volume adjustment
|
||||||
☐ !pause / !resume
|
✔ !pause / !resume @done (18-12-04 11:49)
|
||||||
☐ Web interface for viewers to issue commands
|
☐ Web interface for viewers to issue commands
|
||||||
☐ Admin panel on website for control
|
☐ Admin panel on website for control
|
||||||
☐ Add support for a command to mute/unmute audio sources
|
☐ Add support for a command to mute/unmute audio sources
|
||||||
|
|||||||
49
fgfm.js
49
fgfm.js
@@ -82,12 +82,16 @@ const streamInit = (config, twitch) => {
|
|||||||
|
|
||||||
// Handle show events from the director
|
// Handle show events from the director
|
||||||
director.on('SHOW_STARTED', () => {
|
director.on('SHOW_STARTED', () => {
|
||||||
// Enable vrmode timer
|
manageTimer('vr', 'on');
|
||||||
|
});
|
||||||
|
director.on('SHOW_PAUSED', () => {
|
||||||
|
manageTimer('vr', 'off');
|
||||||
|
});
|
||||||
|
director.on('SHOW_RESUMED', () => {
|
||||||
manageTimer('vr', 'on');
|
manageTimer('vr', 'on');
|
||||||
});
|
});
|
||||||
|
|
||||||
director.on('SHOW_ENDING', (secondsUntilCredits) => {
|
director.on('SHOW_ENDING', (secondsUntilCredits) => {
|
||||||
// Disable vrmode timer
|
|
||||||
manageTimer('vr', 'off');
|
manageTimer('vr', 'off');
|
||||||
|
|
||||||
// Let the chat know the stream is ending soon
|
// Let the chat know the stream is ending soon
|
||||||
@@ -100,10 +104,7 @@ const streamInit = (config, twitch) => {
|
|||||||
|
|
||||||
// Spotify integration
|
// Spotify integration
|
||||||
const spotify = new Spotify(config.spotify);
|
const spotify = new Spotify(config.spotify);
|
||||||
spotify.init()
|
spotify.init();
|
||||||
.then(() => {
|
|
||||||
spotify.getPlaybackState();
|
|
||||||
});
|
|
||||||
|
|
||||||
// Chat commands
|
// Chat commands
|
||||||
const commands = {
|
const commands = {
|
||||||
@@ -298,6 +299,25 @@ const streamInit = (config, twitch) => {
|
|||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
songskip: (cmd) => {
|
||||||
|
spotify.skip();
|
||||||
|
},
|
||||||
|
|
||||||
|
songpause: (cmd) => {
|
||||||
|
spotify.pause();
|
||||||
|
},
|
||||||
|
|
||||||
|
songresume: (cmd) => {
|
||||||
|
spotify.resume();
|
||||||
|
},
|
||||||
|
|
||||||
|
songvol: (cmd) => {
|
||||||
|
let volume = parseInt(cmd.args[1]) || 100;
|
||||||
|
spotify.setVolume(volume)
|
||||||
|
.then(res => twitch.botChat.say(cmd.to, `Volume set to ${volume}`))
|
||||||
|
.catch(err => twitch.botChat.say(cmd.to, `Error setting spotify volume: ${JSON.stringify(err)}`));
|
||||||
|
},
|
||||||
|
|
||||||
reboot: (cmd) => {
|
reboot: (cmd) => {
|
||||||
console.log('Received request from admin to reboot...');
|
console.log('Received request from admin to reboot...');
|
||||||
twitch.botChat.say(cmd.to, 'Rebooting...');
|
twitch.botChat.say(cmd.to, 'Rebooting...');
|
||||||
@@ -436,7 +456,6 @@ const streamInit = (config, twitch) => {
|
|||||||
twitch.botChat.say(cmd.to, snesGames.sort(util.randSort).slice(0, 10).join(' | '));
|
twitch.botChat.say(cmd.to, snesGames.sort(util.randSort).slice(0, 10).join(' | '));
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
// voting to skip current video
|
// voting to skip current video
|
||||||
skip: (cmd) => {
|
skip: (cmd) => {
|
||||||
// check if there is an existing vote to skip for the director.state.currentVideo
|
// check if there is an existing vote to skip for the director.state.currentVideo
|
||||||
@@ -453,6 +472,22 @@ const streamInit = (config, twitch) => {
|
|||||||
skipVote.target = null;
|
skipVote.target = null;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
song: async (cmd) => {
|
||||||
|
spotify.getCurrentSong()
|
||||||
|
.then(async song => {
|
||||||
|
let artists = [];
|
||||||
|
await util.asyncForEach(song.artists, async (artist) => artists.push(artist.name));
|
||||||
|
twitch.botChat.say(cmd.to, `Current Song: ${artists.join(',')} - ${song.name} | ${song.url}`);
|
||||||
|
})
|
||||||
|
.catch(err => twitch.botChat.say(cmd.to, `Error retrieving current song: ${JSON.stringify(err)}`));
|
||||||
|
},
|
||||||
|
|
||||||
|
playlist: (cmd) => {
|
||||||
|
spotify.getCurrentPlaylist()
|
||||||
|
.then(playlist => twitch.botChat.say(cmd.to, `Current Playlist: ${playlist}`))
|
||||||
|
.catch(err => twitch.botChat.say(cmd.to, `Error retrieving current playlist: ${JSON.stringify(err)}`));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -62,16 +62,61 @@ function Spotify(config) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
this.getPlaybackState = () => {
|
this.getCurrentSong = () => {
|
||||||
spotifyApi.getMyCurrentPlaybackState({
|
return new Promise((resolve, reject) => {
|
||||||
})
|
spotifyApi.getMyCurrentPlaybackState({}, (err, data) => {
|
||||||
.then(function(data) {
|
if (err) {
|
||||||
// Output items
|
reject(err);
|
||||||
console.log("Now Playing: ",data.body);
|
return;
|
||||||
}, function(err) {
|
|
||||||
console.log('Something went wrong!', err);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let state = data.body;
|
||||||
|
resolve({
|
||||||
|
artists: state.item.artists,
|
||||||
|
name: state.item.name,
|
||||||
|
album: state.item.album.name,
|
||||||
|
url: state.item.external_urls.spotify
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
this.getCurrentPlaylist = () => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
spotifyApi.getMyCurrentPlaybackState({}, (err, data) => {
|
||||||
|
if (err) {
|
||||||
|
reject(err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let state = data.body;
|
||||||
|
if (state.context) {
|
||||||
|
resolve(state.context.external_urls.spotify);
|
||||||
|
} else {
|
||||||
|
resolve(state.item.album.external_urls.spotify);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
this.skip = () => {
|
||||||
|
return spotifyApi.skipToNext();
|
||||||
|
};
|
||||||
|
|
||||||
|
this.pause = () => {
|
||||||
|
return spotifyApi.pause();
|
||||||
|
};
|
||||||
|
|
||||||
|
this.resume = () => {
|
||||||
|
return spotifyApi.play();
|
||||||
|
};
|
||||||
|
|
||||||
|
this.setVolume = (volume) => {
|
||||||
|
volume = parseInt(volume);
|
||||||
|
if (volume < 0) volume = 0;
|
||||||
|
if (volume > 100) volume = 100;
|
||||||
|
return spotifyApi.setVolume(volume);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Spotify;
|
module.exports = Spotify;
|
||||||
|
|||||||
Reference in New Issue
Block a user