qwtf_discord_bot 5.1.5 → 5.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d0adf9bb170277ec37dddc27d86049f6d678ddbb3b69530b114a177f11719d21
4
- data.tar.gz: ff6c28db3deb0fad59b2ca45d4d53b3c45c622848cc15d6234d14b245c865413
3
+ metadata.gz: 27e4374d157a5f3cad0f5c1cc58ffb1e9fc0b9f6ca9b89391509635260bc460a
4
+ data.tar.gz: 2775f0952e46afb2af7dbff0a72b388e34f343ed896b3d909ca0b9d069f76ab4
5
5
  SHA512:
6
- metadata.gz: 5dfb62990d27a5f250ea4ddbbe5f62583618e947c2c26d8df85308e2b99bb204a35a2b25347080a2352d4d1a7508e45e690fd7a636cd7e7baf1fc2305d8c9a60
7
- data.tar.gz: 52590b32e2c4727c7ccd9b526bdc9f8abccb46b8d4e815d78cd7eb3cfd7dea669e57890b171dfdeb41c5a9de092d38147ae0b3469a97bb1450f96e713fe9b27a
6
+ metadata.gz: 6cf2acfe24299674b69051e0d28ce628cea334840910b5bbd083d73e10d91cdf2d7c96312371ffed448424b769abb86c77a63de05b4a23136d05e92398bf2ff1
7
+ data.tar.gz: 1a5830ef4f29e3c331d5534a84837e8d3e29bccf016e478e439aa8727836fe957d20f4865265264aa69116110f9e7ba7cf322869f6738aff5ef365f4d860137d
data/Gemfile CHANGED
@@ -12,6 +12,6 @@ group :development do
12
12
  end
13
13
 
14
14
  group :test do
15
- gem 'rspec'
16
15
  gem 'factory_bot'
16
+ gem 'rspec'
17
17
  end
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- qwtf_discord_bot (5.0.4)
4
+ qwtf_discord_bot (5.1.12)
5
5
  discordrb (~> 3.3)
6
6
  redis (~> 4.1)
7
7
  thor (~> 0.20)
data/README.md CHANGED
@@ -89,8 +89,12 @@ This responds to discord messages:
89
89
  - `!join`
90
90
  - `!leave`
91
91
  - `!status`
92
- - `!maxplayers <no_of_players>`
93
- - `!notify <roles>`
92
+ - `!kick <@player>`
93
+ - `!teamsize <no_of_players>`
94
+ - `!team <team_no>`
95
+ - `!unteam`
96
+ - `!win <team_no>`
97
+ - `!notify <@role @role2>`
94
98
  - `!end`
95
99
 
96
100
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 5.1.5
1
+ 5.2.5
data/bin/bundle CHANGED
@@ -8,46 +8,46 @@
8
8
  # this file is here to facilitate running it.
9
9
  #
10
10
 
11
- require "rubygems"
11
+ require 'rubygems'
12
12
 
13
13
  m = Module.new do
14
- module_function
14
+ module_function
15
15
 
16
16
  def invoked_as_script?
17
17
  File.expand_path($0) == File.expand_path(__FILE__)
18
18
  end
19
19
 
20
20
  def env_var_version
21
- ENV["BUNDLER_VERSION"]
21
+ ENV['BUNDLER_VERSION']
22
22
  end
23
23
 
24
24
  def cli_arg_version
25
25
  return unless invoked_as_script? # don't want to hijack other binstubs
