cinch 0.2.5 → 0.2.6
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.
- data/README.rdoc +2 -2
- data/examples/custom_patterns.rb +2 -2
- data/lib/cinch.rb +1 -1
- data/lib/cinch/base.rb +8 -4
- data/spec/base_spec.rb +1 -1
- metadata +2 -2
data/README.rdoc
CHANGED
@@ -126,7 +126,7 @@ This would provide the following output on IRC
|
|
126
126
|
Cinch also supports custom named parameter patterns. That's right, you can define you own
|
127
127
|
pattern. Just like this:
|
128
128
|
|
129
|
-
bot.add_custom_pattern(:friends, "
|
129
|
+
bot.add_custom_pattern(:friends, "injekt|lee|john|bob")
|
130
130
|
|
131
131
|
bot.plugin("I like :friend-friends", :prefix => false) do |m|
|
132
132
|
m.reply "I like #{m.args[:friend]} too!"
|
@@ -139,7 +139,7 @@ Which would provide the following output on IRC:
|
|
139
139
|
injekt> I like bob
|
140
140
|
Cinch> I like bob too!
|
141
141
|
|
142
|
-
Note though that
|
142
|
+
Note though that although Cinch adds the capturing parenthesis for you, you must escape it yourself
|
143
143
|
|
144
144
|
== Authors
|
145
145
|
Just me at the moment, sad poor lonely me...
|
data/examples/custom_patterns.rb
CHANGED
@@ -5,8 +5,8 @@ bot = Cinch.setup do
|
|
5
5
|
channels %w{ #cinch }
|
6
6
|
end
|
7
7
|
|
8
|
-
bot.add_custom_pattern(:friends, "
|
9
|
-
bot.add_custom_pattern(:hex, "
|
8
|
+
bot.add_custom_pattern(:friends, "injekt|lee|john|bob")
|
9
|
+
bot.add_custom_pattern(:hex, "[\\dA-Fa-f]+")
|
10
10
|
|
11
11
|
bot.plugin("I like :person-friends", :prefix => false) do |m|
|
12
12
|
m.reply "I like #{m.args[:person]} too!"
|
data/lib/cinch.rb
CHANGED
data/lib/cinch/base.rb
CHANGED
@@ -36,6 +36,7 @@ module Cinch
|
|
36
36
|
:realname => "Cinch IRC Microframework",
|
37
37
|
:prefix => '!',
|
38
38
|
:usermode => 0,
|
39
|
+
:password => nil
|
39
40
|
}
|
40
41
|
|
41
42
|
# Options can be passed via a hash, a block, or on the instance
|
@@ -220,13 +221,13 @@ module Cinch
|
|
220
221
|
# port 6667
|
221
222
|
# end
|
222
223
|
#
|
223
|
-
# bot.add_custom_pattern(:number, "
|
224
|
+
# bot.add_custom_pattern(:number, "[0-9]")
|
224
225
|
#
|
225
226
|
# bot.plugin("getnum :foo-number") do |m|
|
226
227
|
# m.reply "Your number was: #{m.args[:foo]}"
|
227
228
|
# end
|
228
229
|
def add_custom_pattern(name, pattern)
|
229
|
-
@custom_patterns[name.to_s] = pattern.to_s
|
230
|
+
@custom_patterns[name.to_s] = "(#{pattern.to_s})"
|
230
231
|
end
|
231
232
|
alias :add_custom_type :add_custom_pattern # backwards
|
232
233
|
alias :add_pattern :add_custom_pattern
|
@@ -234,6 +235,7 @@ module Cinch
|
|
234
235
|
# Run run run
|
235
236
|
def run
|
236
237
|
@irc.connect options.server, options.port
|
238
|
+
@irc.pass options.password if options.password
|
237
239
|
@irc.nick options.nick
|
238
240
|
@irc.user options.username, options.usermode, '*', options.realname
|
239
241
|
|
@@ -265,10 +267,12 @@ module Cinch
|
|
265
267
|
# of loose checking should be put in place
|
266
268
|
rules.each do |rule|
|
267
269
|
unless rule.options.key?(:prefix) || options.prefix == false
|
268
|
-
rule.to_s
|
270
|
+
unless rule.to_s[1..options.prefix.size] == options.prefix
|
271
|
+
rule.to_s.insert(1, options.prefix)
|
272
|
+
end
|
269
273
|
end
|
270
274
|
|
271
|
-
if message.text && mdata = message.text.match(Regexp.new(rule.to_s))
|
275
|
+
if message.text && mdata = message.text.rstrip.match(Regexp.new(rule.to_s))
|
272
276
|
unless rule.keys.empty? || mdata.captures.empty?
|
273
277
|
args = Hash[rule.keys.map {|k| k.to_sym}.zip(mdata.captures)]
|
274
278
|
message.args = args
|
data/spec/base_spec.rb
CHANGED
@@ -108,7 +108,7 @@ describe "Cinch::Base" do
|
|
108
108
|
end
|
109
109
|
|
110
110
|
it "should convert a custom pattern" do
|
111
|
-
@base.add_custom_pattern(:people, "
|
111
|
+
@base.add_custom_pattern(:people, "foo|bar|baz")
|
112
112
|
rule, keys = @base.compile(":foo-people")
|
113
113
|
rule.should == "^(foo|bar|baz)$"
|
114
114
|
end
|