summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bot.rb63
-rw-r--r--lain.rb48
2 files changed, 64 insertions, 47 deletions
diff --git a/bot.rb b/bot.rb
new file mode 100644
index 0000000..c6d96ce
--- /dev/null
+++ b/bot.rb
@@ -0,0 +1,63 @@
+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
diff --git a/lain.rb b/lain.rb
index 4f0301a..1ad9b2e 100644
--- a/lain.rb
+++ b/lain.rb
@@ -1,53 +1,7 @@
#!/usr/bin/env ruby
-require 'xmpp4r'
-require 'xmpp4r/muc/helper/mucclient'
-
-require_relative 'sasl'
-
-require_relative 'config'
-
-module Lain
- class Bot
- def initialize
- @cl = Jabber::Client.new(Jabber::JID.new(Config::JID))
- @cl.connect
- @cl.auth(Config::Password)
- @cl.send(Jabber::Presence.new)
-
- @muc = Jabber::MUC::MUCClient.new(@cl)
-
- @modules = {}
-
- @muc.add_message_callback { |msg|
- @modules.each { | _, mod |
- begin
- mod.on_message @muc, msg
- rescue
- end
- }
- }
-
- Config::Modules.each { |mod|
- require_relative "modules/#{mod}"
- @modules[mod] = Modules.const_get(mod).new self
- }
-
- Config::Rooms.each { |r| @muc.join("#{r}/#{Config::Nick}") }
- end
-
- def run
- @mainthread = Thread.current
- Thread.stop
- end
-
- def close
- @cl.close
- end
-
- end
-end
+require_relative 'bot'
bot = Lain::Bot.new
bot.run