lita-resistance 0.2.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e185d4c35a4675f50a74b0dc7cb6bcc1c5904777
4
- data.tar.gz: 2722685943a3e76e24046df7b5963487264aa044
3
+ metadata.gz: 4363c72dc88d6f40ca3ab0d35797401f1c556852
4
+ data.tar.gz: 7d4cd10706c1e6180c44506a6e47a5b4ae310d4d
5
5
  SHA512:
6
- metadata.gz: 3aa2752e5bad07a5813181ed3d758d1f0de9b6c1d4417b3163e159af928c8948a8994babb273fca6e1acc7acc4e20277a28d552a8b5a4e049dd2511d69d4fca4
7
- data.tar.gz: c89c5153407acdd28053ce8365788aac102d2b66629bba256e38d054c3a631e23377733bf3a63f19af83f2bb24d79641cfe65bfc49488af59cce8b843d778969
6
+ metadata.gz: 469066210687fa7d82e1a7ba7ede2e51a878a557f83506d04d611b78c02d2f7b8214f7401c1f22630d5314270009565b55facab225ade8cf9bd1010ee1831d5b
7
+ data.tar.gz: 0d299ad027f0f07813fb61b092dcd88550d8fe0b9b2ea84a6cb4556ed849eed59e575f2f358bfbb323eb032a8a10c4f01565cf0fecfff36dd123dae9c3d848f4
data/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  [![Build Status](https://travis-ci.org/DeonHua/lita-resistance.svg?branch=master)](https://travis-ci.org/DeonHua/lita-resistance)
4
4
  [![Gem Version](https://badge.fury.io/rb/lita-resistance.svg)](https://badge.fury.io/rb/lita-resistance)
5
+ [![Coverage Status](https://coveralls.io/repos/DeonHua/lita-resistance/badge.svg?branch=master&service=github)](https://coveralls.io/github/DeonHua/lita-resistance?branch=master)
6
+ [![Code Climate](https://codeclimate.com/github/DeonHua/lita-resistance/badges/gpa.svg)](https://codeclimate.com/github/DeonHua/lita-resistance)
5
7
 
6
8
  Plays a game of resistance by assigning roles to users you mention in chat.
7
9
 
@@ -15,18 +17,48 @@ gem "lita-resistance"
15
17
 
16
18
  ## Usage
17
19
 
18
- `lita resistance [users]` - Assigns the roles of spy/resistance to users you mention.
20
+ `lita resistance help` - Provides detailed help (this readme file)
19
21
 
20
- ### Examples
22
+ `lita resistance N [users]` - Assigns the roles of spy/resistance to users you mention, with no special characters.
21
23
 
22
- `lita resistance @player1 @player2 @player3 @player4 @player5`
24
+ `lita resistance [CBSAFD] [users]` - Assigns special characters to the users mentioned, the remainder (if any) will receive 'vanilla' spy/resistance roles.
25
+
26
+ ### Special Characters
27
+ **Note:** The number of special characters chosen for each team must be less than the number of characters on that team.
28
+
29
+ The number of spies is always (Players + 2)/3 **rounded down**.
30
+
31
+ #### Resistance (Good)
32
+ Commander (**C**) - Knows all spies except Deep Cover.
33
+
34
+ Body Guard (**B**) - Knows Commander and False Commander.
35
+
36
+ #### Spies (Bad)
37
+
38
+ Blind Spy (**S**) - Doesn't know the other spies. The other spies don't know Blind Spy.
39
+
40
+ Assassin (**A**) - If Resistance successfully completes 3 missions, Assassin can guess Commander. If Assassin is correct, Spies win.
41
+
42
+ False Commander (**F**) - Appears as Commander to Bodyguard.
43
+
44
+ Deep Cover (**D**) - Does not appear as spy to Commander. If played with Commander and without Assassin, can take Assassin's role.
45
+
46
+ ### Examples (No Special Characters)
47
+
48
+ `lita resistance N @player1 @player2 @player3 @player4 @player5`
23
49
 
24
50
  You don't need to include the `@` symbol:
25
51
 
26
- `lita resistance player1 player2 player3 player4 player5`
52
+ `lita resistance N player1 player2 player3 player4 player5`
27
53
 
28
54
  You can also do a combination of both:
29
55
 
30
- `lita resistance @player1 @player2 player3 player4 player5`
56
+ `lita resistance N @player1 @player2 player3 player4 player5`
57
+
58
+ #### Special Characters
59
+
60
+ Assigns Assassin and Commander:
61
+
62
+ `lita resistance CA @player1 @player2 @player3 @player4 @player5`
31
63
 
32
- [![forthebadge](http://forthebadge.com/images/badges/built-with-love.svg)](http://forthebadge.com)
64
+ [![forthebadge](http://forthebadge.com/images/badges/built-with-love.svg)](http://forthebadge.com)
@@ -2,26 +2,56 @@ module Lita
2
2
  module Handlers
3
3
  class Resistance < Handler
4
4
 
5
- route(/resistance .+/, :play, command: true, help: {'resistance [users]' => 'Starts a game of resistance with the people you mention.'})
6
- def play(response)
7
- all_users = response.args.uniq
5
+ route(/resistance help/, :help, command: true, help: {'resistance help' => 'Provides detailed help with Resistance commands.'})
8
6
 
9
- if all_users.length < 5
10
- response.reply('You need at least 5 players for Resistance.')
11
- return
12
- elsif all_users.length > 10
13
- response.reply('You cannot play a game of Resistance with more than 10 players.')
14
- return
15
- end
7
+ route(/resistance [NCBSAFD]+ .+/, :play, command: true, help: {'resistance N|[CBSAFD] [users]' => 'Starts a game of resistance with the people you mention.'})
16
8
 
17
- # Remove any "@" from usernames
18
- all_users.map! {|username|
9
+ def help (response)
10
+ response.reply(render_template("help"))
11
+ end
12
+
13
+ # Remove any "@" from usernames
14
+ def normalize_input! (all_users)
15
+ all_users.map! do |username|
19
16
  if username[0] == '@'
20
- username = username[1, username.length-1]
17
+ username[1, username.length-1]
21
18
  else
22
- username = username
19
+ username
23
20
  end
24
- }
21
+ end
22
+ end
23
+
24
+ def verify_characters (characters)
25
+ if characters != characters.uniq
26
+ raise 'You cannot have more than one of the same character.'
27
+ end
28
+
29
+ if characters.include?('N') && characters.length > 1
30
+ raise 'You cannot include special characters with N.'
31
+ end
32
+
33
+ # Num of Special Characters on spies doesn't exceed num of spies
34
+ if !characters.include?('N') && (characters - ['C', 'B']).length > @num_spies
35
+ raise 'You cannot have more special characters on spies than the number of spies.'
36
+ end
37
+ end
38
+
39
+ def validate_input (response)
40
+ input_args = response.args.uniq
41
+ @characters = input_args[0].split(//)
42
+ all_users = input_args[1, input_args.length - 1] # User mention_names
43
+
44
+ if all_users.length < 5
45
+ raise 'You need at least 5 players for Resistance.'
46
+ elsif all_users.length > 10
47
+ raise 'You cannot play a game of Resistance with more than 10 players.'
48
+ end
49
+
50
+ @num_spies = (all_users.length + 2) / 3
51
+
52
+ verify_characters(@characters)
53
+
54
+ normalize_input!(all_users)
25
55
 
26
56
  # Ensure all people are users.
27
57
  unknown_users = []
@@ -31,40 +61,89 @@ module Lita
31
61
  end
32
62
 
33
63
  if unknown_users.any?
34
- response.reply('The following are not users. Please check your spelling and try again.')
35
- unknown_users.each do |user|
36
- response.reply(user)
37
- end and return
64
+ raise "The following are not users: @#{unknown_users.join(' @')}"
38
65
  end
39
66
 
40
- gameId = rand(999999)
67
+ all_users
68
+ end
41
69
 
42
- # Form teams
43
- spies = all_users.sample((all_users.length+2)/3)
44
- resistance = all_users - spies
70
+ def assign_spies (spies)
71
+ spy_specials = {}
72
+ if @characters.include?('D')
73
+ spy_specials[:deep_cover] = spies.sample
74
+ end
75
+
76
+ if @characters.include?('F')
77
+ spy_specials[:false_commander] = (spies - spy_specials.values).sample
78
+ end
79
+
80
+ if @characters.include?('B')
81
+ spy_specials[:blind_spy] = (spies - spy_specials.values).sample
82
+ end
83
+
84
+ if @characters.include?('A')
85
+ spy_specials[:assassin] = (spies - spy_specials.values).sample
86
+ end
45
87
 
46
88
  spies.each do |member|
47
89
  user = Lita::User.find_by_mention_name(member)
48
- current_user = Source.new(user: user)
49
- robot.send_message(current_user,"@#{response.user.mention_name} has started game ID ##{gameId} of Resistance. You are a member of the spies.")
50
- other_spies = spies.dup
51
- other_spies.delete_at(other_spies.find_index(member))
52
- if other_spies.length > 1
53
- robot.send_message(current_user, "The other spies are: @#{other_spies.join(' @')}")
54
- else
55
- robot.send_message(current_user, "The other spy is: @#{other_spies[0]}")
56
- end
90
+ other_spies = spies.dup - [spy_specials[:blind_spy], member] # Don't mention Blind Spy or self
91
+ robot.send_message(Source.new(user: user),
92
+ render_template('spy', { spy_specials: spy_specials,
93
+ other_spies: other_spies,
94
+ member: member,
95
+ starter: @starter,
96
+ game_id: @game_id }))
97
+ end
98
+ spy_specials
99
+ end
100
+
101
+ def assign_resistance (resistance, spies, spy_specials)
102
+ if @characters.include?('C')
103
+ commander = resistance.sample
104
+ commander_visible = spies - [spy_specials[:deep_cover]]
105
+ end
106
+
107
+ if @characters.include?('B')
108
+ bodyguard = (resistance - [commander]).sample
109
+ bodyguard_visible = [commander, spy_specials[:false_commander]].shuffle.compact
57
110
  end
58
111
 
59
112
  resistance.each do |member|
60
113
  user = Lita::User.find_by_mention_name(member)
61
- robot.send_message(Source.new(user: user), "@#{response.user.mention_name} has started game ID ##{gameId} of Resistance. You are a member of the resistance.")
114
+ robot.send_message(Source.new(user: user),
115
+ render_template("resistance", { commander: commander,
116
+ bodyguard: bodyguard,
117
+ bodyguard_visible: bodyguard_visible,
118
+ commander_visible: commander_visible,
119
+ member: member,
120
+ starter: @starter,
121
+ game_id: @game_id,
122
+ spy_specials: spy_specials }))
123
+
124
+ end
125
+ end
126
+
127
+ def play(response)
128
+ begin
129
+ all_users = validate_input(response)
130
+ rescue StandardError => error
131
+ response.reply(error.to_s) and return
62
132
  end
63
133
 
64
- leader = all_users.sample(1)[0] # Randomly pick a leader for the first round
65
- response.reply("Roles have been assigned to the selected people! This is game ID ##{gameId}. @#{leader} will be leading off the first round.")
134
+ @game_id = rand(999999)
135
+ @starter = response.user.mention_name # Person who started the game
136
+ # Form teams
137
+ spies = all_users.sample(@num_spies)
138
+ resistance = all_users - spies
139
+
140
+ spy_specials = assign_spies(spies)
141
+ assign_resistance(resistance, spies, spy_specials)
142
+
143
+ leader = all_users.sample # Randomly pick a leader for the first round
144
+ response.reply("Roles have been assigned to the selected people! This is game ID ##{@game_id}. @#{leader} will be leading off the first round.")
66
145
  end
67
-
146
+
68
147
  Lita.register_handler(self)
69
148
  end
70
149
  end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "lita-resistance"
3
- spec.version = "0.2.2"
3
+ spec.version = "1.0.0"
4
4
  spec.authors = ["Deon Hua", "Yu Chen Hou"]
5
5
  spec.email = ["deonhbci@gmail.com", "me@yuchen.io"]
6
6
  spec.description = "Plays a game of resistance by assigning roles to users you mention in chat."
@@ -1,4 +1,88 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Lita::Handlers::Resistance, lita_handler: true do
4
+ before(:each) do
5
+ a = Lita::User.create(1, {name: 'a', mention_name: 'a'})
6
+ b = Lita::User.create(2, {name: 'b', mention_name: 'b'})
7
+ c = Lita::User.create(3, {name: 'c', mention_name: 'c'})
8
+ d = Lita::User.create(4, {name: 'd', mention_name: 'd'})
9
+ e = Lita::User.create(5, {name: 'e', mention_name: 'e'})
10
+ end
11
+
12
+ describe "help" do
13
+ it "should provide help" do
14
+ send_command('resistance help')
15
+ expect(replies.last).to include('Commands:') # First line
16
+ end
17
+ end
18
+
19
+ describe "with no special characters" do
20
+ it 'should not start a game with more than 10 players' do
21
+ f = Lita::User.create(6, {name: 'f', mention_name: 'f'})
22
+ g = Lita::User.create(7, {name: 'g', mention_name: 'g'})
23
+ h = Lita::User.create(8, {name: 'h', mention_name: 'h'})
24
+ i = Lita::User.create(9, {name: 'i', mention_name: 'i'})
25
+ j = Lita::User.create(10, {name: 'j', mention_name: 'j'})
26
+ k = Lita::User.create(11, {name: 'k', mention_name: 'k'})
27
+
28
+ send_command('resistance N a b c d e f g h i j k')
29
+ expect(replies.last).to eq('You cannot play a game of Resistance with more than 10 players.')
30
+ end
31
+
32
+ it 'should not start a game with unknown users' do
33
+ send_command('resistance N a b c d @e f')
34
+ expect(replies.last).to eq('The following are not users: @f')
35
+ end
36
+
37
+ it 'should start a game with 5 players' do
38
+ send_command('resistance N a b c d @e')
39
+ expect(replies.last).to include('Roles have been assigned to the selected people!')
40
+ end
41
+
42
+ it 'should start a game with 7 players' do
43
+ f = Lita::User.create(6, {name: 'f', mention_name: 'f'})
44
+ g = Lita::User.create(7, {name: 'g', mention_name: 'g'})
45
+ send_command('resistance N a b c d e f g')
46
+ expect(replies.last).to include('Roles have been assigned to the selected people!')
47
+ end
48
+
49
+ it 'should not start a game with less than 5 players' do
50
+ send_command('resistance N a b c d')
51
+ expect(replies.last).to eq('You need at least 5 players for Resistance.')
52
+ end
53
+
54
+ it 'should not start a game with 2 Ns' do
55
+ send_command('resistance NN a b c d @e')
56
+ expect(replies.last).to eq('You cannot have more than one of the same character.')
57
+ end
58
+ end
59
+
60
+ describe "with special characters" do
61
+ it 'should not start a game with multiple of the same character' do
62
+ send_command('resistance CC a b c d @e')
63
+ expect(replies.last).to eq('You cannot have more than one of the same character.')
64
+ end
65
+
66
+ it 'should not start a game with a special character and N' do
67
+ send_command('resistance NC a b c d @e')
68
+ expect(replies.last).to eq('You cannot include special characters with N.')
69
+ end
70
+
71
+ it 'should not start a game with more special spies than spies' do
72
+ send_command('resistance ADF a b c d @e')
73
+ expect(replies.last).to eq('You cannot have more special characters on spies than the number of spies.')
74
+ end
75
+
76
+ it 'should start a game with 5 players' do
77
+ send_command('resistance BCDF a b c d @e')
78
+ expect(replies.last).to include('Roles have been assigned to the selected people!')
79
+ end
80
+
81
+ it 'should start a game with 7 players' do
82
+ f = Lita::User.create(6, {name: 'f', mention_name: 'f'})
83
+ g = Lita::User.create(7, {name: 'g', mention_name: 'g'})
84
+ send_command('resistance ABCFS a b c d e f g')
85
+ expect(replies.last).to include('Roles have been assigned to the selected people!')
86
+ end
87
+ end
4
88
  end
@@ -0,0 +1,26 @@
1
+ Commands:
2
+ `lita resistance help` - Provides detailed help
3
+
4
+ `lita resistance N [users]` - Assigns the roles of spy/resistance to users you mention, with no special characters.
5
+
6
+ `lita resistance [CBSAFD] [users]` - Assigns special characters to the users mentioned, the remainder (if any) will receive 'vanilla' spy/resistance roles.
7
+
8
+ Special Characters:
9
+ Note: The number of special characters chosen for each team must be less than the number of characters on that team.
10
+
11
+ The number of spies is always (Players + 2)/3 rounded down.
12
+
13
+ Resistance:
14
+ Commander (C) - Knows all spies except Deep Cover.
15
+
16
+ Body Guard (B) - Knows Commander and False Commander.
17
+
18
+ Spies:
19
+
20
+ Blind Spy (S) - Doesn't know the other spies. The other spies don't know Blind Spy.
21
+
22
+ Assassin (A) - If Resistance successfully completes 3 missions, Assassin can guess Commander. If Assassin is correct, Spies win.
23
+
24
+ False Commander (F) - Appears as Commander to Bodyguard.
25
+
26
+ Deep Cover (D) - Does not appear as spy to Commander. If played with Commander and without Assassin, can take Assassin's role.
@@ -0,0 +1,24 @@
1
+
2
+ <%= @starter %> has started game ID #<%= @game_id %> of Resistance.
3
+
4
+ <% if @member == @commander %>
5
+ You are the Commander, a member of the Resistance.
6
+
7
+ <% if @spy_specials[:deep_cover].nil? %>
8
+ The spies are: @<%= @commander_visible.join(' @') %>.
9
+ <% else %>
10
+ The spies, excluding Deep Cover, are: @<%= @commander_visible.join(' @') %>.
11
+ <% end %>
12
+ <% elsif @member == @bodyguard %>
13
+ You are the Bodyguard, a member of the Resistance.
14
+
15
+ <% if !@commander.nil? && !@spy_specials[:false_commander].nil? %>
16
+ The Commander and False Commander, in random order, are: @<%= @bodyguard_visible.join(' @')%>.
17
+ <% elsif !@commander.nil? && @spy_specials[:false_commander].nil? %>
18
+ The Commander is @<%= @bodyguard_visible[0] %>
19
+ <% elsif @commander.nil? && !@spy_specials[:false_commander].nil? %>
20
+ The False Commander is @<%= @bodyguard_visible[0] %>
21
+ <% end %>
22
+ <% else %>
23
+ You are a regular member of the Resistance.
24
+ <% end %>
@@ -0,0 +1,24 @@
1
+
2
+ <%= @starter %> has started game ID #<%= @game_id %> of Resistance.
3
+
4
+ <% if @member == @spy_specials[:blind_spy] %>
5
+ You are the Blind Spy, a member of the Spies. Unfortunately, you don't know the other spies, and they don't know you.
6
+ <% else %>
7
+ <% if @member == @spy_specials[:deep_cover] %>
8
+ You are the Deep Cover, a member of the Spies.
9
+ <% elsif @member == @spy_specials[:false_commander] %>
10
+ You are the False Commander, a member of the Spies.
11
+ <% elsif @member == @spy_specials[:assassin] %>
12
+ You are the Assassin, a member of the Spies.
13
+ <% else %>
14
+ You are a regular member of the Spies.
15
+ <% end %>
16
+
17
+ <% if @other_spies.length == 1 %>
18
+ The other spy is @<%= @other_spies[0] %>.
19
+ <% elsif @other_spies.length > 1 %>
20
+ The other spies are @<%= @other_spies.join(' @') %>.
21
+ <% else %>
22
+ The other spy is invisible to you.
23
+ <% end %>
24
+ <% end %>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lita-resistance
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Deon Hua
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-01-06 00:00:00.000000000 Z
12
+ date: 2016-01-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: lita
@@ -144,6 +144,9 @@ files:
144
144
  - spec/lita/handlers/resistance_spec.rb
145
145
  - spec/spec_helper.rb
146
146
  - templates/.gitkeep
147
+ - templates/help.erb
148
+ - templates/resistance.erb
149
+ - templates/spy.erb
147
150
  homepage: http://github.com/DeonHua/lita-resistance
148
151
  licenses:
149
152
  - MIT