-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmopidy.coffee
116 lines (101 loc) · 3.1 KB
/
mopidy.coffee
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# Description
# Control the mopidy music server
#
# Dependencies:
# mopidy
#
# Configuration:
# HUBOT_MOPIDY_WEBSOCKETURL (eg. ws://localhost:8282/mopidy/ws/)
#
#
# Commands:
#
#
#
# Notes:
# None
#
# Author:
# eriley
Mopidy = require("mopidy").Mopidy
mopidy = new Mopidy(webSocketUrl: 'ws://localhost:8282/mopidy/ws/')
online = false
mopidy.on 'state:online', ->
online = true
mopidy.on 'state:offline', ->
online = false
module.exports = (robot) ->
robot.respond /set volume (\d+)/i, (message) ->
newVolume = parseInt(message.match[1])
if online
mopidy.playback.setVolume(newVolume)
message.send("Set volume to #{newVolume}")
else
message.send('Mopidy is offline')
robot.respond /volume\?/i, (message) ->
if online
printCurrentVolume = (volume) ->
if volume
message.send("The Current volume is #{volume}")
else
message.send("Sorry, can't grab current volume")
else
message.send('Mopidy is offline')
mopidy.playback.getVolume().then printCurrentVolume, console.error.bind(console)
robot.respond /what'?s playing/i, (message) ->
if online
printCurrentTrack = (track) ->
if track
message.send("Currently playing: #{track.name} by #{track.artists[0].name} from #{track.album.name}")
else
message.send("No track is playing")
else
message.send('Mopidy is offline')
mopidy.playback.getCurrentTrack().then printCurrentTrack, console.error.bind(console)
robot.respond /next track/i, (message) ->
if online
mopidy.playback.next()
printCurrentTrack = (track) ->
if track
message.send("Now playing: #{track.name} by #{track.artists[0].name} from #{track.album.name}")
else
message.send("No track is playing")
else
message.send('Mopidy is offline')
mopidy.playback.getCurrentTrack().then printCurrentTrack, console.error.bind(console)
robot.respond /mute/i, (message) ->
if online
mopidy.playback.setMute(true)
message.send('Playback muted')
else
message.send('Mopidy is offline')
robot.respond /unmute/i, (message) ->
if online
mopidy.playback.setMute(false)
message.send('Playback unmuted')
else
message.send('Mopidy is offline')
robot.respond /pause music/i, (message) ->
if online
mopidy.playback.pause()
message.send('Music paused')
else
message.send('Mopidy is offline')
robot.respond /resume music/i, (message) ->
if online
mopidy.playback.resume()
message.send('Music resumed')
else
message.send('Mopidy is offline')
robot.respond /shuffle music/i, (message) ->
if online
mopidy.tracklist.setRandom(true)
message.send('Now shuffling')
else
message.send('Mopidy is offline')
robot.respond /stop shuffle/i, (message) ->
if online
mopidy.tracklist.setRandom(false)
message.send('Shuffling has been stopped')
else
message.send('Mopidy is offline')