26
- return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update`
26
+ return unless 'update'.start_with?(ARGV.first || ' ') # must be running `bundle update`
27
+
27
28
  bundler_version = nil
28
29
  update_index = nil
29
30
  ARGV.each_with_index do |a, i|
30
- if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN
31
- bundler_version = a
32
- end
31
+ bundler_version = a if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN
33
32
  next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/
34
- bundler_version = $1 || ">= 0.a"
33
+
34
+ bundler_version = Regexp.last_match(1) || '>= 0.a'
35
35
  update_index = i
36
36
  end
37
37
  bundler_version
38
38
  end
39
39
 
40
40
  def gemfile
41
- gemfile = ENV["BUNDLE_GEMFILE"]
41
+ gemfile = ENV['BUNDLE_GEMFILE']
42
42
  return gemfile if gemfile && !gemfile.empty?
43
43
 
44
- File.expand_path("../../Gemfile", __FILE__)
44
+ File.expand_path('../Gemfile', __dir__)
45
45
  end
46
46
 
47
47
  def lockfile
48
48
  lockfile =
49
49
  case File.basename(gemfile)
50
- when "gems.rb" then gemfile.sub(/\.rb$/, gemfile)
50
+ when 'gems.rb' then gemfile.sub(/\.rb$/, gemfile)
51
51
  else "#{gemfile}.lock"
52
52
  end
53
53
  File.expand_path(lockfile)
@@ -55,8 +55,10 @@ m = Module.new do
55
55
 
56
56
  def lockfile_version
57
57
  return unless File.file?(lockfile)
58
+
58
59
  lockfile_contents = File.read(lockfile)
59
60
  return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/
61
+
60
62
  Regexp.last_match(1)
61
63
  end
62
64
 
@@ -68,24 +70,28 @@ m = Module.new do
68
70
  end
69
71
 
70
72
  def load_bundler!
71
- ENV["BUNDLE_GEMFILE"] ||= gemfile
73
+ ENV['BUNDLE_GEMFILE'] ||= gemfile
72
74
 
73
75
  # must dup string for RG < 1.8 compatibility
74
76
  activate_bundler(bundler_version.dup)
75
77
  end
76
78
 
77
79
  def activate_bundler(bundler_version)
78
- if Gem::Version.correct?(bundler_version) && Gem::Version.new(bundler_version).release < Gem::Version.new("2.0")
79
- bundler_version = "< 2"
80
+ if Gem::Version.correct?(bundler_version) && Gem::Version.new(bundler_version).release < Gem::Version.new('2.0')
81
+ bundler_version = '< 2'
80
82
  end
81
83
  gem_error = activation_error_handling do
82
- gem "bundler", bundler_version
84
+ gem 'bundler', bundler_version
83
85
  end
84
86
  return if gem_error.nil?
87
+
85
88
  require_error = activation_error_handling do
86
- require "bundler/version"
89
+ require 'bundler/version'
90
+ end
91
+ if require_error.nil? && Gem::Requirement.new(bundler_version).satisfied_by?(Gem::Version.new(Bundler::VERSION))
92
+ return
87
93
  end
88
- return if require_error.nil? && Gem::Requirement.new(bundler_version).satisfied_by?(Gem::Version.new(Bundler::VERSION))
94
+
89
95
  warn "Activating bundler (#{bundler_version}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_version}'`"
90
96
  exit 42
91
97
  end
@@ -100,6 +106,4 @@ end
100
106
 
101
107
  m.load_bundler!
102
108
 
103
- if m.invoked_as_script?
104
- load Gem.bin_path("bundler", "bundle")
105
- end
109
+ load Gem.bin_path('bundler', 'bundle') if m.invoked_as_script?
@@ -8,11 +8,11 @@
8
8
  # this file is here to facilitate running it.
9
9
  #
10
10
 
11
- require "pathname"
12
- ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
- Pathname.new(__FILE__).realpath)
11
+ require 'pathname'
12
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
13
+ Pathname.new(__FILE__).realpath)
14
14
 
15
- bundle_binstub = File.expand_path("../bundle", __FILE__)
15
+ bundle_binstub = File.expand_path('bundle', __dir__)
16
16
 
17
17
  if File.file?(bundle_binstub)
18
18
  if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
@@ -23,7 +23,7 @@ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this
23
23
  end
24
24
  end
25
25
 
26
- require "rubygems"
27
- require "bundler/setup"
26
+ require 'rubygems'
27
+ require 'bundler/setup'
28
28
 
29
- load Gem.bin_path("coderay", "coderay")
29
+ load Gem.bin_path('coderay', 'coderay')
File without changes
@@ -8,11 +8,11 @@
8
8
  # this file is here to facilitate running it.
9
9
  #
10
10
 
11
- require "pathname"
12
- ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
- Pathname.new(__FILE__).realpath)
11
+ require 'pathname'
12
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
13
+ Pathname.new(__FILE__).realpath)
14
14
 
15
- bundle_binstub = File.expand_path("../bundle", __FILE__)
15
+ bundle_binstub = File.expand_path('bundle', __dir__)
16
16
 
