rumpy 0.9.11 → 0.9.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. data/lib/rumpy.rb +21 -10
  2. metadata +4 -4
data/lib/rumpy.rb CHANGED
@@ -67,8 +67,9 @@ module Rumpy
67
67
  connect
68
68
  @logger.debug 'clear wrong users'
69
69
  clear_users
70
- start_subscription_callback
71
- start_message_callback
70
+ set_subscription_callback
71
+ set_message_callback
72
+ set_iq_callback
72
73
  @logger.info 'Bot is going ONLINE'
73
74
  @client.send Jabber::Presence.new.set_priority(@priority).set_status(@status)
74
75
 
@@ -82,7 +83,7 @@ module Rumpy
82
83
  rescue ActiveRecord::StatementInvalid
83
84
  @logger.warn 'Statement Invalid catched'
84
85
  @logger.info 'Reconnecting to database'
85
- @main_model.connection.reconnect!
86
+ reconnect_db!
86
87
  retry
87
88
  rescue => e
88
89
  $logger.error e.inspect
@@ -149,11 +150,10 @@ module Rumpy
149
150
  end
150
151
  end
151
152
  @roster.items.each do |jid, item|
152
- user = @main_model.find_by_jid jid
153
+ user = find_user_by_jid jid
153
154
  if user.nil? then
154
155
  @logger.info "deleting from roster user with jid #{jid}"
155
156
  item.remove
156
- next
157
157
  elsif item.subscription != :both then
158
158
  @logger.info "deleting from roster&database user with jid #{jid}"
159
159
  item.remove
@@ -162,7 +162,7 @@ module Rumpy
162
162
  end
163
163
  end
164
164
 
165
- def start_subscription_callback
165
+ def set_subscription_callback
166
166
  @roster.add_subscription_request_callback do |item, presence|
167
167
  jid = presence.from
168
168
  @roster.accept_subscription jid
@@ -184,17 +184,25 @@ module Rumpy
184
184
  rescue ActiveRecord::StatementInvalid
185
185
  @logger.warn 'Statement Invalid catched'
186
186
  @logger.info 'Reconnecting to database'
187
- @main_model.connection.reconnect!
187
+ reconnect_db!
188
188
  retry
189
189
  end
190
190
  end
191
191
  end
192
192
 
193
- def start_message_callback
193
+ def find_user_by_jid(jid)
194
+ @main_model.find_by_jid jid
195
+ end
196
+
197
+ def reconnect_db!
198
+ @main_model.connection.reconnect!
199
+ end
200
+
201
+ def set_message_callback
194
202
  @client.add_message_callback do |msg|
195
203
  begin
196
204
  if msg.type != :error and msg.body and msg.from then
197
- if user = @main_model.find_by_jid(msg.from) then
205
+ if user = find_user_by_jid(msg.from) then
198
206
  @logger.debug "get normal message from #{msg.from}"
199
207
  pars_results = parser_func msg.body
200
208
  @logger.debug "parsed message: #{pars_results.inspect}"
@@ -214,13 +222,16 @@ module Rumpy
214
222
  rescue ActiveRecord::StatementInvalid
215
223
  @logger.warn 'Statement Invalid catched!'
216
224
  @logger.info 'Reconnecting to database'
217
- @main_model.connection.reconnect!
225
+ reconnect_db!
218
226
  retry
219
227
  rescue => e
220
228
  @logger.error e.inspect
221
229
  @logger.error e.backtrace
222
230
  end
223
231
  end
232
+ end
233
+
234
+ def set_iq_callback
224
235
  @client.add_iq_callback do |iq|
225
236
  @logger.debug "got iq #{iq.inspect}"
226
237
  if iq.type == :get then # hack for pidgin (STOP USING IT)
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rumpy
3
3
  version: !ruby/object:Gem::Version
4
- hash: 45
4
+ hash: 35
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 9
9
- - 11
10
- version: 0.9.11
9
+ - 12
10
+ version: 0.9.12
11
11
  platform: ruby
12
12
  authors:
13
13
  - Tsokurov A.G.
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-07-20 00:00:00 +03:00
19
+ date: 2011-08-10 00:00:00 +03:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency