cinch 1.0.0 → 1.0.1

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.
@@ -1,7 +1,7 @@
1
1
  require 'cinch/bot'
2
2
 
3
3
  module Cinch
4
- VERSION = '1.0.0'
4
+ VERSION = '1.0.1'
5
5
 
6
6
  # @return [String]
7
7
  # @todo Handle mIRC color codes more gracefully.
@@ -138,7 +138,7 @@ module Cinch
138
138
  Channel.all.each do |channel|
139
139
  channel.remove_user(user)
140
140
  end
141
- user.synced = false
141
+ msg.user.unsync_all
142
142
  end
143
143
 
144
144
  def on_mode(msg)
@@ -172,7 +172,7 @@ module Cinch
172
172
  Channel.all.each do |channel|
173
173
  channel.remove_user(msg.user)
174
174
  end
175
- msg.user.synced = false
175
+ msg.user.unsync_all
176
176
  end
177
177
 
178
178
  def on_005(msg)
@@ -202,25 +202,11 @@ module Cinch
202
202
  def on_318(msg)
203
203
  # RPL_ENDOFWHOIS
204
204
  user = User.find_ensured(msg.params[1], @bot)
205
- user.instance_variable_set(:@in_whois, false)
205
+
206
206
  if @whois_updates[user].empty? && !user.attr(:unknown?, true, true)
207
- # for some reason, we did not receive user information. one
208
- # reason is freenode throttling WHOIS
209
- Thread.new do
210
- sleep 2
211
- user.whois
212
- end
207
+ user.end_of_whois(nil)
213
208
  else
214
- {
215
- :authname => nil,
216
- :idle => 0,
217
- :secure? => false,
218
- }.merge(@whois_updates[user]).each do |attr, value|
219
- user.sync(attr, value, true)
220
- end
221
-
222
- user.sync(:unknown?, false, true)
223
- user.instance_variable_set(:@synced, true)
209
+ user.end_of_whois(@whois_updates[user])
224
210
  @whois_updates.delete user
225
211
  end
226
212
  end
@@ -327,12 +313,17 @@ module Cinch
327
313
  # ERR_NOSUCHNICK
328
314
  user = User.find_ensured(msg.params[1], @bot)
329
315
  user.sync(:unknown?, true, true)
316
+ if @whois_updates.key?(user)
317
+ user.end_of_whois(nil, true)
318
+ @whois_updates.delete user
319
+ end
330
320
  end
331
321
 
332
322
  def on_402(msg)
333
323
  # ERR_NOSUCHSERVER
324
+
334
325
  if user = User.find(msg.params[1]) # not _ensured, we only want a user that already exists
335
- user.sync(:unknown?, true, true)
326
+ user.end_of_whois(nil, true)
336
327
  @whois_updates.delete user
337
328
  # TODO freenode specific, test on other IRCd
338
329
  end
@@ -30,6 +30,10 @@ module Cinch
30
30
  @synced_attributes.delete(attribute)
31
31
  end
32
32
 
33
+ def unsync_all
34
+ @synced_attributes.clear
35
+ end
36
+
33
37
  # @api private
34
38
  def attr(attribute, data = false, unsync = false)
35
39
  unless unsync
@@ -151,6 +151,9 @@ module Cinch
151
151
 