17
17
  if File.file?(bundle_binstub)
18
18
  if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
@@ -23,7 +23,7 @@ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this
23
23
  end
24
24
  end
25
25
 
26
- require "rubygems"
27
- require "bundler/setup"
26
+ require 'rubygems'
27
+ require 'bundler/setup'
28
28
 
29
- load Gem.bin_path("diff-lcs", "htmldiff")
29
+ load Gem.bin_path('diff-lcs', 'htmldiff')
data/bin/ldiff CHANGED
@@ -8,11 +8,11 @@
8
8
  # this file is here to facilitate running it.
9
9
  #
10
10
 
11
- require "pathname"
12
- ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
- Pathname.new(__FILE__).realpath)
11
+ require 'pathname'
12
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
13
+ Pathname.new(__FILE__).realpath)
14
14
 
15
- bundle_binstub = File.expand_path("../bundle", __FILE__)
15
+ bundle_binstub = File.expand_path('bundle', __dir__)
16
16
 
17
17
  if File.file?(bundle_binstub)
18
18
  if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
@@ -23,7 +23,7 @@ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this
23
23
  end
24
24
  end
25
25
 
26
- require "rubygems"
27
- require "bundler/setup"
26
+ require 'rubygems'
27
+ require 'bundler/setup'
28
28
 
29
- load Gem.bin_path("diff-lcs", "ldiff")
29
+ load Gem.bin_path('diff-lcs', 'ldiff')
data/bin/pry CHANGED
@@ -8,11 +8,11 @@
8
8
  # this file is here to facilitate running it.
9
9
  #
10
10
 
11
- require "pathname"
12
- ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
- Pathname.new(__FILE__).realpath)
11
+ require 'pathname'
12
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
13
+ Pathname.new(__FILE__).realpath)
14
14
 
15
- bundle_binstub = File.expand_path("../bundle", __FILE__)
15
+ bundle_binstub = File.expand_path('bundle', __dir__)
16
16
 
17
17
  if File.file?(bundle_binstub)
18
18
  if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
@@ -23,7 +23,7 @@ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this
23
23
  end
24
24
  end
25
25
 
26
- require "rubygems"
27
- require "bundler/setup"
26
+ require 'rubygems'
27
+ require 'bundler/setup'
28
28
 
29
- load Gem.bin_path("pry", "pry")
29
+ load Gem.bin_path('pry', 'pry')
@@ -8,11 +8,11 @@
8
8
  # this file is here to facilitate running it.
9
9
  #
10
10
 
11
- require "pathname"
12
- ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
- Pathname.new(__FILE__).realpath)
11
+ require 'pathname'
12
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
13
+ Pathname.new(__FILE__).realpath)
14
14
 
15
- bundle_binstub = File.expand_path("../bundle", __FILE__)
15
+ bundle_binstub = File.expand_path('bundle', __dir__)
16
16
 
17
17
  if File.file?(bundle_binstub)
18
18
  if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
@@ -23,7 +23,7 @@ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this
23
23
  end
24
24
  end
25
25
 
26
- require "rubygems"
27
- require "bundler/setup"
26
+ require 'rubygems'
27
+ require 'bundler/setup'
28
28
 
29
- load Gem.bin_path("qwtf_discord_bot", "qwtf_discord_bot")
29
+ load Gem.bin_path('qwtf_discord_bot', 'qwtf_discord_bot')
@@ -8,11 +8,11 @@
8
8
  # this file is here to facilitate running it.
9
9
  #
10
10
 
11
- require "pathname"
12
- ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
- Pathname.new(__FILE__).realpath)
11
+ require 'pathname'
12
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
13
+ Pathname.new(__FILE__).realpath)
14
14
 
15
- bundle_binstub = File.expand_path("../bundle", __FILE__)
15
+ bundle_binstub = File.expand_path('bundle', __dir__)
16
16
 
17
17
  if File.file?(bundle_binstub)
18
18
  if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
@@ -23,7 +23,7 @@ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this
23
23
  end
24
24
  end
25
25
 
26
- require "rubygems"
27
- require "bundler/setup"
26
+ require 'rubygems'
27
+ require 'bundler/setup'
28
28
 
