summaryrefslogtreecommitdiffstats
path: root/lain.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lain.rb')
-rw-r--r--lain.rb67
1 files changed, 45 insertions, 22 deletions
diff --git a/lain.rb b/lain.rb
index 802d378..4f0301a 100644
--- a/lain.rb
+++ b/lain.rb
@@ -2,30 +2,53 @@
require 'xmpp4r'
-require 'xmpp4r/muc/helper/simplemucclient'
+require 'xmpp4r/muc/helper/mucclient'
require_relative 'sasl'
require_relative 'config'
-include Jabber
-
-
-cl = Jabber::Client.new(Jabber::JID.new(LainConfig::JID))
-cl.connect
-cl.auth(LainConfig::Password)
-cl.send(Presence.new)
-
-mainthread = Thread.current
-
-m = Jabber::MUC::MUCClient.new(cl)
-
-m.add_message_callback { |x|
- puts x
-}
-
-LainConfig::Rooms.each { |r| m.join("#{r}/#{LainConfig::Nick}") }
-
-Thread.stop
-
-cl.close
+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
+
+bot = Lain::Bot.new
+bot.run
+bot.close