v0.0.2-beta. Added conf file.

master
Pitriss 7 years ago
parent 3c4071b245
commit 377b906f9d

1
.gitignore vendored

@ -1 +1,2 @@
*~ *~
conf/config.yml

@ -10,11 +10,18 @@ This software is still in alpha stage. It works for me so I can't promise update
TODO: TODO:
* Create persistent config file
* Code cleanup * Code cleanup
* Automatic fork to background
* Possibly add some more features * Possibly add some more features
* Make it work in all versions of private messages * Make it work in all versions of private messages
Howto start:
* Clone this repo
* In conf directory copy config.yml.sample to config.yml.sample
* Edit config.yml accordingly
* Launch botik.rb
Do: Do:
<botnick>: help <botnick>: help
@ -26,3 +33,4 @@ This bot depends on following ruby modules:
* rubygems * rubygems
* jabbot * jabbot
* ruby-mpd * ruby-mpd
* yaml

@ -1,15 +1,43 @@
#!/usr/bin/ruby #!/usr/bin/ruby
$VERBOSE = nil $VERBOSE = nil
$BOTVERSION = "beta 0.0.1" $BOTVERSION = "v0.0.2-alpha"
scriptname = "botik.rb" # When its changed, bot will switch to dev mode
botnick = "StreamCtl"
require 'rubygems' require 'rubygems'
require 'jabbot' require 'jabbot'
require 'ruby-mpd' 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 mpd.connect
class MPD class MPD
@ -200,9 +228,9 @@ 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 = "https://stream.example.com" sitelink = $SITE
outputs = mpd.outputstatus([0, 1, 2]) outputs = mpd.outputstatus([0, 1, 2])
outs = outputsctl(outputs,sitelink) outs = outputsctl(outputs,$SITE)
if type == "0" then if type == "0" then
post "#{sticon} #{answer}\n#{nsanswer}\nOutputs:\n#{outs}" 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 post "#{sticon} #{answer}\n#{nsanswer}\nOutputs:\n#{outs}" => mess.user
end end
when "outputs" when "outputs"
sitelink = "https://stream.example.com"
outputs = mpd.outputstatus([0, 1, 2]) outputs = mpd.outputstatus([0, 1, 2])
if type == "0" then if type == "0" then
post outputsctl(outputs,sitelink) post outputsctl(outputs,$SITE)
else else
post outputsctl(outputs,sitelink) => mess.user post outputsctl(outputs,$SITE) => mess.user
end end
when "version" when "version"
if type == "0" then if type == "0" then
@ -224,7 +251,7 @@ def mpdcontrol(mpd,request, mess, type)
post "Pitriss MPD stream control bot, version #{$BOTVERSION}" => mess.user post "Pitriss MPD stream control bot, version #{$BOTVERSION}" => mess.user
end end
when "help" 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 Commands:\n
status - Info about played track status - Info about played track
nestsong - Info about next song in queue nestsong - Info about next song in queue
@ -253,21 +280,21 @@ end
configure do |conf| configure do |conf|
conf.login = "bot@example.com" conf.login = $LOGIN
conf.password = "ChangeMe" conf.password = $PASS
# conf.nick = "StreamCtl" conf.nick = $NICK
conf.nick = botnick conf.resource = $RESOURCE
conf.resource = "StreamCtl" if $SCNAME == File.basename($0) then
if scriptname == File.basename($0) then conf.channel = $ROOM
conf.channel = "some-room" conf.server = $CSERV
else else
conf.channel = "botdev" conf.channel = $DROOM
conf.server = $DCSERV
end end
conf.server = "conf.example.com"
end end
message(/^#{botnick}[,|:| ].*$/i) do |message, params| message(/^#{$NICK}[,|:| ].*$/i) do |message, params|
arr = message.text.split(/\W+/) arr = message.text.split(/\W+/)
if arr[1].nil? == false then if arr[1].nil? == false then
if arr[1].chomp.strip != "" then if arr[1].chomp.strip != "" then

@ -0,0 +1,19 @@
# All values in this config file are required
# If you omit some values, bot will most likely crash
general:
scriptname: "botik.rb"
jabber:
nick: "BotNick"
login: "bot@example.com"
password: "ChangeMe"
resource: "StreamCtl"
# Will be applied when general - scriptname matches the real filename
room: "some-room"
confserver: "conf.example.com"
# Will be applied when general - scriptname differs from the real filename
devroom: "some-dev-room"
devconfserver: "conf.example.com"
mpd:
host: localhost
port: 6600
site: "https://stream.example.com"
Loading…
Cancel
Save