29
- load Gem.bin_path("rest-client", "restclient")
29
+ load Gem.bin_path('rest-client', 'restclient')
data/bin/rspec CHANGED
@@ -8,11 +8,11 @@
8
8
  # this file is here to facilitate running it.
9
9
  #
10
10
 
11
- require "pathname"
12
- ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
- Pathname.new(__FILE__).realpath)
11
+ require 'pathname'
12
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
13
+ Pathname.new(__FILE__).realpath)
14
14
 
15
- bundle_binstub = File.expand_path("../bundle", __FILE__)
15
+ bundle_binstub = File.expand_path('bundle', __dir__)
16
16
 
17
17
  if File.file?(bundle_binstub)
18
18
  if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
@@ -23,7 +23,7 @@ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this
23
23
  end
24
24
  end
25
25
 
26
- require "rubygems"
27
- require "bundler/setup"
26
+ require 'rubygems'
27
+ require 'bundler/setup'
28
28
 
29
- load Gem.bin_path("rspec-core", "rspec")
29
+ load Gem.bin_path('rspec-core', 'rspec')
data/bin/thor CHANGED
@@ -8,11 +8,11 @@
8
8
  # this file is here to facilitate running it.
9
9
  #
10
10
 
11
- require "pathname"
12
- ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
- Pathname.new(__FILE__).realpath)
11
+ require 'pathname'
12
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
13
+ Pathname.new(__FILE__).realpath)
14
14
 
15
- bundle_binstub = File.expand_path("../bundle", __FILE__)
15
+ bundle_binstub = File.expand_path('bundle', __dir__)
16
16
 
17
17
  if File.file?(bundle_binstub)
18
18
  if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
@@ -23,7 +23,7 @@ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this
23
23
  end
24
24
  end
25
25
 
26
- require "rubygems"
27
- require "bundler/setup"
26
+ require 'rubygems'
27
+ require 'bundler/setup'
28
28
 
29
- load Gem.bin_path("thor", "thor")
29
+ load Gem.bin_path('thor', 'thor')
@@ -12,7 +12,7 @@ class Endpoint
12
12
 
13
13
  @config.values.each do |settings|
14
14
  settings.each do |setting|
15
- setting["channel_ids"].each do |channel_id|
15
+ setting['channel_ids'].each do |channel_id|
16
16
  channel_ids << channel_id
17
17
  end
18
18
  end
@@ -23,10 +23,18 @@ class EventDecorator
23
23
  server.users
24
24
  end
25
25
 
26
+ def mention_for(user_id)
27
+ find_user(user_id)&.mention
28
+ end
29
+
26
30
  def mentions_for(user_ids)
27
31
  find_users(user_ids).map(&:mention)
28
32
  end
29
33
 
34
+ def display_name_for(user_id)
35
+ find_user(user_id)&.display_name
36
+ end
37
+
30
38
  def display_names_for(user_ids)
31
39
  find_users(user_ids).map(&:display_name)
32
40
  end
@@ -51,4 +59,3 @@ class EventDecorator
51
59
  @event.user
52
60
  end
53
61
  end
54
-
@@ -28,7 +28,8 @@ class Player
28
28
  end
29
29
 
30
30
  def team
31
- return 'spec' if !valid_score? || @data['team'].empty? || @data['team'] == "observe"
31
+ return 'spec' if !valid_score? || @data['team'].empty? || @data['team'] == 'observe'
32
+
32
33
  @data['team']
33
34
  end
34
35
 
data/lib/pug.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  class Pug
2
- DEFAULT_MAXPLAYERS = 8
2
+ DEFAULT_TEAMSIZE = 4
3
+ MIN_NO_OF_TEAMS = 2
3
4
 
4
5
  def self.for(channel_id)
5
6
  new(channel_id)
@@ -9,13 +10,29 @@ class Pug
9
10
  @channel_id = channel_id
10
11
  end
11
12
 
12
- def join(user_id)
13
+ def join(player_id)
13
14
  redis.setnx(pug_key, Time.now)
14
- redis.sadd(players_key, user_id)
15
+
16
+ redis.sadd(team_key(0), player_id)
17
+ end
18
+
19
+ def join_team(team_no:, player_id:)
20
+ leave_teams(player_id)
21
+ redis.sadd(team_key(team_no), player_id)
15
22
  end
16
23
 
