class SlackBot::Matcher
Public Class Methods
new()
click to toggle source
# File lib/slack/matchers/matcher.rb, line 2 def initialize @tests = [] @finally = nil end
Public Instance Methods
from?(user)
click to toggle source
# File lib/slack/matchers/matcher.rb, line 17 def from?(user) @tests << lambda do |msg| user = user.to_s.downcase msg_user = msg.user return false unless msg_user if msg_user.id == user || msg_user.name.downcase == user return true else real = msg_user.real_name return real == user || real.split(' ').map { |n| user == n }.any? end end self end
in?(options={})
click to toggle source
# File lib/slack/matchers/matcher.rb, line 32 def in?(options={}) @tests << lambda do |msg| if options[:id] return msg.channel == options[:id] elsif options[:name] chan = msg.bot.channel(options[:name]) return chan['id'] == msg.channel end end self end
include?(text)
click to toggle source
# File lib/slack/matchers/matcher.rb, line 44 def include?(text) @tests << Proc.new do |msg| msg.text.downcase.include? text end self end
match?(reg)
click to toggle source
# File lib/slack/matchers/matcher.rb, line 51 def match?(reg) @tests << Proc.new { |msg| msg.text.downcase.match reg } self end
run_on(msg)
click to toggle source
# File lib/slack/matchers/matcher.rb, line 7 def run_on(msg) @tests.each do |test| unless test.call(msg) return false end end @finally.call(msg) if @finally return true end
then(&block)
click to toggle source
# File lib/slack/matchers/matcher.rb, line 61 def then(&block) @finally = block end
then_reply(*args)
click to toggle source
# File lib/slack/matchers/matcher.rb, line 65 def then_reply(*args) @finally = Proc.new do |msg| msg.reply(*args) end end
try?(&block)
click to toggle source
# File lib/slack/matchers/matcher.rb, line 56 def try?(&block) @tests << block self end