diff options
-rw-r--r-- | bot.rb | 15 | ||||
-rw-r--r-- | modules/Credits.rb | 17 | ||||
-rw-r--r-- | modules/DDate.rb | 5 |
3 files changed, 27 insertions, 10 deletions
@@ -6,17 +6,13 @@ require_relative 'sasl' require_relative 'config' module Lain + Version = '0.1' + 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...' @@ -26,6 +22,13 @@ module Lain @modules[mod] = Modules.const_get(mod).new self } + $stderr.puts 'Connecting...' + + @cl = Jabber::Client.new(Jabber::JID.new(Config::JID)) + @cl.connect + @cl.auth(Config::Password) + @cl.send(Jabber::Presence.new) + @mucs = {} Config::Rooms.each { |r| diff --git a/modules/Credits.rb b/modules/Credits.rb new file mode 100644 index 0000000..e0289e4 --- /dev/null +++ b/modules/Credits.rb @@ -0,0 +1,17 @@ +# -*- coding: utf-8 -*- +require 'xmpp4r/message' + +require_relative '../module_base' + +module Lain + module Modules + class Credits < Base + def on_message(muc, message) + return unless message.type == :groupchat + return unless /!credits\b/ =~ message.body + + muc.send(Jabber::Message.new(message.to, "Lain (レイン) #{Version}\n\n -- hacked by NeoRaider")) + end + end + end +end diff --git a/modules/DDate.rb b/modules/DDate.rb index 1402648..af9912e 100644 --- a/modules/DDate.rb +++ b/modules/DDate.rb @@ -9,10 +9,7 @@ module Lain return unless message.type == :groupchat return unless /!ddate\b/ =~ message.body - p = IO.popen("ddate") - while (line = p.gets) - muc.send(Jabber::Message.new(message.to, line.chomp)) - end + muc.send(Jabber::Message.new(message.to, IO.popen("ddate").gets(sep=nil).chomp)) end end end |