17
24
  def joined_players
18
- redis.smembers(players_key).map(&:to_i)
25
+ teams_keys.inject([]) do |players, team|
26
+ players + redis.smembers(team).map(&:to_i)
27
+ end
28
+ end
29
+
30
+ def team(number)
31
+ redis.smembers(team_key(number)).map(&:to_i)
32
+ end
33
+
34
+ def teamsize=(teamsize)
35
+ redis.set(teamsize_key, teamsize)
19
36
  end
20
37
 
21
38
  def full?
@@ -23,7 +40,11 @@ class Pug
23
40
  end
24
41
 
25
42
  def joined_player_count
26
- redis.scard(players_key).to_i
43
+ joined_players.count
44
+ end
45
+
46
+ def team_player_count(team_no)
47
+ redis.scard(team_key(team_no)).to_i
27
48
  end
28
49
 
29
50
  def player_slots
@@ -39,15 +60,11 @@ class Pug
39
60
  end
40
61
 
41
62
  def notify_roles
42
- redis.get(notify_roles_key) || "@here"
63
+ redis.get(notify_roles_key) || '@here'
43
64
  end
44
65
 
45
- def maxplayers=(maxplayers)
46
- redis.set(maxplayers_key, maxplayers)
47
- end
48
-
49
- def maxplayers
50
- (redis.get(maxplayers_key) || DEFAULT_MAXPLAYERS).to_i
66
+ def teamsize
67
+ (redis.get(teamsize_key) || DEFAULT_TEAMSIZE).to_i
51
68
  end
52
69
 
53
70
  def active?
@@ -55,37 +72,79 @@ class Pug
55
72
  end
56
73
 
57
74
  def leave(player_id)
58
- redis.srem(players_key, player_id)
75
+ leave_teams(player_id)
76
+ end_pug if empty?
59
77
  end
60
78
 
61
- def empty?
62
- joined_player_count == 0
79
+ def end_pug
80
+ redis.keys([pug_key, "*"].join).each do |key|
81
+ redis.del(key)
82
+ end
63
83
  end
64
84
 
65
- def end_pug
66
- redis.del(pug_key)
67
- redis.del(players_key)
85
+ def joined?(player_id)
86
+ joined_players.include?(player_id)
87
+ end
88
+
89
+ def maxplayers
90
+ teamsize * no_of_teams
91
+ end
92
+
93
+ def won_by(team_no)
94
+ { teams: teams, winner: team_no }
95
+ end
96
+
97
+ def teams
98
+ teams_keys.inject({}) do |teams, team|
99
+ teams.merge({ team.split(':').last => redis.smembers(team).map(&:to_i) })
100
+ end
101
+ end
102
+
103
+ def actual_teams
104
+ teams.tap { |team| team.delete("0") }
68
105
  end
69
106
 
70
107
  private
71
108
 
72
- def maxplayers_key
73
- [pug_key, "maxplayers"].join(":")
109
+ def leave_teams(player_id)
110
+ teams_keys.each do |team|
111
+ redis.srem(team, player_id)
112
+ end
113
+ end
114
+
115
+ def teams_keys
116
+ redis.keys([pug_key, 'teams:*'].join(':'))
74
117
  end
75
118
 
76
- def players_key
77
- [pug_key, "players"].join(":")
119
+ def empty?
120
+ joined_player_count.zero?
121
+ end
122
+
123
+ def team_key(team_no)
124
+ [pug_key, 'teams', team_no].join(':')
78
125
  end
79
126
 
80
127
  def pug_key
81
- ["pug", "channel", @channel_id].join(":")
128
+ [channel_key, 'pug'].join(':')
129
+ end
130
+
131
+ def channel_key
132
+ ['channel', @channel_id].join(':')
82
133
  end
83
134
 
84
135
  def notify_roles_key
85
- [pug_key, "role"].join(":")
136
+ [channel_key, 'role'].join(':')
137
+ end
138
+
139
+ def teamsize_key
140
+ [pug_key, 'teamsize'].join(':')
86
141
  end
87
142
 
88
143
  def redis
89
144
  Redis.current
90
145
  end
146
+
147
+ def no_of_teams
148
+ [actual_teams.count, MIN_NO_OF_TEAMS].max
149
+ end
91
150
  end