Sha256: 52f2dba220b54f7a7dca05e6be6c305b5deb05333df3a91936f9d393e81dc264

Contents?: true

Size: 808 Bytes

Versions: 4

Compression:

Stored size: 808 Bytes

Contents

#!/usr/bin/env ruby

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

$:.unshift '../../../../../lib'

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

4 entries across 4 versions & 1 rubygems

Version Path
gmcmillan-xmpp4r-0.6.2 data/doc/xmpp4r/examples/basic/echo.rb
gmcmillan-xmpp4r-0.6.1 data/doc/xmpp4r/examples/basic/echo.rb
gmcmillan-xmpp4r-0.6 data/doc/xmpp4r/examples/basic/echo.rb
gmcmillan-xmpp4r-0.5 data/doc/xmpp4r/examples/basic/echo.rb