peinwag / p_xmpp_BOT

my xmpp bot
0 stars 0 forks source link

Some improvements or tips #1

Closed danielbayerlein closed 11 years ago

danielbayerlein commented 11 years ago

Gemfile

source 'https://rubygems.org'

gem 'xmpp4r', '~> 0.5'

bot.rb

require 'rubygems'
require 'xmpp4r'
require 'xmpp4r/muc/helper/simplemucclient'
require 'yaml'

class Bot
  attr_accessor :config, :client, :muc

  def initialize(config)
    self.config = config
    self.client = Jabber::Client.new(config[:jid])
    self.muc = Jabber::MUC::SimpleMUCClient.new(client)
    Jabber.debug = true if Jabber.logger = config[:debug]
    self
  end

  def connect
    client.connect
    client.auth(config[:password])
    client.send(Jabber::Presence.new.set_type(:available))
    self
  end

  def idle
    puts 'running'
    loop { sleep 1 }
end

config = YAML.load_file('../config/jabber.yml')
config[:debug] = Logger.new(STDOUT)

Bot.new(config).connect.idle
peinwag commented 11 years ago

thanks alot I appriciate it ;)