-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathapp.rb
More file actions
65 lines (51 loc) · 2.31 KB
/
app.rb
File metadata and controls
65 lines (51 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
require "sinatra"
require "json"
require "./spotify.rb"
HELP_TEXT = <<~HELP_TEXT.freeze
Usage:
`/maestro play` -- Resumes playback where Spotify last left off.
`/maestro play <song name>` -- Finds a song by name and plays it.
`/maestro play album <album name>` -- Finds an album by name and plays it.
`/maestro play artist <artist name>` -- Finds an artist by name and plays it.
`/maestro play list <playlist name>` -- Finds a playlist by name and plays it.
`/maestro play uri <uri>` -- Play songs from specific uri.
`/maestro next` -- Skips to the next song in a playlist.
`/maestro prev` -- Returns to the previous song in a playlist.
`/maestro replay` -- Replays the current track from the begining.
`/maestro pos <time>` -- Jumps to a time (in secs) in the current song.
`/maestro pause` -- Pauses (or resumes) Spotify playback.
`/maestro stop` -- Stops playback.
`/maestro quit` -- Stops playback and quits Spotify.
`/maestro restart` -- Quits and restarts Spotify.
`/maestro vol up` -- Increases the volume by 10%.
`/maestro vol down` -- Decreases the volume by 10%.
`/maestro vol <amount>` -- Sets the volume to an amount between 0 and 100.
`/maestro vol` -- Shows the current Spotify volume.
`/maestro status` -- Shows the current player status.
`/maestro share` -- Displays the current song's Spotify URL and URI.
`/maestro share url` -- Displays the current song's Spotify URL.
`/maestro share uri` -- Displays the current song's Spotify URI.
`/maestro toggle shuffle` -- Toggles shuffle playback mode.
`/maestro toggle repeat` -- Toggles repeat playback mode.
HELP_TEXT
# Find methods unique to Spotify class
VALID_COMMANDS = (Spotify.public_methods - Object.public_methods).freeze
def process_spotify_command(args)
command, *params = *split_args(args)
command = command.downcase.to_sym
return [HELP_TEXT, true] if args == "help" || !VALID_COMMANDS.include?(command)
Spotify.public_send(*format_params(command, params))
end
def format_params(command, params)
[command, params.join(" ")].reject(&:empty?)
end
def split_args(args)
args.split(" ")
end
post "/maestro" do
output, success = process_spotify_command(params["text"])
response_code = success ? 200 : 422
body = { response_type: "in_channel", text: output }
content_type :json
[response_code, body.to_json]
end