percy 1.4.1 → 1.4.2

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 (6) hide show
  1. data/README.md +32 -9
  2. data/VERSION +1 -1
  3. data/lib/percy.rb +2 -2
  4. data/lib/percy/irc.rb +35 -17
  5. data/percy.gemspec +2 -2
  6. metadata +3 -3
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Percy 1.4.1
1
+ # Percy 1.4.2
2
2
 
3
3
  ## Installing Percy
4
4
  `sudo gem install percy`
@@ -41,7 +41,8 @@ No variables.
41
41
  end
42
42
  Variables:
43
43
 
44
- <tt>env[:nick]<br />
44
+ <tt>env[:type]<br />
45
+ env[:nick]<br />
45
46
  env[:user]<br />
46
47
  env[:host]<br />
47
48
  env[:channel]<br />
@@ -53,7 +54,8 @@ env[:message]</tt>
53
54
  end
54
55
  Variables:
55
56
 
56
- <tt>env[:nick]<br />
57
+ <tt>env[:type]<br />
58
+ env[:nick]<br />
57
59
  env[:user]<br />
58
60
  env[:host]<br />
59
61
  env[:message]</tt>
@@ -64,7 +66,8 @@ env[:message]</tt>
64
66
  end
65
67
  Variables:
66
68
 
67
- <tt>env[:nick]<br />
69
+ <tt>env[:type]<br />
70
+ env[:nick]<br />
68
71
  env[:user]<br />
69
72
  env[:host]<br />
70
73
  env[:channel]</tt>
@@ -75,7 +78,8 @@ env[:channel]</tt>
75
78
  end
76
79
  Variables:
77
80
 
78
- <tt>env[:nick]<br />
81
+ <tt>env[:type]<br />
82
+ env[:nick]<br />
79
83
  env[:user]<br />
80
84
  env[:host]<br />
81
85
  env[:channel]<br />
@@ -87,7 +91,8 @@ env[:message]</tt>
87
91
  end
88
92
  Variables:
89
93
 
90
- <tt>env[:nick]<br />
94
+ <tt>env[:type]<br />
95
+ env[:nick]<br />
91
96
  env[:user]<br />
92
97
  env[:host]<br />
93
98
  env[:message]</tt>
@@ -98,7 +103,8 @@ env[:message]</tt>
98
103
  end
99
104
  Variables:
100
105
 
101
- <tt>env[:nick]<br />
106
+ <tt>env[:type]<br />
107
+ env[:nick]<br />
102
108
  env[:user]<br />
103
109
  env[:host]<br />
104
110
  env[:new_nick]</tt>
@@ -109,7 +115,8 @@ env[:new_nick]</tt>
109
115
  end
110
116
  Variables:
111
117
 
112
- <tt>env[:nick]<br />
118
+ <tt>env[:type]<br />
119
+ env[:nick]<br />
113
120
  env[:user]<br />
114
121
  env[:host]<br />
115
122
  env[:channel]<br />
@@ -122,7 +129,21 @@ env[:reason]</tt>
122
129
  end
123
130
  Variables:
124
131
 
125
- <tt>env[:params]</tt>
132
+ <tt>env[:type]<br />
133
+ env[:params]</tt>
134
+
135
+ ### Multiple event handling
136
+ You can gather types:
137
+
138
+ on [:channel, :query], /foo/ do |env|
139
+ message (env[:channel] || env[:nick]), 'bar!'
140
+ end
141
+
142
+ on ['353', '372'] do |env|
143
+ message '#that_cool_channel', "I just got a #{env[:type]}."
144
+ end
145
+
146
+ You can get the type of event with `env[:type]`, which will be a Symbol like `:channel?`, `:query`, `:quit` or `:"353"`.
126
147
 
127
148
  ## Availabe Class Methods
128
149
 
@@ -222,6 +243,8 @@ Availabe colors through the `COLORS` hash:
222
243
  ## Reloading
223
244
  You can reload your source files with `Percy::IRC.reload` (or just `reload`) without restarting the bot. It is a simple `load $0` where all events are erased and added from the sources again.
224
245
 
246
+ You can check for a reloading process with `Percy::IRC.reloading?` (or just `reloading?`) which is `false` by default, `true` while and `false` after reloading.
247
+
225
248
  ## License
226
249
  Copyright (c) 2009, 2010 Tobias Bühlmann
227
250
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.4.1
1
+ 1.4.2
@@ -5,7 +5,7 @@ require 'percy/formatting'
5
5
  Thread.abort_on_exception = true
6
6
 
7
7
  module Percy
8
- VERSION = 'Percy 1.4.1 (http://github.com/tbuehlmann/percy)'
8
+ VERSION = 'Percy 1.4.2 (http://github.com/tbuehlmann/percy)'
9
9
 
10
10
  # set the percy root directory
11
11
  Object::const_set(:PERCY_ROOT, Pathname.new($0).dirname.expand_path)
@@ -23,4 +23,4 @@ end
23
23
 
24
24
  delegate :action, :channel_limit, :configure, :connect, :is_online, :join, :kick, :message,
25
25
  :mode, :nick, :notice, :on, :part, :quit, :raw, :topic, :users_on, :users_with_status_on,
26
- :reload
26
+ :reload, :reloading?
@@ -25,6 +25,7 @@ module Percy
25
25
  @temp_socket = []
26
26
 
27
27
  @connected = false
28
+ @reloading = false
28
29
 
29
30
  # user methods
30
31
  @events = Hash.new []
