qwtf_discord_bot 5.1.8 → 5.1.9

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
  SHA256:
3
- metadata.gz: cfcb9cea490b3e0de6db8028dbe88bdc5989186b97225f92f9a87cf0e0eeb05a
4
- data.tar.gz: 814fc6269bec9872b68fed72b96a78322735534cb8969f7e1d74618aa9fef5cc
3
+ metadata.gz: 874aab5dba875e61f9dfd5500d91a25149a7b08a8a91854402080d4775cc1b24
4
+ data.tar.gz: e68aa880053d9bffbfb563fa6bcdaa060b89d91051e6955615f89543a30e1530
5
5
  SHA512:
6
- metadata.gz: d853f68c400f0ec91e7da0185c77a98e96958168c6057143d646d0f007c3496b9cab2a8f20936c6d4d504a82e9bdd76234949358a5bf5c58b07d79dd7eab7fe6
7
- data.tar.gz: 334b46c0db3144f305c19f0d24923c4a487460fdac0413ded541aafb80edde9fcbb8835499fc29f7723e5730771c411951383a764e6bb78418a236ccf09448c9
6
+ metadata.gz: aae1ed1e4fa7e631a4903fb7fdfb933b51bf127ee3de0d3b8497f39d3d6d36c16dcd23db18664a724375bb454ac60bca7467ce0f34bfbcfe7c55b278ece01660
7
+ data.tar.gz: 7426320e57d72affc5170ed20a7cd4a0d0ff1711c2103cfe88c85d8c646e5900725860d4c8644653cc53ce610a8f0b18cd88e1db8550d96c80df05e271532f72
data/README.md CHANGED
@@ -90,7 +90,7 @@ This responds to discord messages:
90
90
  - `!leave`
91
91
  - `!status`
92
92
  - `!kick <@player>`
93
- - `!maxplayers <no_of_players>`
93
+ - `!teamsize <no_of_players>`
94
94
  - `!notify <@role @role2>`
95
95
  - `!end`
96
96
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 5.1.8
1
+ 5.1.9
@@ -24,7 +24,9 @@ class EventDecorator
24
24
  end
25
25
 
26
26
  def mentions_for(user_ids)
27
- find_users(user_ids).map(&:mention)
27
+ find_users(user_ids).map do |user|
28
+ user&.mention
29
+ end
28
30
  end
29
31
 
30
32
  def display_names_for(user_ids)
data/lib/pug.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  class Pug
2
- DEFAULT_MAXPLAYERS = 8
2
+ DEFAULT_teamsize = 4
3
+ NO_OF_TEAMS = 2
3
4
 
4
5
  def self.for(channel_id)
5
6
  new(channel_id)
@@ -18,6 +19,15 @@ class Pug
18
19
  redis.smembers(players_key).map(&:to_i)
19
20
  end
20
21
 
22
+ def team(no)
23
+ index = no - 1
24
+ joined_players.each_slice(teamsize).to_a[index]
25
+ end
26
+
27
+ def teamsize=(teamsize)
28
+ redis.set(teamsize_key, teamsize)
29
+ end
30
+
21
31
  def full?
22
32
  joined_player_count >= maxplayers
23
33
  end
@@ -42,12 +52,12 @@ class Pug
42
52
  redis.get(notify_roles_key) || "@here"
43
53
  end
44
54
 
45
- def maxplayers=(maxplayers)
46
- redis.set(maxplayers_key, maxplayers)
55
+ def teamsize=(teamsize)
56
+ redis.set(teamsize_key, teamsize)
47
57
  end
48
58
 
49
- def maxplayers
50
- (redis.get(maxplayers_key) || DEFAULT_MAXPLAYERS).to_i
59
+ def teamsize
60
+ (redis.get(teamsize_key) || DEFAULT_teamsize).to_i
51
61
  end
52
62
 
53
63
  def active?
@@ -68,14 +78,18 @@ class Pug
68
78
  joined_players.include?(player_id)
69
79
  end
70
80
 
81
+ def maxplayers
82
+ teamsize * NO_OF_TEAMS
83
+ end
84
+
71
85
  private
72
86
 
73
87
  def empty?
74
88
  joined_player_count.zero?
75
89
  end
76
90
 
77
- def maxplayers_key
78
- [pug_key, "maxplayers"].join(":")
91
+ def teamsize_key
92
+ [pug_key, "teamsize"].join(":")
79
93
  end
80
94
 
81
95
  def players_key
@@ -90,6 +104,10 @@ class Pug
90
104
  [pug_key, "role"].join(":")
91
105
  end
92
106
 
107
+ def teamsize_key
108
+ [pug_key, "teamsize"].join(":")
109
+ end
110
+
93
111
  def redis
94
112
  Redis.current
95
113
  end
@@ -42,14 +42,7 @@ class QwtfDiscordBotPug # :nodoc:
42
42
 
43
43
  message(message, e.channel)
44
44
 
45
- if pug.full?
46
- message = start_pug_message(
47
- player_slots: pug.player_slots,
48
- mentions: e.mentions_for(pug.joined_players)
49
- )
50
-
51
- message(message, e.channel)
52
- end
45
+ start_pug(pug, e) if pug.full?
53
46
  end
54
47
  end
55
48
 
@@ -68,26 +61,22 @@ class QwtfDiscordBotPug # :nodoc:
68
61
  end
69
62
  end
70
63
 
71
- bot.command :maxplayers do |event, *args|
64
+ bot.command :teamsize do |event, *args|
72
65
  setup_pug(event) do |e, pug|
73
- new_maxplayers = args[0]
66
+ new_teamsize = args[0]
74
67
 
75
- message = if new_maxplayers
76
- pug.maxplayers = new_maxplayers
77
- "Max number of players set to #{pug.maxplayers} | #{pug.player_slots} joined"
78
- else
79
- "Current max number of players is #{pug.maxplayers} | #{pug.player_slots} joined"
80
- end
81
-
82
- message(message, e.channel)
83
-
84
- if pug.full?
85
- message = start_pug_message(
86
- player_slots: pug.player_slots,
87
- mentions: e.mentions_for(pug.joined_players)
68
+ if new_teamsize
69
+ pug.teamsize = new_teamsize
70
+ message(
71
+ "Team size set to #{pug.teamsize} | #{pug.player_slots} joined",
72
+ e.channel
73
+ )
74
+ start_pug(pug, e) if pug.full?
75
+ else
76
+ message(
77
+ "Current team size is #{pug.teamsize} | #{pug.player_slots} joined",
78
+ e.channel
88
79
  )
89
-
90
- message(message, e.channel)
91
80
  end
92
81
  end
93
82
  end
@@ -174,6 +163,17 @@ class QwtfDiscordBotPug # :nodoc:
174
163
  nil # stop discordrb printing return value
175
164
  end
176
165
 
166
+ def start_pug(pug, event)
167
+ message(
168
+ [
169
+ 'Time to play!',
170
+ ['Team 1:', event.mentions_for(pug.team(1)).join(' ')].join(' '),
171
+ ['Team 2:', event.mentions_for(pug.team(2)).join(' ')].join(' ')
172
+ ].join("\n"),
173
+ event.channel
174
+ )
175
+ end
176
+
177
177
  def start_pug_message(player_slots:, mentions:)
178
178
  ['Time to play!', player_slots, mentions.join(' ')].join(' | ')
179
179
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qwtf_discord_bot
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.1.8
4
+ version: 5.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sheldon Johnson
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-08-28 00:00:00.000000000 Z
11
+ date: 2020-08-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: discordrb