little fixups
This commit is contained in:
parent
c98e381ae8
commit
6b3bc9b859
17
main.rb
17
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)"
|
puts "Bailing since mpd exists but not mpc (which is needed to control mpd)"
|
||||||
exit
|
exit
|
||||||
end
|
end
|
||||||
puts "starting mpd if not already running"
|
if mpc.running
|
||||||
`systemctl start mpd` unless `ps aux | grep mpd` != ""
|
puts "starting mpd if not already running"
|
||||||
mpc.reset()
|
`systemctl start mpd` unless `ps aux | grep mpd` != ""
|
||||||
|
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
|
||||||
|
@ -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)
|
||||||
|
Loading…
Reference in New Issue
Block a user