|
|
|
|
@ -1,15 +1,43 @@
|
|
|
|
|
#!/usr/bin/ruby
|
|
|
|
|
$VERBOSE = nil
|
|
|
|
|
$BOTVERSION = "beta 0.0.1"
|
|
|
|
|
scriptname = "botik.rb" # When its changed, bot will switch to dev mode
|
|
|
|
|
|
|
|
|
|
botnick = "StreamCtl"
|
|
|
|
|
$BOTVERSION = "v0.0.2-alpha"
|
|
|
|
|
|
|
|
|
|
require 'rubygems'
|
|
|
|
|
require 'jabbot'
|
|
|
|
|
require 'ruby-mpd'
|
|
|
|
|
require 'yaml'
|
|
|
|
|
|
|
|
|
|
def configload ()
|
|
|
|
|
$CONF = YAML::load_file('conf/config.yml')
|
|
|
|
|
puts $CONF.to_hash
|
|
|
|
|
# Parsing of the general part of the yaml file
|
|
|
|
|
$SCNAME = $CONF["general"]["scriptname"]
|
|
|
|
|
# Parsing of the Jabber part of the yaml file
|
|
|
|
|
$JABB = $CONF["jabber"]
|
|
|
|
|
$NICK = $JABB["nick"]
|
|
|
|
|
$LOGIN = $JABB["login"]
|
|
|
|
|
$PASS = $JABB["password"]
|
|
|
|
|
$RESOURCE = $JABB["resource"]
|
|
|
|
|
$ROOM = $JABB["room"]
|
|
|
|
|
$CSERV = $JABB["confserver"]
|
|
|
|
|
$DROOM = $JABB["devroom"]
|
|
|
|
|
$DCSERV = $JABB["devconfserver"]
|
|
|
|
|
# Parsing of the MPD part of the yaml file
|
|
|
|
|
$MPDC = $CONF["mpd"]
|
|
|
|
|
$HOST = $MPDC["host"]
|
|
|
|
|
$PORT = $MPDC["port"]
|
|
|
|
|
$SITE = $MPDC["site"]
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
begin
|
|
|
|
|
configload()
|
|
|
|
|
rescue => error
|
|
|
|
|
puts "Error during loading configuration!\n" + error.message
|
|
|
|
|
exit
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mpd = MPD.new 'localhost', 6600
|
|
|
|
|
mpd = MPD.new $HOST, $PORT
|
|
|
|
|
mpd.connect
|
|
|
|
|
|
|
|
|
|
class MPD
|
|
|
|
|
@ -200,9 +228,9 @@ def mpdcontrol(mpd,request, mess, type)
|
|
|
|
|
ns = mpd.nextsong
|
|
|
|
|
nsanswer = "Next song in queue: #{ns[:artist]} - #{ns[:title]} [album #{ns[:album]}]"
|
|
|
|
|
end
|
|
|
|
|
sitelink = "https://stream.example.com"
|
|
|
|
|
sitelink = $SITE
|
|
|
|
|
outputs = mpd.outputstatus([0, 1, 2])
|
|
|
|
|
outs = outputsctl(outputs,sitelink)
|
|
|
|
|
outs = outputsctl(outputs,$SITE)
|
|
|
|
|
|
|
|
|
|
if type == "0" then
|
|
|
|
|
post "#{sticon} #{answer}\n#{nsanswer}\nOutputs:\n#{outs}"
|
|
|
|
|
@ -210,12 +238,11 @@ def mpdcontrol(mpd,request, mess, type)
|
|
|
|
|
post "#{sticon} #{answer}\n#{nsanswer}\nOutputs:\n#{outs}" => mess.user
|
|
|
|
|
end
|
|
|
|
|
when "outputs"
|
|
|
|
|
sitelink = "https://stream.example.com"
|
|
|
|
|
outputs = mpd.outputstatus([0, 1, 2])
|
|
|
|
|
if type == "0" then
|
|
|
|
|
post outputsctl(outputs,sitelink)
|
|
|
|
|
post outputsctl(outputs,$SITE)
|
|
|
|
|
else
|
|
|
|
|
post outputsctl(outputs,sitelink) => mess.user
|
|
|
|
|
post outputsctl(outputs,$SITE) => mess.user
|
|
|
|
|
end
|
|
|
|
|
when "version"
|
|
|
|
|
if type == "0" then
|
|
|
|
|
@ -224,7 +251,7 @@ def mpdcontrol(mpd,request, mess, type)
|
|
|
|
|
post "Pitriss MPD stream control bot, version #{$BOTVERSION}" => mess.user
|
|
|
|
|
end
|
|
|
|
|
when "help"
|
|
|
|
|
answer = "Stream is located at https://stream.example.com/xyz.ext (see outputs)\n
|
|
|
|
|
answer = "Stream is located at #{$SITE}/xyz.ext (see outputs)\n
|
|
|
|
|
Commands:\n
|
|
|
|
|
status - Info about played track
|
|
|
|
|
nestsong - Info about next song in queue
|
|
|
|
|
@ -253,21 +280,21 @@ end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
configure do |conf|
|
|
|
|
|
conf.login = "bot@example.com"
|
|
|
|
|
conf.password = "ChangeMe"
|
|
|
|
|
# conf.nick = "StreamCtl"
|
|
|
|
|
conf.nick = botnick
|
|
|
|
|
conf.resource = "StreamCtl"
|
|
|
|
|
if scriptname == File.basename($0) then
|
|
|
|
|
conf.channel = "some-room"
|
|
|
|
|
conf.login = $LOGIN
|
|
|
|
|
conf.password = $PASS
|
|
|
|
|
conf.nick = $NICK
|
|
|
|
|
conf.resource = $RESOURCE
|
|
|
|
|
if $SCNAME == File.basename($0) then
|
|
|
|
|
conf.channel = $ROOM
|
|
|
|
|
conf.server = $CSERV
|
|
|
|
|
else
|
|
|
|
|
conf.channel = "botdev"
|
|
|
|
|
conf.channel = $DROOM
|
|
|
|
|
conf.server = $DCSERV
|
|
|
|
|
end
|
|
|
|
|
conf.server = "conf.example.com"
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
message(/^#{botnick}[,|:| ].*$/i) do |message, params|
|
|
|
|
|
message(/^#{$NICK}[,|:| ].*$/i) do |message, params|
|
|
|
|
|
arr = message.text.split(/\W+/)
|
|
|
|
|
if arr[1].nil? == false then
|
|
|
|
|
if arr[1].chomp.strip != "" then
|
|
|
|
|
|