64 lines
1.2 KiB
Ruby
64 lines
1.2 KiB
Ruby
|
require 'xmpp4r'
|
||
|
require 'xmpp4r/muc/helper/mucclient'
|
||
|
|
||
|
require_relative 'sasl'
|
||
|
|
||
|
require_relative 'config'
|
||
|
|
||
|
module Lain
|
||
|
class Bot
|
||
|
Version = '0.1'
|
||
|
|
||
|
def initialize
|
||
|
$stderr.puts "Lain #{Version} starting..."
|
||
|
|
||
|
@cl = Jabber::Client.new(Jabber::JID.new(Config::JID))
|
||
|
@cl.connect
|
||
|
@cl.auth(Config::Password)
|
||
|
@cl.send(Jabber::Presence.new)
|
||
|
|
||
|
@modules = {}
|
||
|
|
||
|
$stderr.puts 'Loading modules...'
|
||
|
|
||
|
Config::Modules.each { |mod|
|
||
|
require_relative "modules/#{mod}"
|
||
|
@modules[mod] = Modules.const_get(mod).new self
|
||
|
}
|
||
|
|
||
|
@mucs = {}
|
||
|
|
||
|
Config::Rooms.each { |r|
|
||
|
muc = Jabber::MUC::MUCClient.new(@cl)
|
||
|
@mucs[r] = muc
|
||
|
|
||
|
muc.add_message_callback { |msg|
|
||
|
@modules.each { | _, mod |
|
||
|
begin
|
||
|
mod.on_message muc, msg
|
||
|
rescue
|
||
|
end
|
||
|
}
|
||
|
}
|
||
|
|
||
|
$stderr.puts "Joining room `#{r}'..."
|
||
|
|
||
|
muc.join("#{r}/#{Config::Nick}")
|
||
|
muc.configure()
|
||
|
}
|
||
|
|
||
|
$stderr.puts 'Startup finished.'
|
||
|
end
|
||
|
|
||
|
def run
|
||
|
@mainthread = Thread.current
|
||
|
Thread.stop
|
||
|
end
|
||
|
|
||
|
def close
|
||
|
@cl.close
|
||
|
end
|
||
|
|
||
|
end
|
||
|
end
|