spotify control
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
TODO:
|
||||
☐ Spotify integration
|
||||
☐ !song -- display current song + link
|
||||
☐ !skip -- mods auto-skip, voting for regs
|
||||
✔ !song -- display current song + link @done (18-12-04 11:24)
|
||||
✔ !playlist -- display current context / album @done (18-12-04 11:24)
|
||||
✔ !skip -- mods auto-skip @done (18-12-04 11:47)
|
||||
☐ !volume -- volume adjustment
|
||||
☐ !pause / !resume
|
||||
✔ !pause / !resume @done (18-12-04 11:49)
|
||||
☐ Web interface for viewers to issue commands
|
||||
☐ Admin panel on website for control
|
||||
☐ 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
|
||||
director.on('SHOW_STARTED', () => {
|
||||
// Enable vrmode timer
|
||||
manageTimer('vr', 'on');
|
||||
});
|
||||
director.on('SHOW_PAUSED', () => {
|
||||
manageTimer('vr', 'off');
|
||||
});
|
||||
director.on('SHOW_RESUMED', () => {
|
||||
manageTimer('vr', 'on');
|
||||
});
|
||||
|
||||
director.on('SHOW_ENDING', (secondsUntilCredits) => {
|
||||
// Disable vrmode timer
|
||||
manageTimer('vr', 'off');
|
||||
|
||||
// Let the chat know the stream is ending soon
|
||||
@@ -100,10 +104,7 @@ const streamInit = (config, twitch) => {
|
||||
|
||||
// Spotify integration
|
||||
const spotify = new Spotify(config.spotify);
|
||||
spotify.init()
|
||||
.then(() => {
|
||||
spotify.getPlaybackState();
|
||||
});
|
||||
spotify.init();
|
||||
|
||||
// Chat 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) => {
|
||||
console.log('Received request from admin to reboot...');
|
||||
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(' | '));
|
||||
},
|
||||
|
||||
|
||||
// voting to skip current video
|
||||
skip: (cmd) => {
|
||||
// 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;
|
||||
}
|
||||
},
|
||||
|
||||
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 = () => {
|
||||
spotifyApi.getMyCurrentPlaybackState({
|
||||
})
|
||||
.then(function(data) {
|
||||
// Output items
|
||||
console.log("Now Playing: ",data.body);
|
||||
}, function(err) {
|
||||
console.log('Something went wrong!', err);
|
||||
this.getCurrentSong = () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
spotifyApi.getMyCurrentPlaybackState({}, (err, data) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user