Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
163 additions
and
30 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,10 @@ def or | |
join_with 'or' | ||
end | ||
|
||
def same? | ||
uniq.length == 1 | ||
end | ||
|
||
private | ||
|
||
def join_with(separator) | ||
|
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,17 @@ | ||
module SlackGamebot | ||
module Commands | ||
class ChallengeQuestion < SlackRubyBot::Commands::Base | ||
include SlackGamebot::Commands::Mixins::Subscription | ||
|
||
subscribed_command 'challenge?' do |client, data, match| | ||
challenger = ::User.find_create_or_update_by_slack_id!(client, data.user) | ||
arguments = match['expression'].split.reject(&:blank?) if match['expression'] | ||
arguments ||= [] | ||
challenge = ::Challenge.new_from_teammates_and_opponents(client, data.channel, challenger, arguments) | ||
match = ::Match.new(team: client.owner, winners: challenge.challengers, losers: challenge.challenged, scores: []) | ||
client.say(channel: data.channel, text: "#{challenge.challengers.map(&:slack_mention).and} challenging #{challenge.challenged.map(&:slack_mention).and} to a match is worth #{match.elo_s} elo.", gif: 'challenge') | ||
logger.info "CHALLENGE?: #{client.owner} - #{challenge}" | ||
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
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,49 @@ | ||
require 'spec_helper' | ||
|
||
describe SlackGamebot::Commands::ChallengeQuestion, vcr: { cassette_name: 'user_info' } do | ||
let!(:team) { Fabricate(:team) } | ||
let(:app) { SlackGamebot::Server.new(team: team) } | ||
let(:client) { app.send(:client) } | ||
let(:user) { Fabricate(:user, user_name: 'username') } | ||
let(:opponent) { Fabricate(:user) } | ||
it 'displays elo at stake for a singles challenge' do | ||
expect do | ||
expect(message: "#{SlackRubyBot.config.user} challenge? <@#{opponent.user_id}>", user: user.user_id, channel: 'pongbot').to respond_with_slack_message( | ||
"#{user.slack_mention} challenging #{opponent.slack_mention} to a match is worth 48 elo." | ||
) | ||
end.to_not change(Challenge, :count) | ||
end | ||
it 'displays elo at stake for a doubles challenge' do | ||
opponent2 = Fabricate(:user, team: team) | ||
teammate = Fabricate(:user, team: team) | ||
expect do | ||
expect(message: "#{SlackRubyBot.config.user} challenge? #{opponent.slack_mention} #{opponent2.user_name} with #{teammate.user_name}", user: user.user_id, channel: 'pongbot').to respond_with_slack_message( | ||
"#{user.slack_mention} and #{teammate.slack_mention} challenging #{opponent.slack_mention} and #{opponent2.slack_mention} to a match is worth 48 elo." | ||
) | ||
end.to_not change(Challenge, :count) | ||
end | ||
context 'with unbalanced option enabled' do | ||
before do | ||
team.update_attributes!(unbalanced: true) | ||
end | ||
it 'displays elo at stake with different number of opponents' do | ||
opponent1 = Fabricate(:user) | ||
opponent2 = Fabricate(:user) | ||
expect do | ||
expect(message: "#{SlackRubyBot.config.user} challenge? #{opponent1.slack_mention} #{opponent2.slack_mention}", user: user.user_id, channel: 'pongbot').to respond_with_slack_message( | ||
"#{user.slack_mention} challenging #{opponent1.slack_mention} and #{opponent2.slack_mention} to a match is worth 24 and 48 elo." | ||
) | ||
end.to_not change(Challenge, :count) | ||
end | ||
end | ||
context 'subscription expiration' do | ||
before do | ||
team.update_attributes!(created_at: 3.weeks.ago) | ||
end | ||
it 'prevents new challenge questions' do | ||
expect(message: "#{SlackRubyBot.config.user} challenge? <@#{opponent.user_id}>", user: user.user_id, channel: 'pongbot').to respond_with_slack_message( | ||
"Your trial subscription has expired. Subscribe your team for $29.99 a year at https://www.playplay.io/subscribe?team_id=#{team.team_id}&game=#{team.game.name}." | ||
) | ||
end | ||
end | ||
end |