Sha256: 8245d714243e3a7f0b246d2975d78a705d3d731d45241f418459d9f6b3d85cf1

Contents?: true

Size: 771 Bytes

Versions: 27

Compression:

Stored size: 771 Bytes

Contents

#!/usr/bin/ruby

# This bot will reply to every message it receives. To end the game, send 'exit'

require 'xmpp4r/client'
include Jabber

# settings
if ARGV.length != 2
  puts "Run with ./echo_thread.rb user@server/resource password"
  exit 1
end
myJID = JID.new(ARGV[0])
myPassword = ARGV[1]
cl = Client.new(myJID)
cl.connect
cl.auth(myPassword)
cl.send(Presence.new)
puts "Connected ! send messages to #{myJID.strip.to_s}."
mainthread = Thread.current
cl.add_message_callback do |m|
  if m.type != :error
    m2 = Message.new(m.from, "You sent: #{m.body}")
    m2.type = m.type
    cl.send(m2)
    if m.body == 'exit'
      m2 = Message.new(m.from, "Exiting ...")
      m2.type = m.type
      cl.send(m2)
      mainthread.wakeup
    end
  end
end
Thread.stop
cl.close

Version data entries

27 entries across 27 versions & 5 rubygems

Version Path
bryanl-xmpp4r-0.3.2 data/doc/xmpp4r/examples/basic/echo.rb
heipei-xmpp4r-0.3.2 data/doc/xmpp4r/examples/basic/echo.rb
sprsquish-blather-0.4.0 examples/xmpp4r/echo.rb
sprsquish-blather-0.4.1 examples/xmpp4r/echo.rb
sprsquish-blather-0.4.2 examples/xmpp4r/echo.rb
sprsquish-blather-0.4.3 examples/xmpp4r/echo.rb
sprsquish-blather-0.4.4 examples/xmpp4r/echo.rb
blather-0.4.16 examples/xmpp4r/echo.rb
blather-0.4.15 examples/xmpp4r/echo.rb
shingara-blather-0.4.14 examples/xmpp4r/echo.rb
blather-0.4.14 examples/xmpp4r/echo.rb
blather-0.4.13 examples/xmpp4r/echo.rb
blather-0.4.12 examples/xmpp4r/echo.rb
blather-0.4.11 examples/xmpp4r/echo.rb
blather-0.4.10 examples/xmpp4r/echo.rb
shingara-blather-0.4.9 examples/xmpp4r/echo.rb
shingara-blather-0.4.8 examples/xmpp4r/echo.rb
blather-0.4.8 examples/xmpp4r/echo.rb
blather-0.4.7 examples/xmpp4r/echo.rb
blather-0.4.6 examples/xmpp4r/echo.rb