152
152
  @when_requesting_synced_attribute = lambda {|attr|
153
153
  unless @synced
154
+ @data[:unknown?] = false
155
+ unsync :unknown?
156
+
154
157
  unsync attr
155
158
  whois
156
159
  end
@@ -187,6 +190,58 @@ module Cinch
187
190
  end
188
191
  alias_method :refresh, :whois
189
192
 
193
+ # @param [Hash, nil] values A hash of values gathered from WHOIS,
194
+ # or `nil` if no data was returned
195
+ # @param [Boolean] not_found Has to be true if WHOIS resulted in
196
+ # an unknown user
197
+ # @return [void]
198
+ # @api private
199
+ def end_of_whois(values, not_found = false)
200
+ @in_whois = false
201
+ if not_found
202
+ sync(:unknown?, true, true)
203
+ sync(:idle, 0, true)
204
+ sync(:channels, [], true)
205
+
206
+ fields = @data.keys
207
+ fields.delete(:unknown?)
208
+ fields.delete(:idle)
209
+ fields.delete(:channels)
210
+ fields.each do |field|
211
+ sync(field, nil, true)
212
+ end
213
+
214
+ return
215
+ end
216
+
217
+ if values.nil?
218
+ # for some reason, we did not receive user information. one
219
+ # reason is freenode throttling WHOIS
220
+ Thread.new do
221
+ sleep 2
222
+ whois
223
+ end
224
+ return
225
+ end
226
+
227
+ {
228
+ :authname => nil,
229
+ :idle => 0,
230
+ :secure? => false,
231
+ }.merge(values).each do |attr, value|
232
+ sync(attr, value, true)
233
+ end
234
+ p [self, values, not_found]
235
+ sync(:unknown?, false, true)
236
+ @synced = true
237
+ end
238
+
239
+ # @api private
240
+ def unsync_all
241
+ @synced = false
242
+ super
243
+ end
244
+
190
245
  # Send a message to the user.
191
246
  #
192
247
  # @param [String] message the message
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 1
7
7
  - 0
8
- - 0
9
- version: 1.0.0
8
+ - 1
9
+ version: 1.0.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Lee Jarvis
@@ -15,14 +15,13 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-08-19 00:00:00 +01:00
18
+ date: 2010-08-20 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  name: rspec
23
23
  prerelease: false
24
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
- none: false
26
25
  requirements:
27
26
  - - "="
28
27
  - !ruby/object:Gem::Version
@@ -47,58 +46,58 @@ files:
47
46
  - LICENSE
48
47
  - Rakefile
49
48
  - README.md
50
- - spec/message_spec.rb
49
+ - spec/user_spec.rb
50
+ - spec/plugin_spec.rb
51
51
  - spec/spec_helper.rb
52
+ - spec/bot_spec.rb
52
53
  - spec/spec.opts
54
+ - spec/channel_spec.rb
55
+ - spec/message_spec.rb
53
56
  - spec/cinch_spec.rb
54
- - spec/plugin_spec.rb
55
57
  - spec/irc_spec.rb
56
- - spec/bot_spec.rb
57
- - spec/channel_spec.rb
58
- - spec/user_spec.rb
59
- - lib/cinch.rb
60
- - lib/cinch/bot.rb
61
- - lib/cinch/user.rb
58
+ - lib/cinch/irc.rb
62
59
  - lib/cinch/mask.rb
63
60
  - lib/cinch/exceptions.rb
64
- - lib/cinch/irc.rb
61
+ - lib/cinch/rubyext/module.rb
62
+ - lib/cinch/rubyext/queue.rb
63
+ - lib/cinch/rubyext/string.rb
64
+ - lib/cinch/rubyext/infinity.rb
65
+ - lib/cinch/channel.rb
66
+ - lib/cinch/message.rb
67
+ - lib/cinch/bot.rb
68
+ - lib/cinch/user.rb
69
+ - lib/cinch/constants.rb
70
+ - lib/cinch/callback.rb
71
+ - lib/cinch/syncable.rb
72
+ - lib/cinch/message_queue.rb
65
73
  - lib/cinch/helpers.rb
74
+ - lib/cinch/ban.rb
75
+ - lib/cinch/plugin.rb
66
76
  - lib/cinch/isupport.rb
67
- - lib/cinch/logger/null_logger.rb
68
77
  - lib/cinch/logger/logger.rb
69
78
  - lib/cinch/logger/formatted_logger.rb
70
- - lib/cinch/constants.rb
71
- - lib/cinch/ban.rb
72
- - lib/cinch/message.rb
73
- - lib/cinch/syncable.rb
74
- - lib/cinch/plugin.rb
75
- - lib/cinch/callback.rb
76
- - lib/cinch/channel.rb
77
- - lib/cinch/message_queue.rb
78
- - lib/cinch/rubyext/infinity.rb
79
- - lib/cinch/rubyext/queue.rb
80
- - lib/cinch/rubyext/string.rb
81
- - lib/cinch/rubyext/module.rb
82
- - examples/basic/join_part.rb
83
- - examples/basic/url_shorten.rb
84
- - examples/basic/urban_dict.rb
85
- - examples/basic/msg.rb
86
- - examples/basic/hello.rb
87
- - examples/basic/seen.rb
88
- - examples/basic/memo.rb
89
- - examples/basic/google.rb
90
- - examples/basic/autovoice.rb
91
- - examples/plugins/join_part.rb
92
- - examples/plugins/url_shorten.rb
93
- - examples/plugins/custom_prefix.rb
79
+ - lib/cinch/logger/null_logger.rb
80
+ - lib/cinch.rb
94
81
  - examples/plugins/urban_dict.rb
95
- - examples/plugins/msg.rb
96
- - examples/plugins/hello.rb
97
82
  - examples/plugins/multiple_matches.rb
83
+ - examples/plugins/autovoice.rb
84
+ - examples/plugins/hello.rb
85
+ - examples/plugins/url_shorten.rb
98
86
  - examples/plugins/seen.rb
99
- - examples/plugins/memo.rb
87
+ - examples/plugins/join_part.rb
100
88
  - examples/plugins/google.rb
101
- - examples/plugins/autovoice.rb
89
+ - examples/plugins/memo.rb
90
+ - examples/plugins/msg.rb
91
+ - examples/plugins/custom_prefix.rb
92
+ - examples/basic/urban_dict.rb
93
+ - examples/basic/autovoice.rb
94
+ - examples/basic/hello.rb
95
+ - examples/basic/url_shorten.rb
96
+ - examples/basic/seen.rb
97
+ - examples/basic/join_part.rb
98
+ - examples/basic/google.rb
99
+ - examples/basic/memo.rb
100
+ - examples/basic/msg.rb
102
101
  has_rdoc: true
103
102
  homepage: http://doc.injekt.net/cinch
104
103
  licenses: []
@@ -109,7 +108,6 @@ rdoc_options: []
109
108
  require_paths:
110
109
  - lib
111
110
  required_ruby_version: !ruby/object:Gem::Requirement
112
- none: false
113
111
  requirements:
114
112
  - - ">="
115
113
  - !ruby/object:Gem::Version
@@ -119,7 +117,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
119
117
  - 1
120
118
  version: 1.9.1
121
119
  required_rubygems_version: !ruby/object:Gem::Requirement
122
- none: false
123
120
  requirements:
124
121
  - - ">="
125
122
  - !ruby/object:Gem::Version
@@ -129,7 +126,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
129
126
  requirements: []
130
127
 
131
128
  rubyforge_project:
132
- rubygems_version: 1.3.7
129
+ rubygems_version: 1.3.6
133
130
  signing_key:
134
131
  specification_version: 3
135
132
  summary: An IRC Bot Building Framework