little fixups
This commit is contained in:
parent
c98e381ae8
commit
6b3bc9b859
13
main.rb
13
main.rb
@ -28,9 +28,11 @@ if File.exists?("/usr/bin/mpd")
|
||||
puts "Bailing since mpd exists but not mpc (which is needed to control mpd)"
|
||||
exit
|
||||
end
|
||||
if mpc.running
|
||||
puts "starting mpd if not already running"
|
||||
`systemctl start mpd` unless `ps aux | grep mpd` != ""
|
||||
mpc.reset()
|
||||
mpc.reset
|
||||
end
|
||||
end
|
||||
|
||||
bot = Discordrb::Commands::CommandBot.new token: options[:bot_token], prefix: '!radio '
|
||||
@ -101,14 +103,17 @@ end
|
||||
puts("logging into discord")
|
||||
bot.run(true)
|
||||
puts("starting main loop")
|
||||
timer = 15
|
||||
timer = 5
|
||||
loop do
|
||||
sleep timer
|
||||
if mpc.running?
|
||||
if !mpc.playing?
|
||||
current = mpc.nowplaying
|
||||
status = bot.listening(current)
|
||||
puts("listening to #{current}")
|
||||
status = bot.listening=current
|
||||
if status != current
|
||||
puts("tried to update listening status but got #{status} back")
|
||||
elsif status == ""
|
||||
puts("tried to update listening status but have empty now playing")
|
||||
end
|
||||
else
|
||||
bot.idle
|
||||
|
@ -45,15 +45,19 @@ class MpcShim
|
||||
|
||||
def start()
|
||||
`systemctl start mpd` unless `ps aux | grep mpd` != ""
|
||||
`mpc ${@host_arg} repeat`
|
||||
`mpc #{@host_arg} repeat`
|
||||
end
|
||||
|
||||
def running?()
|
||||
return `ps aux | grep mpd` == ""
|
||||
end
|
||||
|
||||
def playing?()
|
||||
return `mpc status | grep playing` == ""
|
||||
end
|
||||
|
||||
def nowplaying()
|
||||
return `mpc ${@host_arg} | head -n 1`
|
||||
return `mpc #{@host_arg} | head -n 1`
|
||||
end
|
||||
|
||||
def initialize(hostname=:localhost)
|
||||
|
Loading…
Reference in New Issue
Block a user