Skip to content

Commit

Permalink
Merge pull request crispymtn#8 from leek/feature/updating-help
Browse files Browse the repository at this point in the history
Feature/updating help
  • Loading branch information
dkoch committed Jan 26, 2015
2 parents a142bef + cee1c21 commit c318096
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 9 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ text=<trigger_word> <argument>

Currently the following trigger words are available:

* `play [Spotify URI]` - Starts/resumes playback if no URI is provided. If a URI is given, immedtiately switches to the linked track.
* `play [Spotify URI]` - Starts/resumes playback if no URI is provided. If a URI is given, immediately switches to the linked track.
* `pause` - Pauses playback at the current time.
* `stop` - Stops playback and resets to the beginning of the current track.
* `skip` - Skips (or shuffles) to the next track in the playlist.
* `shuffle` - Toggles shuffle on or off.
* `vol [up|down|0..10]` Turns the volume either up/down one notch or directly to a step between 0 (mute) and 10 (full blast). Also goes to eleven.
* `list [command] [options]` - See playlists section below.
* `status` - Shows the currently playing song, playlist and whether you're shuffling or not.
* `help` - Shows a list of commands with a short explaantion.
* `help` - Shows a list of commands with a short explanation.

If you're using Slack integrations, simply create an outgoing webhook to `http://your-crispyfi-url/handle` that listens to the appropriate trigger words. See below for an example screenshot of our setup. To disable certain funtions, just remove the trigger word.

Expand Down
22 changes: 16 additions & 6 deletions lib/slack_interface/request_handler.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,19 @@ class SlackInterfaceRequestHandler
reply_data = { ok: true }

switch @auth.command
when 'play' then @spotify.play @auth.args[0]
when 'pause' then @spotify.pause()
when 'stop' then @spotify.stop()
when 'skip' then @spotify.skip()
when 'reconnect' then @spotify.connect()
when 'restart' then process.exit 1
when 'mute' then @volume.set 0
when 'unmute' then @volume.set 5

when 'play'
if @auth.args[0]?
@spotify.play @auth.args[0]
else
@spotify.play()

when 'shuffle'
@spotify.toggle_shuffle()
Expand All @@ -45,20 +52,24 @@ class SlackInterfaceRequestHandler
if status
reply_data['text'] = 'Ok.'
else
reply_data['text'] = "I don't understand. Please consult the manual or cry for help."
reply_data['text'] = "I don't understand. Please consult the manual or cry for `help`."
else
str = 'Currently available playlists:'
for key of @spotify.playlists
str += "\n*#{key}* (#{@spotify.playlists[key]})"
reply_data['text'] = str


when 'status'
shuffleword = if @spotify.shuffle then '' else ' not'
reply_data['text'] = "You are currently letting your ears feast on the beautiful tunes titled *#{@spotify.state.track.name}* from *#{@spotify.state.track.artists}*.\nYour currently selected playlist, which you are#{shuffleword} shuffling through, is named *#{@spotify.state.playlist.name}*."
if @spotify.is_paused()
reply_data['text'] = "Playback is currently *paused* on a song titled *#{@spotify.state.track.name}* from *#{@spotify.state.track.artists}*.\nYour currently selected playlist, which you are#{shuffleword} shuffling through, is named *#{@spotify.state.playlist.name}*. Resume playback with `play`."
else if !@spotify.is_playing()
reply_data['text'] = "Playback is currently *stopped*. You can start it again by choosing an available `list`."
else
reply_data['text'] = "You are currently letting your ears feast on the beautiful tunes titled *#{@spotify.state.track.name}* from *#{@spotify.state.track.artists}*.\nYour currently selected playlist, which you are#{shuffleword} shuffling through, is named *#{@spotify.state.playlist.name}*."

when 'help'
reply_data['text'] = "You seem lost. Maybe trying one of these commands will help you out:\n*play* [Spotify-URI] - Starts or resumes playback. If you provide a Spotify-URI it will be played immediately.\n*stop* - Stops playback.\n*pause* - Pauses playback (can be resumed using *play*).\n*skip*: Skips to the next track.\n*list* [listname] - Switches to the specified Spotify-Playlist. If no list name is provided, all available lists will be shown. Playlists need to be configured beforehand, please check the project's readme for details.\n*vol* [up|down|0-10] - Sets the output volume. Either goes up or down one notch or directly to a level ranging from 0 to 10 (inclusive). 0 is mute."
reply_data['text'] = "You seem lost. Here is a list of commands that are available to you: \n \n*Commands*\n> `play [Spotify URI]` - Starts/resumes playback if no URI is provided. If a URI is given, immediately switches to the linked track.\n> `pause` - Pauses playback at the current time.\n> `stop` - Stops playback and resets to the beginning of the current track.\n> `skip` - Skips (or shuffles) to the next track in the playlist.\n> `shuffle` - Toggles shuffle on or off.\n> `vol [up|down|0..10]` Turns the volume either up/down one notch or directly to a step between `0` (mute) and `10` (full blast). Also goes to `11`.\n> `mute` - Same as `vol 0`.\n> `unmute` - Same as `vol 0`.\n> `status` - Shows the currently playing song, playlist and whether you're shuffling or not.\n> `help` - Shows a list of commands with a short explanation.\n \n*Playlists*\n> `list add <name> <Spotify URI>` - Adds a list that can later be accessed under <name>.\n> `list remove <name>` - Removes the specified list.\n> `list rename <old name> <new name>` - Renames the specified list.\n> `list <name>` - Selects the specified list and starts playback."

else
# Fallback to external plugins.
Expand All @@ -75,4 +86,3 @@ class SlackInterfaceRequestHandler
module.exports = (auth, spotify, volume) ->
handler = new SlackInterfaceRequestHandler(auth, spotify, volume)
return handler.endpoints

15 changes: 14 additions & 1 deletion lib/spotify_handler.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class SpotifyHandler
# "playing" in this context means actually playing music or being currently paused (but NOT stopped).
# This is an important distinction regarding the functionality of @spotify.player.resume().
@playing = false
@paused = false

@state = {
shuffle: false
Expand Down Expand Up @@ -84,6 +85,7 @@ class SpotifyHandler

# Pauses playback at the current time. Can be resumed by calling @play().
pause: ->
@paused = true
@spotify.player.pause()
return

Expand All @@ -93,6 +95,7 @@ class SpotifyHandler
# Call @play() to start playing again.
stop: ->
@playing = false
@paused = false
@spotify.player.stop()
return

Expand All @@ -108,9 +111,19 @@ class SpotifyHandler
@shuffle = !@shuffle


# Either starts playing the current track (or next one, if none is set) or immediately
is_playing: ->
return @playing


is_paused: ->
return @paused


# Either starts
the current track (or next one, if none is set) or immediately
# plays the provided track or link.
play: (track_or_link=null) ->
@paused = false
# If a track is given, immediately switch to it
if track_or_link?
switch typeof track_or_link
Expand Down

0 comments on commit c318096

Please sign in to comment.