Class: Dat::ChatBot
- Inherits:
-
Object
- Object
- Dat::ChatBot
- Defined in:
- lib/dat/bots/chatbot.rb
Constant Summary collapse
- DATBOT_INFO =
{ :jid => '[email protected]', :password => 'robotdat' }
Instance Method Summary collapse
-
#initialize(log_path_prefix = nil) ⇒ ChatBot
constructor
A new instance of ChatBot.
- #run ⇒ Object
Constructor Details
Instance Method Details
#run ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/dat/bots/chatbot.rb', line 16 def run @client = Jabber::Client.new(Jabber::JID.new(DATBOT_INFO[:jid])) @client.connect @client.auth(DATBOT_INFO[:password]) @client.send(Jabber::Presence.new) @client. do |m| if m.type != :error && !m.composing? && !m.body.to_s.strip.empty? body = m.body.to_s from = m.from..to_s @logger[from].log(body) response = @interface.respond(from, body).to_s.strip if !response.empty? msg = Jabber::Message.new(from, response) msg.set_type(:chat) @client.send(msg) @logger[from].log(response) end end end Thread.stop @client.stop end |