-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SpotiPi now communicates over slack. HTTP interface started.
- Loading branch information
Showing
8 changed files
with
85 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
node_modules/ | ||
config.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"slack_bot_API_key": "your_key_here" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,7 @@ | ||
var io = require('socket.io')(3000); | ||
var stdin = process.openStdin(); | ||
var spotiPi = require('./src/client.js'); | ||
var slack = require('./src/slackInterface.js'); | ||
|
||
process.stdout.write("play/pause/skip/<track uri>: "); | ||
slack(spotiPi); | ||
|
||
stdin.addListener("data", function(d) { | ||
var command = d.toString().trim(); | ||
|
||
switch(command) { | ||
case 'play': | ||
io.emit('play'); | ||
break; | ||
case 'pause': | ||
io.emit('pause'); | ||
break; | ||
case 'skip': | ||
io.emit('skip'); | ||
break; | ||
default: | ||
io.emit('add track to queue', command); | ||
} | ||
process.stdout.write("play/pause/skip/<track uri>: "); | ||
}); | ||
|
||
io.on('connection', function(socket) { | ||
}); | ||
//TODO: have options for http interface, slack interface, etc, defined in config. | ||
//Perhaps eventually move this out into plugins, but that's probably way down the line. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
var io = require('socket.io')(3000); | ||
var request = require('request-promise'); | ||
|
||
io.on('connection', function() { | ||
console.log('Client connected'); | ||
}); | ||
|
||
exports.searchAndAdd = function(searchQuery, callback) { | ||
|
||
console.log(searchQuery); | ||
|
||
request('https://api.spotify.com/v1/search?q=track:' + searchQuery + '&type=track&limit=1') | ||
.then(function (response) { | ||
|
||
var track = JSON.parse(response).tracks.items[0]; | ||
io.emit('add track to queue', track.uri); | ||
|
||
callback({ | ||
name: track.name, | ||
artist: track.artists[0].name | ||
}); | ||
}) | ||
.catch(function (err) { | ||
return "error: " + err; | ||
}); | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
var express = require('express'); | ||
|
||
var app = express(); | ||
app.listen(4000); | ||
|
||
app.get('/play_from_query', function (req, res) { | ||
|
||
if (req.query.hasOwnProperty('q')) { | ||
var searchQuery = req.query.q; | ||
res.send('Searching for "' + searchQuery + '"...'); | ||
//TODO: Communicate with client (passed in?) | ||
} else { | ||
res.send('You must provide a query.'); | ||
} | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
var config = require('../config.json'); | ||
var RtmClient = require('@slack/client').RtmClient; | ||
var RTM_EVENTS = require('@slack/client').RTM_EVENTS; | ||
var token = config.slack_bot_API_key; | ||
var rtm = new RtmClient(token); | ||
|
||
rtm.start(); | ||
|
||
module.exports = function(spotiPiClient) { | ||
|
||
rtm.on(RTM_EVENTS.MESSAGE, function (message) { | ||
if(message.text.indexOf('<@' + rtm.activeUserId + '>') > -1) { | ||
var messageContent = message.text.toLowerCase(); | ||
|
||
console.log(messageContent); | ||
|
||
var index; | ||
|
||
if ((index = messageContent.indexOf('play ')) > -1) { | ||
var searchQuery = messageContent.substring(index + 5, messageContent.length); | ||
spotiPiClient.searchAndAdd(searchQuery, function (track) { | ||
rtm.sendMessage('I\'ve queued up ' + track.name + ' by ' + track.artist, message.channel); | ||
}); | ||
} else if(messageContent.indexOf('night') > -1) { | ||
rtm.sendMessage('Night <@' + message.user + '>', message.channel); | ||
} else { | ||
rtm.sendMessage('Hey <@' + message.user + '>, why don\'t you try asking me to play something?', message.channel); | ||
} | ||
} | ||
}); | ||
|
||
}; |
Empty file.