percy 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +9 -1
- data/VERSION +1 -1
- data/lib/percy.rb +48 -42
- metadata +2 -2
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Percy 1.
|
1
|
+
# Percy 1.1.0
|
2
2
|
|
3
3
|
## Configuring and starting the bot
|
4
4
|
|
@@ -113,6 +113,14 @@ env[:channel]<br />
|
|
113
113
|
env[:victim]<br />
|
114
114
|
env[:reason]</tt>
|
115
115
|
|
116
|
+
### Raw Numerics
|
117
|
+
Percy.on '301' do |env|
|
118
|
+
# ...
|
119
|
+
end
|
120
|
+
Variables:
|
121
|
+
|
122
|
+
<tt>env[:params]</tt>
|
123
|
+
|
116
124
|
## Availabe Class Methods
|
117
125
|
|
118
126
|
`Percy.raw(msg)`
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.1.0
|
data/lib/percy.rb
CHANGED
@@ -42,7 +42,7 @@ class Percy
|
|
42
42
|
attr_accessor :traffic_logger, :connected
|
43
43
|
end
|
44
44
|
|
45
|
-
VERSION = 'Percy 1.
|
45
|
+
VERSION = 'Percy 1.1.0 (http://github.com/tbuehlmann/percy)'
|
46
46
|
|
47
47
|
Config = Struct.new(:server, :port, :password, :nick, :username, :verbose, :logging, :reconnect, :reconnect_interval)
|
48
48
|
|
@@ -55,14 +55,8 @@ class Percy
|
|
55
55
|
@connected = false
|
56
56
|
|
57
57
|
# user methods
|
58
|
-
@
|
59
|
-
@
|
60
|
-
@on_connect = []
|
61
|
-
@on_join = []
|
62
|
-
@on_part = []
|
63
|
-
@on_quit = []
|
64
|
-
@on_nickchange = []
|
65
|
-
@on_kick = []
|
58
|
+
@events = Hash.new []
|
59
|
+
@listened_types = [:connect, :channel, :query, :join, :part, :quit, :nickchange, :kick] # + 3-digit numbers
|
66
60
|
|
67
61
|
# observer synchronizer
|
68
62
|
@mutex_observer = Mutex.new
|
@@ -240,23 +234,16 @@ class Percy
|
|
240
234
|
|
241
235
|
# on method
|
242
236
|
def self.on(type = :channel, match = //, &block)
|
237
|
+
unless @listened_types.include?(type) || type =~ /^\d\d\d$/
|
238
|
+
raise ArgumentError, "#{type} is not a supported type"
|
239
|
+
end
|
240
|
+
|
241
|
+
@events[type] = [] if @events[type].empty?
|
243
242
|
case type
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
when :query
|
249
|
-
@on_query << {:match => match, :proc => block}
|
250
|
-
when :join
|
251
|
-
@on_join << block
|
252
|
-
when :part
|
253
|
-
@on_part << block
|
254
|
-
when :quit
|
255
|
-
@on_quit << block
|
256
|
-
when :nickchange
|
257
|
-
@on_nickchange << block
|
258
|
-
when :kick
|
259
|
-
@on_kick << block
|
243
|
+
when :channel || :query
|
244
|
+
@events[type] << {:match => match, :proc => block}
|
245
|
+
else
|
246
|
+
@events[type] << block
|
260
247
|
end
|
261
248
|
end
|
262
249
|
|
@@ -278,27 +265,46 @@ class Percy
|
|
278
265
|
# parses incoming traffic (types)
|
279
266
|
def self.parse_type(type, env = nil)
|
280
267
|
case type
|
281
|
-
when
|
282
|
-
@
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
268
|
+
when /^\d\d\d$/
|
269
|
+
if @events[type]
|
270
|
+
@events[type].each do |block|
|
271
|
+
Thread.new do
|
272
|
+
begin
|
273
|
+
block.call(env)
|
274
|
+
rescue => e
|
275
|
+
if @error_logger
|
276
|
+
@error_logger.error(e.message)
|
277
|
+
e.backtrace.each do |line|
|
278
|
+
@error_logger.error(line)
|
279
|
+
end
|
280
|
+
end
|
288
281
|
end
|
289
|
-
|
282
|
+
end
|
283
|
+
end
|
284
|
+
end
|
285
|
+
# :connect
|
286
|
+
if type =~ /^376|422$/
|
287
|
+
@events[:connect].each do |block|
|
288
|
+
Thread.new do
|
289
|
+
begin
|
290
|
+
unless @connected
|
291
|
+
@connected = true
|
292
|
+
block.call
|
293
|
+
end
|
294
|
+
rescue => e
|
290
295
|
if @error_logger
|
291
296
|
@error_logger.error(e.message)
|
292
297
|
e.backtrace.each do |line|
|
293
298
|
@error_logger.error(line)
|
294
299
|
end
|
295
300
|
end
|
301
|
+
end
|
296
302
|
end
|
297
303
|
end
|
298
304
|
end
|
299
305
|
|
300
306
|
when :channel
|
301
|
-
@
|
307
|
+
@events[type].each do |method|
|
302
308
|
if env[:message] =~ method[:match]
|
303
309
|
Thread.new do
|
304
310
|
begin
|
@@ -331,7 +337,7 @@ class Percy
|
|
331
337
|
self.notice env[:nick], "\001PING #{$1}\001"
|
332
338
|
end
|
333
339
|
|
334
|
-
@
|
340
|
+
@events[type].each do |method|
|
335
341
|
if env[:message] =~ method[:match]
|
336
342
|
Thread.new do
|
337
343
|
begin
|
@@ -349,7 +355,7 @@ class Percy
|
|
349
355
|
end
|
350
356
|
|
351
357
|
when :join
|
352
|
-
@
|
358
|
+
@events[type].each do |block|
|
353
359
|
Thread.new do
|
354
360
|
begin
|
355
361
|
block.call(env)
|
@@ -365,7 +371,7 @@ class Percy
|
|
365
371
|
end
|
366
372
|
|
367
373
|
when :part
|
368
|
-
@
|
374
|
+
@events[type].each do |block|
|
369
375
|
Thread.new do
|
370
376
|
begin
|
371
377
|
block.call(env)
|
@@ -381,7 +387,7 @@ class Percy
|
|
381
387
|
end
|
382
388
|
|
383
389
|
when :quit
|
384
|
-
@
|
390
|
+
@events[type].each do |block|
|
385
391
|
Thread.new do
|
386
392
|
begin
|
387
393
|
block.call(env)
|
@@ -397,7 +403,7 @@ class Percy
|
|
397
403
|
end
|
398
404
|
|
399
405
|
when :nickchange
|
400
|
-
@
|
406
|
+
@events[type].each do |block|
|
401
407
|
Thread.new do
|
402
408
|
begin
|
403
409
|
block.call(env)
|
@@ -413,7 +419,7 @@ class Percy
|
|
413
419
|
end
|
414
420
|
|
415
421
|
when :kick
|
416
|
-
@
|
422
|
+
@events[type].each do |block|
|
417
423
|
Thread.new do
|
418
424
|
begin
|
419
425
|
block.call(env)
|
@@ -449,8 +455,8 @@ class Percy
|
|
449
455
|
when /^PING \S+$/
|
450
456
|
self.raw message.chomp.gsub('PING', 'PONG')
|
451
457
|
|
452
|
-
when /^:\S+
|
453
|
-
self.parse_type(:
|
458
|
+
when /^:\S+ (\d\d\d) /
|
459
|
+
self.parse_type($1, :params => $')
|
454
460
|
|
455
461
|
when /^:(\S+)!(\S+)@(\S+) PRIVMSG #(\S+) :/
|
456
462
|
self.parse_type(:channel, :nick => $1, :user => $2, :host => $3, :channel => "##{$4}", :message => $')
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: percy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- "Tobias B\xC3\xBChlmann"
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-12-
|
12
|
+
date: 2009-12-22 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|