v0.0.2-beta. Added conf file.

master
Pitriss 7 years ago
parent 3c4071b245
commit 377b906f9d

3
.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:
* Create persistent config file
* Code cleanup
* Automatic fork to background
* Possibly add some more features
* 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:
<botnick>: help
@ -25,4 +32,5 @@ This bot depends on following ruby modules:
* rubygems
* jabbot
* ruby-mpd
* ruby-mpd
* yaml

@ -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

@ -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