cinch 0.2.5 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
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, "(injekt|lee|john|bob)")
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 you must wrap your type regexp in capturing parenthesis and escape it yourself
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...
@@ -5,8 +5,8 @@ bot = Cinch.setup do
5
5
  channels %w{ #cinch }
6
6
  end
7
7
 
8
- bot.add_custom_pattern(:friends, "(injekt|lee|john|bob)")
9
- bot.add_custom_pattern(:hex, "([\\dA-Fa-f]+?)")
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
@@ -9,7 +9,7 @@ require 'cinch/rules'
9
9
  require 'cinch/base'
10
10
 
11
11
  module Cinch
12
- VERSION = '0.2.5'
12
+ VERSION = '0.2.6'
13
13
 
14
14
  # Setup bot options and return a new Cinch::Base instance
15
15
  def self.setup(ops={}, &blk)
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, "([0-9])")
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.insert(1, options.prefix) unless rule.to_s[1].chr == options.prefix
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, "(foo|bar|baz)")
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
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 5
9
- version: 0.2.5
8
+ - 6
9
+ version: 0.2.6
10
10
  platform: ruby
11
11
  authors:
12
12
  - Lee 'injekt' Jarvis