little fixups

This commit is contained in:
stryan 2022-05-01 17:10:02 -04:00
parent c98e381ae8
commit 6b3bc9b859
2 changed files with 17 additions and 8 deletions

13
main.rb
View File

@ -28,9 +28,11 @@ if File.exists?("/usr/bin/mpd")
puts "Bailing since mpd exists but not mpc (which is needed to control mpd)" puts "Bailing since mpd exists but not mpc (which is needed to control mpd)"
exit exit
end end
if mpc.running
puts "starting mpd if not already running" puts "starting mpd if not already running"
`systemctl start mpd` unless `ps aux | grep mpd` != "" `systemctl start mpd` unless `ps aux | grep mpd` != ""
mpc.reset() mpc.reset
end
end end
bot = Discordrb::Commands::CommandBot.new token: options[:bot_token], prefix: '!radio ' bot = Discordrb::Commands::CommandBot.new token: options[:bot_token], prefix: '!radio '
@ -101,14 +103,17 @@ end
puts("logging into discord") puts("logging into discord")
bot.run(true) bot.run(true)
puts("starting main loop") puts("starting main loop")
timer = 15 timer = 5
loop do loop do
sleep timer sleep timer
if mpc.running? if !mpc.playing?
current = mpc.nowplaying current = mpc.nowplaying
status = bot.listening(current) puts("listening to #{current}")
status = bot.listening=current
if status != current if status != current
puts("tried to update listening status but got #{status} back") puts("tried to update listening status but got #{status} back")
elsif status == ""
puts("tried to update listening status but have empty now playing")
end end
else else
bot.idle bot.idle

View File

@ -45,15 +45,19 @@ class MpcShim
def start() def start()
`systemctl start mpd` unless `ps aux | grep mpd` != "" `systemctl start mpd` unless `ps aux | grep mpd` != ""
`mpc ${@host_arg} repeat` `mpc #{@host_arg} repeat`
end end
def running?() def running?()
return `ps aux | grep mpd` == "" return `ps aux | grep mpd` == ""
end end
def playing?()
return `mpc status | grep playing` == ""
end
def nowplaying() def nowplaying()
return `mpc ${@host_arg} | head -n 1` return `mpc #{@host_arg} | head -n 1`
end end
def initialize(hostname=:localhost) def initialize(hostname=:localhost)