macosx上のejabberdでreudyを動かす

ejabberdをダウンロードしてインストール。
ウェブの管理画面でちょこちょこっとユーザのアカウントを登録。
jabberクライアントはxmpp4rを使ってrubyで書く。
reudyのソースをかなりいじり回す。

require $REUDY_DIR+'/reudy_common'
require 'rubygems'
require 'xmpp4r'
require 'xmpp4r/muc/helper/simplemucclient'
include Jabber

module Gimite

class BotJabberClient
  
  include(Gimite)
  
  SILENT_SECOND= 20.0
  
  def initialize(user)
    @user= user
    @isExitting= false
    @user.client= self
    @user.onBeginConnecting()
  end
  
  def processLoop()
    @prevTime= Time.now()
    @end = false
    Jabber::debug = false

    @client = Client.new(Jabber::JID.new('reudy@black.local'))
    @client.connect
    @client.auth('reudy')
    @client.send(Jabber::Presence.new)

    thread = Thread.current

    @muc = Jabber::MUC::SimpleMUCClient.new(@client)
    @muc.on_message { |time,nick,text| 
      @prevTime= Time.now() #onSilent用。
      puts (time || Time.new).strftime('%I:%M') + " <#{nick}> #{text}"
      if nick != "reudy2"
        @user.onOtherSpeak(nick, text)
      end
    }
    @muc.join(Jabber::JID.new('test2@conference.black.local/reudy2'))

    @watcher = Thread.new do
      while not @end
        @client.send(Jabber::Presence.new)

        if Time.now()-@prevTime>=SILENT_SECOND
          @prevTime= Time.now()
          @user.onSilent()
        end

        sleep 30
      end
    end

    @watcher.join

  end
  
  def outputInfo(s)
    sleep(@user.settings("wait_before_info").to_f()) if @user.settings("wait_before_info")
    @muc.send(Jabber::Message::new(nil, s))
  end
  
  def speak(s)
    @muc.send(Jabber::Message::new(nil, s))
  end

  def exit()
    @muc.exit()
    @end = true
  end

end

end #module Gimite