@@ -250,17 +251,30 @@ module Percy
250
251
  end
251
252
 
252
253
  # on method
253
- def self.on(type = :channel, match = //, &block)
254
- unless @listened_types.include?(type) || type =~ /^\d\d\d$/
255
- raise ArgumentError, "#{type} is not a supported type"
254
+ def self.on(type = [:channel], match = //, &block)
255
+ if (type.is_a?(Symbol) || type.is_a?(String))
256
+ type = [type]
256
257
  end
257
258
 
258
- @events[type] = [] if @events[type].empty? # @events' default value is [], but it's not possible to add elements to it (weird!)
259
- case type
260
- when :channel || :query
261
- @events[type] << {:match => match, :proc => block}
262
- else
263
- @events[type] << block
259
+ if type.is_a? Array
260
+ type.each do |t|
261
+ unless @listened_types.include?(t) || t =~ /^\d\d\d$/
262
+ raise ArgumentError, "#{t} is not a supported type"
263
+ end
264
+
265
+ if @events[t].empty?
266
+ @events[t] = [] # @events' default value is [], but it's not possible to add elements to it (weird!)
267
+ end
268
+
269
+ case t
270
+ when :channel
271
+ @events[t] << {:match => match, :proc => block}
272
+ when :query
273
+ @events[t] << {:match => match, :proc => block}
274
+ else
275
+ @events[t] << block
276
+ end
277
+ end
264
278
  end
265
279
  end
266
280
 
@@ -283,6 +297,10 @@ module Percy
283
297
  @reloading = false
284
298
  end
285
299
 
300
+ def self.reloading?
301
+ @reloading
302
+ end
303
+
286
304
  private
287
305
 
288
306
  # add observer
@@ -487,28 +505,28 @@ module Percy
487
505
  self.raw message.chomp.gsub('PING', 'PONG')
488
506
 
489
507
  when /^:\S+ (\d\d\d) /
490
- self.parse_type($1, :params => $')
508
+ self.parse_type($1, :type => $1.to_sym, :params => $')
491
509
 
492
510
  when /^:(\S+)!(\S+)@(\S+) PRIVMSG #(\S+) :/
493
- self.parse_type(:channel, :nick => $1, :user => $2, :host => $3, :channel => "##{$4}", :message => $')
511
+ self.parse_type(:channel, :type => :channel, :nick => $1, :user => $2, :host => $3, :channel => "##{$4}", :message => $')
494
512
 
495
513
  when /^:(\S+)!(\S+)@(\S+) PRIVMSG \S+ :/
496
- self.parse_type(:query, :nick => $1, :user => $2, :host => $3, :message => $')
514
+ self.parse_type(:query, :type => :query, :nick => $1, :user => $2, :host => $3, :message => $')
497
515
 
498
516
  when /^:(\S+)!(\S+)@(\S+) JOIN :*(\S+)$/
499
- self.parse_type(:join, :nick => $1, :user => $2, :host => $3, :channel => $4)
517
+ self.parse_type(:join, :type => :join, :nick => $1, :user => $2, :host => $3, :channel => $4)
500
518
 
501
519
  when /^:(\S+)!(\S+)@(\S+) PART (\S+)/
502
- self.parse_type(:part, :nick => $1, :user => $2, :host => $3, :channel => $4, :message => $'.sub(' :', ''))
520
+ self.parse_type(:part, :type => :part, :nick => $1, :user => $2, :host => $3, :channel => $4, :message => $'.sub(' :', ''))
503
521
 
504
522
  when /^:(\S+)!(\S+)@(\S+) QUIT/
505
- self.parse_type(:quit, :nick => $1, :user => $2, :host => $3, :message => $'.sub(' :', ''))
523
+ self.parse_type(:quit, :type => :quit, :nick => $1, :user => $2, :host => $3, :message => $'.sub(' :', ''))
506
524
 
507
525
  when /^:(\S+)!(\S+)@(\S+) NICK :/
508
- self.parse_type(:nickchange, :nick => $1, :user => $2, :host => $3, :new_nick => $')
526
+ self.parse_type(:nickchange, :type => :nickchange, :nick => $1, :user => $2, :host => $3, :new_nick => $')
509
527
 
510
528
  when /^:(\S+)!(\S+)@(\S+) KICK (\S+) (\S+) :/
511
- self.parse_type(:kick, :nick => $1, :user => $2, :host => $3, :channel => $4, :victim => $5, :reason => $')
529
+ self.parse_type(:kick, :type => :kick, :nick => $1, :user => $2, :host => $3, :channel => $4, :victim => $5, :reason => $')
512
530
  end
513
531
 
514
532
  if @observers > 0
@@ -1,10 +1,10 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'percy'
3
- s.version = '1.4.1'
3
+ s.version = '1.4.2'
4
4
  s.summary = '(DSL, EventMachine) IRC Bot Framework inspired by isaac'
5
5
  s.description = 'Percy is an IRC Bot framework inspired by isaac with various changes.'
6
6
  s.homepage = 'http://github.com/tbuehlmann/percy'
7
- s.date = '17.03.2010'
7
+ s.date = '18.03.2010'
8
8
 
9
9
  s.author = 'Tobias Bühlmann'
10
10
  s.email = 'tobias.buehlmann@gmx.de'
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 1
7
7
  - 4
8
- - 1
9
- version: 1.4.1
8
+ - 2
9
+ version: 1.4.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - "Tobias B\xC3\xBChlmann"
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-03-17 00:00:00 +01:00
17
+ date: 2010-03-18 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency