more features, handle mpd status
This commit is contained in:
parent
f8dde5672b
commit
5d999cc417
23
main.rb
23
main.rb
@ -36,7 +36,12 @@ end
|
||||
bot = Discordrb::Commands::CommandBot.new token: options[:bot_token], prefix: '!radio '
|
||||
|
||||
bot.command :start do |event|
|
||||
mpc.play
|
||||
if mpc.running?
|
||||
mpc.play
|
||||
else
|
||||
mpc.start
|
||||
mpc.play
|
||||
end
|
||||
event.respond("starting radio")
|
||||
end
|
||||
|
||||
@ -73,6 +78,10 @@ bot.command :shuffle do |event|
|
||||
nil
|
||||
end
|
||||
|
||||
bot.command :nowplaying do |event|
|
||||
event.respond(mpc.nowplaying)
|
||||
end
|
||||
|
||||
bot.command :initialize do |event|
|
||||
event.respond("loading last 50 messages from channel")
|
||||
channel = bot.channel(options[:channel_id])
|
||||
@ -89,5 +98,13 @@ bot.message(in: options[:channel_id],contains: "youtube.com") do |event|
|
||||
parse_songs_from_string(event.content)
|
||||
update_mpd(mpc)
|
||||
end
|
||||
|
||||
bot.run
|
||||
puts("logging into discord")
|
||||
bot.run(true)
|
||||
puts("starting main loop")
|
||||
loop do
|
||||
timer = 15
|
||||
sleep timer
|
||||
if mpc.running?
|
||||
bot.listening(mpc.nowplaying)
|
||||
end
|
||||
end
|
||||
|
13
mpc_shim.rb
13
mpc_shim.rb
@ -43,6 +43,19 @@ class MpcShim
|
||||
return $?.success?
|
||||
end
|
||||
|
||||
def start()
|
||||
`systemctl start mpd` unless `ps aux | grep mpd` != ""
|
||||
`mpc ${host_arg} repeat`
|
||||
end
|
||||
|
||||
def running?()
|
||||
return `ps aux | grep mpd` == ""
|
||||
end
|
||||
|
||||
def nowplaying()
|
||||
return `mpc ${host_arg} | head -n 1`
|
||||
end
|
||||
|
||||
def initialize(hostname=:localhost)
|
||||
if hostname != :localhost
|
||||
@host_arg = "--host #{hostname} "
|
||||
|
Loading…
Reference in New Issue
Block a user