Slight code cleanup, many parts still deserves complete rewrite - but it works for me.

master
Pitriss 7 years ago
parent 377b906f9d
commit c56d620785

@ -9,7 +9,6 @@ require 'yaml'
def configload () def configload ()
$CONF = YAML::load_file('conf/config.yml') $CONF = YAML::load_file('conf/config.yml')
puts $CONF.to_hash
# Parsing of the general part of the yaml file # Parsing of the general part of the yaml file
$SCNAME = $CONF["general"]["scriptname"] $SCNAME = $CONF["general"]["scriptname"]
# Parsing of the Jabber part of the yaml file # Parsing of the Jabber part of the yaml file
@ -36,7 +35,6 @@ rescue => error
exit exit
end end
mpd = MPD.new $HOST, $PORT mpd = MPD.new $HOST, $PORT
mpd.connect mpd.connect
@ -127,7 +125,7 @@ def mpdcontrol(mpd,request, mess, type)
end end
end end
def outputsctl (outputs,sitelink) def outputsctl (outputs)
reply = "" reply = ""
def site_state_translate (input) def site_state_translate (input)
if input == 0 then if input == 0 then
@ -140,6 +138,7 @@ def mpdcontrol(mpd,request, mess, type)
|key,var| |key,var|
outfile = var[:name].split.last outfile = var[:name].split.last
weblink = "" weblink = ""
# This part needs to be modified to fit your setup.
case outfile case outfile
when "HQ" when "HQ"
file = "hi.ogg" file = "hi.ogg"
@ -148,7 +147,7 @@ def mpdcontrol(mpd,request, mess, type)
when "MP3" when "MP3"
file = "stream.mp3" file = "stream.mp3"
end end
reply = reply+"#{key} - #{sitelink}/#{file} - #{site_state_translate(var.status)}\n" reply = reply+"#{key} - #{$SITE}/#{file} - #{site_state_translate(var.status)}\n"
} }
return reply return reply
end end
@ -169,11 +168,9 @@ def mpdcontrol(mpd,request, mess, type)
end end
song = mpd.current_song song = mpd.current_song
if song.name != nil then if song.name.nil? then
# do nothing
else
ns = mpd.nextsong ns = mpd.nextsong
answer = "#{answer}\nNext song in queue: #{ns[:artist]} - #{ns[:title]} [album #{ns[:album]}]" answer = "#{answer}\nNext song in the queue: #{ns[:artist]} - #{ns[:title]} [album #{ns[:album]}]"
end end
if type == "0" then if type == "0" then
post "#{sticon} #{answer}" post "#{sticon} #{answer}"
@ -228,9 +225,8 @@ def mpdcontrol(mpd,request, mess, type)
ns = mpd.nextsong ns = mpd.nextsong
nsanswer = "Next song in queue: #{ns[:artist]} - #{ns[:title]} [album #{ns[:album]}]" nsanswer = "Next song in queue: #{ns[:artist]} - #{ns[:title]} [album #{ns[:album]}]"
end end
sitelink = $SITE
outputs = mpd.outputstatus([0, 1, 2]) outputs = mpd.outputstatus([0, 1, 2])
outs = outputsctl(outputs,$SITE) outs = outputsctl(outputs)
if type == "0" then if type == "0" then
post "#{sticon} #{answer}\n#{nsanswer}\nOutputs:\n#{outs}" post "#{sticon} #{answer}\n#{nsanswer}\nOutputs:\n#{outs}"
@ -240,9 +236,9 @@ def mpdcontrol(mpd,request, mess, type)
when "outputs" when "outputs"
outputs = mpd.outputstatus([0, 1, 2]) outputs = mpd.outputstatus([0, 1, 2])
if type == "0" then if type == "0" then
post outputsctl(outputs,$SITE) post outputsctl(outputs)
else else
post outputsctl(outputs,$SITE) => mess.user post outputsctl(outputs) => mess.user
end end
when "version" when "version"
if type == "0" then if type == "0" then
@ -253,17 +249,18 @@ def mpdcontrol(mpd,request, mess, type)
when "help" when "help"
answer = "Stream is located at #{$SITE}/xyz.ext (see outputs)\n answer = "Stream is located at #{$SITE}/xyz.ext (see outputs)\n
Commands:\n Commands:\n
status - Info about played track status - Info about currently played track
nestsong - Info about next song in queue nestsong - Info about the next song in the queue
info - Verbose info about most relevant aspects info - Verbose info about the most relevant aspects
outputs - list all outputs available and its status outputs - Lists all outputs available and its status
toggle <output number> - toggle state of output toggle <output number> - Toggle state of the output
play - start MPD play - start the MPD
pause - pause MPD pause - pause the MPD
stop - stops MPD stop - stops the MPD
next - next song next - next song
prev - previous song\n\n prev - previous song\n\n
For more info ask in room. (eg howto access playlist control)" For more info ask in the room. (eg howto access playlist control)\n
Playlist control (Adding/Removing songs to/from the playlist) is not possible via this bot."
if type == "0" then if type == "0" then
post answer post answer
else else

Loading…
Cancel
Save