Skip to content

Instantly share code, notes, and snippets.

@wizardishungry
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wizardishungry/9c6fb4b98b4a096b47ea to your computer and use it in GitHub Desktop.
Save wizardishungry/9c6fb4b98b4a096b47ea to your computer and use it in GitHub Desktop.
facebook / xmpp ebooks
#!/usr/bin/env ruby
require 'xmpp4r'
require 'xmpp4r/client'
require 'xmpp4r/roster'
require 'twitter_ebooks'
include Jabber
class Bot
attr_reader :client
def initialize jabber_id, password
@jabber_id = jabber_id
@jabber_password = password
end
def connect
jid = JID.new(@jabber_id)
@model = Ebooks::Model.load("model/MASTER.model")
@client = Client.new jid
@client.connect
@client.auth @jabber_password
@client.send(Presence.new.set_type(:available))
puts "Hurray...!! Connected..!!"
on_message
end
private
def on_message
mainthread = Thread.current
@client.add_message_callback do |message|
unless message.body.nil? && message.type != :error
funny = @model.make_response(message.body, 300)
puts "#{message.from}> #{message.body}\n"
puts "#{message.from}< #{funny}\n"
reply(message, funny)
end
end
Thread.stop
@client.close
end
def reply message, reply_content
reply_message = Message.new(message.from, reply_content)
reply_message.type = message.type
@client.send reply_message
end
end
@bot = Bot.new('llanfairpwllgwyngyllgogerychwyrndrobwllllantysilio@chat.facebook.com', 'MYREALFACEBOOKPASSWORD').connect
@bot.connect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment