Skip to content

Commit

Permalink
You can address the bot by its slack @id.
Browse files Browse the repository at this point in the history
Closes #13.
  • Loading branch information
dblock committed Aug 21, 2015
1 parent 7e5e9f1 commit 80e2321
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 11 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
### 0.4.3 (Next)
### 0.4.3 (8/21/2015)

* [#13](https://github.com/dblock/slack-ruby-bot/issues/13): You can now address the bot by its Slack @id - [@dblock](https://githubcom/dblock).

* Your contribution here.

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ The following examples of production-grade bots based on slack-ruby-bot are list

### Commands and Operators

Bots are addressed by name and respond to commands and operators. By default a command class responds, case-insensitively, to its name. A class called `Phone` that inherits from `SlackRubyBot::Commands::Base` responds to `phone` and `Phone` and calls the `call` method when implemented.
Bots are addressed by name and respond to commands and operators. By default a command class responds, case-insensitively, to its name and Slack ID. A class called `Phone` that inherits from `SlackRubyBot::Commands::Base` responds to `phone` and `Phone` and calls the `call` method when implemented.

```ruby
class Phone < SlackRubyBot::Commands::Base
Expand Down Expand Up @@ -107,7 +107,7 @@ Operator match data includes `match['operator']` and `match['expression']`. The

### Bot Aliases

A bot will always respond to its name, but you can specify multiple aliases via the `SLACK_RUBY_BOT_ALIASES` environment variable or via an explicit configuration.
A bot will always respond to its name and Slack ID, but you can specify multiple aliases via the `SLACK_RUBY_BOT_ALIASES` environment variable or via an explicit configuration.

```
SLACK_RUBY_BOT_ALIASES=:pp: table-tennis
Expand Down
5 changes: 1 addition & 4 deletions examples/minimal/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ../..
specs:
slack-ruby-bot (0.4.2)
slack-ruby-bot (0.4.3)
activesupport
giphy (~> 2.0.2)
hashie
Expand Down Expand Up @@ -60,6 +60,3 @@ PLATFORMS

DEPENDENCIES
slack-ruby-bot!

BUNDLED WITH
1.10.6
2 changes: 1 addition & 1 deletion lib/slack-ruby-bot/commands/about.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module SlackRubyBot
module Commands
class Default < Base
command 'about'
match(/^(?<bot>\w*)$/)
match(/^(?<bot>[\w[:punct:]@<>]*)$/)

def self.call(client, data, _match)
send_message_with_gif client, data.channel, SlackRubyBot::ABOUT, 'selfie'
Expand Down
4 changes: 2 additions & 2 deletions lib/slack-ruby-bot/commands/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ def self.operator(*values, &block)

def self.command(*values, &block)
values.each do |value|
match Regexp.new("^(?<bot>[\\w[:punct:]]*)[\\s]+(?<command>#{value})$", Regexp::IGNORECASE), &block
match Regexp.new("^(?<bot>[\\w[:punct:]]*)[\\s]+(?<command>#{value})[\\s]+(?<expression>.*)$", Regexp::IGNORECASE), &block
match Regexp.new("^(?<bot>[\\w[:punct:]@<>]*)[\\s]+(?<command>#{value})$", Regexp::IGNORECASE), &block
match Regexp.new("^(?<bot>[\\w[:punct:]@<>]*)[\\s]+(?<command>#{value})[\\s]+(?<expression>.*)$", Regexp::IGNORECASE), &block
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/slack-ruby-bot/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module Config
attr_accessor :team_id

def names
[user, aliases].compact.flatten
[user, aliases, "<@#{user_id.downcase}>", "<@#{user_id.downcase}>:"].compact.flatten
end

def name?(name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
SlackRubyBot.configure do |c|
c.token = 'testtoken'
c.user = 'rubybot'
c.user_id = 'DEADBEEF'
end
end
end
3 changes: 3 additions & 0 deletions spec/slack-ruby-bot/commands/about_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@ def app
it 'upcase' do
expect(message: SlackRubyBot.config.user.upcase).to respond_with_slack_message(SlackRubyBot::ABOUT)
end
it 'id' do
expect(message: "<@#{SlackRubyBot.config.user_id}>").to respond_with_slack_message(SlackRubyBot::ABOUT)
end
end
6 changes: 6 additions & 0 deletions spec/slack-ruby-bot/commands/hi_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,10 @@ def app
it 'says hi' do
expect(message: "#{SlackRubyBot.config.user} hi").to respond_with_slack_message('Hi <@user>!')
end
it 'says hi to @bot' do
expect(message: "<@#{SlackRubyBot.config.user_id}> hi").to respond_with_slack_message('Hi <@user>!')
end
it 'says hi to @bot: ' do
expect(message: "<@#{SlackRubyBot.config.user_id}>: hi").to respond_with_slack_message('Hi <@user>!')
end
end

0 comments on commit 80e2321

Please sign in to comment.