-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added set dollars on|off, respond to , but not MSFT.
- Loading branch information
Showing
11 changed files
with
113 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
### Changelog | ||
|
||
* 2/8/2016: [#3](https://github.com/dblock/slack-market/issues/3): Added `set dollars on|off`, respond to $MSFT but not MSFT - [@dblock](https://github.com/dblock). | ||
* 2/5/2016: Respond to single character stocks with a $ sign, eg. `$F` - [@dblock](https://github.com/dblock). | ||
* 2/5/2016: Don't respond to channel mentions that contain what looks like a ticker - [@dblock](https://github.com/dblock). | ||
* 2/4/2016: Initial public release - [@dblock](https://github.com/dblock). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
require 'slack-market/commands/help' | ||
require 'slack-market/commands/quote' | ||
require 'slack-market/commands/set' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
module SlackMarket | ||
module Commands | ||
class Set < SlackRubyBot::Commands::Base | ||
def self.call(client, data, match) | ||
if !match.names.include?('expression') | ||
client.say(channel: data.channel, text: 'Missing setting, eg. _set dollars on_.', gif: 'help') | ||
logger.info "SET: #{client.team} - failed, missing setting" | ||
else | ||
k, v = match['expression'].split(/\W+/, 2) | ||
case k | ||
when 'dollars' then | ||
client.team.update_attributes!(dollars: v.to_b) unless v.nil? | ||
client.say(channel: data.channel, text: "Dollar signs for team #{client.team.name} are #{client.team.dollars? ? 'on!' : 'off.'}", gif: 'dollars') | ||
logger.info "SET: #{client.team} - dollar signs are #{client.team.dollars? ? 'on' : 'off'}" | ||
else | ||
fail "Invalid setting #{k}, you can _set dollars on|off_." | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
require 'spec_helper' | ||
|
||
describe SlackMarket::Commands::Set do | ||
let!(:team) { Fabricate(:team) } | ||
let(:app) { SlackMarket::Server.new(team: team) } | ||
let(:client) { app.send(:client) } | ||
it 'gives help' do | ||
expect(message: "#{SlackRubyBot.config.user} set").to respond_with_slack_message( | ||
'Missing setting, eg. _set dollars on_.' | ||
) | ||
end | ||
context 'dollars' do | ||
it 'shows current value of dollars off' do | ||
expect(message: "#{SlackRubyBot.config.user} set dollars").to respond_with_slack_message( | ||
"Dollar signs for team #{team.name} are off." | ||
) | ||
end | ||
it 'shows current value of dollars on' do | ||
team.update_attributes!(dollars: true) | ||
expect(message: "#{SlackRubyBot.config.user} set dollars").to respond_with_slack_message( | ||
"Dollar signs for team #{team.name} are on!" | ||
) | ||
end | ||
it 'enables dollars' do | ||
team.update_attributes!(dollars: false) | ||
expect(message: "#{SlackRubyBot.config.user} set dollars on").to respond_with_slack_message( | ||
"Dollar signs for team #{team.name} are on!" | ||
) | ||
expect(client.team.dollars).to be true | ||
expect(team.reload.dollars).to be true | ||
end | ||
it 'disables dollars' do | ||
team.update_attributes!(dollars: true) | ||
expect(message: "#{SlackRubyBot.config.user} set dollars off").to respond_with_slack_message( | ||
"Dollar signs for team #{team.name} are off." | ||
) | ||
expect(client.team.dollars).to be false | ||
expect(team.reload.dollars).to be false | ||
end | ||
end | ||
end |