-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Turn GIFs on/off with set gifs on|off. Closes #57.
- Loading branch information
Showing
13 changed files
with
137 additions
and
5 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
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
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
module SlackGamebot | ||
module Commands | ||
class Set < SlackRubyBot::Commands::Base | ||
def self.call(client, data, match) | ||
user = ::User.find_create_or_update_by_slack_id!(client, data.user) | ||
if !user.captain? | ||
send_message_with_gif client, data.channel, "You're not a captain, sorry.", 'sorry' | ||
logger.info "SET: #{client.team} - #{user.user_name}, failed, not captain" | ||
elsif !match.names.include?('expression') | ||
send_message_with_gif client, data.channel, 'Missing setting, eg. _set gifs off_.', 'help' | ||
logger.info "SET: #{client.team} - #{user.user_name}, failed, missing setting" | ||
else | ||
k, v = match['expression'].split(/\W/, 2) | ||
case k | ||
when 'gifs' | ||
client.team.update_attributes!(gifs: v.to_b) | ||
client.send_gifs = client.team.gifs | ||
if client.team.gifs? | ||
send_message_with_gif client, data.channel, "Enabled GIFs for team #{client.team.name}, thanks captain!", 'fun' | ||
logger.info "SET: #{client.team} - #{user.user_name} enabled GIFs." | ||
else | ||
send_message_with_gif client, data.channel, "Disabled GIFs for team #{client.team.name}, thanks captain!", 'boring' | ||
logger.info "SET: #{client.team} - #{user.user_name} disabled GIFs." | ||
end | ||
else | ||
send_message_with_gif client, data.channel, "Invalid setting #{k}, you can _set gifs on|off_.", 'help' | ||
logger.info "SET: #{client.team} - #{user.user_name}, failed, invalid setting #{k}" | ||
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,50 @@ | ||
require 'spec_helper' | ||
|
||
describe SlackGamebot::Commands::Set, vcr: { cassette_name: 'user_info' } do | ||
let!(:team) { Fabricate(:team) } | ||
let(:app) { SlackGamebot::Server.new(team: team) } | ||
let(:captain) { Fabricate(:user, team: team, user_name: 'username', captain: true) } | ||
context 'captain' do | ||
it 'gives help' do | ||
expect(message: "#{SlackRubyBot.config.user} set").to respond_with_slack_message( | ||
'Missing setting, eg. _set gifs off_.' | ||
) | ||
end | ||
context 'gifs' do | ||
it 'enables GIFs' do | ||
team.update_attributes!(gifs: false) | ||
expect(message: "#{SlackRubyBot.config.user} set gifs on").to respond_with_slack_message( | ||
"Enabled GIFs for team #{team.name}, thanks captain!" | ||
) | ||
expect(team.reload.gifs).to be true | ||
expect(app.send(:client).send_gifs?).to be true | ||
end | ||
it 'disables GIFs' do | ||
team.update_attributes!(gifs: true) | ||
expect(message: "#{SlackRubyBot.config.user} set gifs off").to respond_with_slack_message( | ||
"Disabled GIFs for team #{team.name}, thanks captain!" | ||
) | ||
expect(team.reload.gifs).to be false | ||
expect(app.send(:client).send_gifs?).to be false | ||
end | ||
end | ||
context 'invalid' do | ||
it 'error' do | ||
expect(message: "#{SlackRubyBot.config.user} set invalid on").to respond_with_slack_message( | ||
'Invalid setting invalid, you can _set gifs on|off_.' | ||
) | ||
end | ||
end | ||
end | ||
context 'not captain' do | ||
before do | ||
Fabricate(:user, team: team, captain: true) | ||
captain.demote! | ||
end | ||
it 'cannot set GIFs' do | ||
expect(message: "#{SlackRubyBot.config.user} set gifs true").to respond_with_slack_message( | ||
"You're not a captain, sorry." | ||
) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
require 'spec_helper' | ||
|
||
describe SlackGamebot::Server do | ||
let(:app) { SlackGamebot::Server.new(team: team) } | ||
context 'send_gifs' do | ||
context 'default' do | ||
let(:team) { Fabricate(:team) } | ||
it 'true' do | ||
expect(app.send(:client).send_gifs?).to be true | ||
end | ||
end | ||
context 'on' do | ||
let(:team) { Fabricate(:team, gifs: true) } | ||
it 'true' do | ||
expect(app.send(:client).send_gifs?).to be true | ||
end | ||
end | ||
context 'off' do | ||
let(:team) { Fabricate(:team, gifs: false) } | ||
it 'false' do | ||
expect(app.send(:client).send_gifs?).to be false | ||
end | ||
end | ||
end | ||
end |