From 6b3bc9b85904149c7b9473bd04457c986763ea03 Mon Sep 17 00:00:00 2001 From: Steve Date: Sun, 1 May 2022 17:10:02 -0400 Subject: [PATCH] little fixups --- main.rb | 17 +++++++++++------ mpc_shim.rb | 8 ++++++-- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/main.rb b/main.rb index 56bcb12..cca2803 100644 --- a/main.rb +++ b/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 - 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 diff --git a/mpc_shim.rb b/mpc_shim.rb index 0deb84c..b77b043 100644 --- a/mpc_shim.rb +++ b/mpc_shim.rb @@ -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)