botfly 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/botfly.gemspec +1 -1
- data/lib/botfly.rb +6 -4
- data/lib/botfly/bot.rb +3 -2
- data/lib/botfly/common_block_acceptor.rb +3 -2
- data/lib/botfly/responder.rb +3 -1
- data/lib/botfly/responder/subscription_request_responder.rb +1 -0
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.1
|
data/botfly.gemspec
CHANGED
data/lib/botfly.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
|
3
|
+
require 'logger'
|
4
|
+
require 'forwardable'
|
5
|
+
|
3
6
|
require 'xmpp4r'
|
4
7
|
require 'xmpp4r/muc'
|
5
8
|
require 'xmpp4r/roster'
|
@@ -10,8 +13,7 @@ require 'botfly/bot'
|
|
10
13
|
require 'botfly/matcher'
|
11
14
|
require 'botfly/muc_client'
|
12
15
|
|
13
|
-
|
14
|
-
require 'forwardable'
|
16
|
+
|
15
17
|
|
16
18
|
Thread.abort_on_exception = true
|
17
19
|
|
@@ -20,10 +22,10 @@ module Botfly
|
|
20
22
|
@logger = Logger.new(@logfile)
|
21
23
|
return @logger
|
22
24
|
end
|
23
|
-
def Botfly.login(jid,pass,logfile=STDOUT,&block)
|
25
|
+
def Botfly.login(jid,pass,opts={},logfile=STDOUT,&block)
|
24
26
|
@logfile = logfile
|
25
27
|
Botfly.logger.info("BOTFLY: #login")
|
26
|
-
bot = Botfly::Bot.new(jid,pass)
|
28
|
+
bot = Botfly::Bot.new(jid,pass,opts)
|
27
29
|
bot.connect # Must connect first, since MUC requires an active connection to initiate
|
28
30
|
bot.instance_exec(&block)
|
29
31
|
return bot # At this point doesn't get returned, as the thread is stopped
|
data/lib/botfly/bot.rb
CHANGED
@@ -20,10 +20,11 @@ module Botfly
|
|
20
20
|
Botfly.logger.info(" BOT: Connecting to #{@host || @jid}...")
|
21
21
|
@client.connect(@host)
|
22
22
|
@client.auth(@password)
|
23
|
+
@roster = Jabber::Roster::Helper.new(@client)
|
23
24
|
Botfly.logger.info(" BOT: Connected")
|
24
25
|
register_for_callbacks
|
25
26
|
@client.send(Jabber::Presence.new.set_status("Carrier has arrived"))
|
26
|
-
|
27
|
+
|
27
28
|
#Thread.stop
|
28
29
|
end
|
29
30
|
|
@@ -43,7 +44,7 @@ module Botfly
|
|
43
44
|
def register_for_callbacks
|
44
45
|
Botfly.logger.info(" BOT: Registering for callbacks with client")
|
45
46
|
# @client.add_update_callback {|presence| respond_to(:update, :presence => presence) }
|
46
|
-
@
|
47
|
+
@roster.add_subscription_request_callback do |item, pres| # requires Roster helper
|
47
48
|
Botfly.logger.debug(" CB: Got Message")
|
48
49
|
respond_to(:subscription_request, :roster_item => item, :presence => pres)
|
49
50
|
end
|
@@ -5,7 +5,7 @@ module Botfly
|
|
5
5
|
attr_accessor :responders
|
6
6
|
attr_reader :client
|
7
7
|
|
8
|
-
def initialize(
|
8
|
+
def initialize(jid,pass,opts={})
|
9
9
|
@block_state = {}
|
10
10
|
@responders = {}
|
11
11
|
end
|
@@ -37,7 +37,8 @@ module Botfly
|
|
37
37
|
|
38
38
|
def method_missing(type,&block)
|
39
39
|
Botfly.logger.info("#{@obj.to_debug_s}: Bot#on")
|
40
|
-
|
40
|
+
type_name = type.to_s.split('_').map(&:capitalize).join('')
|
41
|
+
klass = Botfly.const_get(@obj.class_prefix + type_name + "Responder")
|
41
42
|
(@obj.responders[type] ||= []) << responder = klass.new(@obj, &block)
|
42
43
|
Botfly.logger.info("#{@obj.to_debug_s}: #{@obj.class_prefix}#{type.to_s.capitalize}Responder added to responder chain")
|
43
44
|
return responder
|
data/lib/botfly/responder.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
+
# TODO: Dry this up
|
1
2
|
require 'botfly/responder/common_responder_methods'
|
2
3
|
require 'botfly/responder/responder'
|
3
4
|
require 'botfly/responder/message_responder'
|
4
5
|
require 'botfly/responder/presence_responder'
|
5
6
|
require 'botfly/responder/muc_responder'
|
6
|
-
require 'botfly/responder/muc_message_responder'
|
7
|
+
require 'botfly/responder/muc_message_responder'
|
8
|
+
require 'botfly/responder/subscription_request_responder'
|