Skip to content

Commit

Permalink
[#16] option to make all reactions case insensitive
Browse files Browse the repository at this point in the history
  • Loading branch information
Bartosz Kopiński committed Apr 17, 2015
1 parent f300862 commit 6b634dd
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ class MyBot < Hipbot::Bot
# Auto join criteria (default: :all)
# Accepted values: :all, :public, :private, :none, "room name"
c.join = :private

# Makes all reactions case insensitive (default: true)
c.case_insensitive = true
end
end
```
Expand Down
3 changes: 2 additions & 1 deletion lib/hipbot/configuration.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Hipbot
class Configuration
OPTIONS = [
:adapter, :exception_handler, :helpers, :join,
:adapter, :case_insensitive, :exception_handler, :helpers, :join,
:logger, :password, :plugins, :preloader, :rooms, :status, :storage, :teams, :user
]
attr_accessor *OPTIONS
Expand All @@ -12,6 +12,7 @@ def initialize
end

self.adapter = Adapters::Hipchat
self.case_insensitive = true
self.exception_handler = proc do |e|
Hipbot.logger.error(e.message)
e.backtrace.each { |line| Hipbot.logger.error(line) }
Expand Down
9 changes: 7 additions & 2 deletions lib/hipbot/reaction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,13 @@ def to_private_message?
end

attr_cache :regexps do
Array(options[:regexps]).map do |regexp|
Regexp.new(regexp.source, Regexp::IGNORECASE)
regexps = Array(options[:regexps])
if Hipbot.configuration.case_insensitive
regexps.map do |regexp|
Regexp.new(regexp.source, Regexp::IGNORECASE)
end
else
regexps
end
end

Expand Down

0 comments on commit 6b634dd

Please sign in to comment.