lib/slack-ruby-bot/commands/base.rb in slack-ruby-bot-0.1.0 vs lib/slack-ruby-bot/commands/base.rb in slack-ruby-bot-0.2.0
- old
+ new
@@ -1,10 +1,17 @@
module SlackRubyBot
module Commands
class Base
+ class_attribute :operators
+ class_attribute :commands
+
def self.send_message(channel, text)
- Slack.chat_postMessage(channel: channel, text: text)
+ if text && text.length > 0
+ Slack.chat_postMessage(channel: channel, text: text)
+ else
+ send_message_with_gif channel, 'Nothing to see here.', 'nothing'
+ end
end
def self.send_message_with_gif(channel, text, keywords)
gif = begin
Giphy.random(keywords)
@@ -19,9 +26,31 @@
def self.logger
@logger ||= begin
$stdout.sync = true
Logger.new(STDOUT)
end
+ end
+
+ def self.responds_to_command?(command)
+ commands ? commands.include?(command) : command == default_command_name
+ end
+
+ def self.default_command_name
+ name && name.split(':').last.downcase
+ end
+
+ def self.responds_to_operator?(operator)
+ operators && operators.include?(operator)
+ end
+
+ def self.operator(value)
+ self.operators ||= []
+ self.operators << value.to_s
+ end
+
+ def self.command(value)
+ self.commands ||= []
+ self.commands << value.to_s
end
end
end
end