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

17
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)"
exit
end
puts "starting mpd if not already running"
`systemctl start mpd` unless `ps aux | grep mpd` != ""
mpc.reset()
if mpc.running
puts "starting mpd if not already running"
`systemctl start mpd` unless `ps aux | grep mpd` != ""
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

View File

@ -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)