qwtf_discord_bot 5.5.22 → 6.0.1

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: 8935dcbd9f811d2277081ce9d92ae0ae7818663212f5858a897e47d799d6765c
4
- data.tar.gz: bc16097b879c0ab8ed026e1a42ce0ca981b333280ce96a62f320ac4f80250f1a
3
+ metadata.gz: 7873dfbc7828ca1970851e98c563be1adfc62cb0f451a4a3f76d5dbc551db8a4
4
+ data.tar.gz: b34b2f5138fff279ff9ed28f2034058cef15ba3cd95c4c4157d1588dd0664dc3
5
5
  SHA512:
6
- metadata.gz: a04f4e900ed5011cd7abfab2a13f9c501600e0a6c6a4e6ee6623f6e32cd2c5aaba7452e01609b1dc3ac9441f22af0ace8035d47ca0bf2b7f0d3eb5f5711034e8
7
- data.tar.gz: a932142714804658be6725f0f6f2e5f3236e740204e3c58cfd8bf971ee27cd95bd8d6342cacade9a3c42ef59490a852f20588c73ecd82e78fd41d073321b9a25
6
+ metadata.gz: 6bc88b6b480c2a53a8f79a17a1c7202d446d8a068aa1daf0bc9a685ca63c09705450466572ba3fb95a7b7e84360e7e29db41415a74f3e277ea08ae1e61c18b89
7
+ data.tar.gz: a75c8be77b08ffd148e79c374451e65d31f7b5131e6254f0fa2da434885db24a7ebb1df6e84509c3715a1f46cde7a53dae8d4a326fc367c996c791c81a3926ce
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- qwtf_discord_bot (5.5.21)
4
+ qwtf_discord_bot (6.0.0)
5
5
  discordrb (= 3.4.0)
6
6
  redis (~> 4.2)
7
7
  thor (~> 1.1)
data/README.md CHANGED
@@ -180,8 +180,8 @@ Build:
180
180
 
181
181
  Push:
182
182
 
183
- docker tag discord-bot fortressone/discord-bot:latest
184
- docker push fortressone/discord-bot:latest
183
+ docker tag discord-bot fortressone/discord-bot:latest \
184
+ && docker push fortressone/discord-bot:latest
185
185
 
186
186
 
187
187
  Create AWS instance:
data/VERSION CHANGED
@@ -1 +1 @@
1
- 5.5.22
1
+ 6.0.1
data/docker-compose.yml CHANGED
@@ -35,6 +35,7 @@ services:
35
35
  environment:
36
36
  - REDIS_URL=redis://redis
37
37
  - RATINGS_API_URL
38
+ - RATINGS_APP_URL
38
39
  volumes:
39
40
  - type: bind
40
41
  source: "/home/ubuntu/.config/qwtf_discord_bot/config.yaml"
data/lib/dashboard.rb CHANGED
@@ -2,6 +2,8 @@ class Dashboard
2
2
  def initialize(dashboard_config, bot)
3
3
  @server = bot.server(dashboard_config["server_id"])
4
4
  @endpoints = dashboard_config["endpoints"]
5
+ @messages = {}
6
+
5
7
 
6
8
  channel_name = dashboard_config["name"]
7
9
 
@@ -32,15 +34,13 @@ class Dashboard
32
34
  end
33
35
 
34
36
  def update
35
- messages = {}
36
-
37
37
  @endpoints.each do |endpoint|
38
38
  qstat_request = QstatRequest.new(endpoint)
39
39
 
40
40
  if qstat_request.is_empty?
41
- if messages[endpoint]
42
- messages[endpoint].delete
43
- messages.delete(endpoint)
41
+ if @messages[endpoint]
42
+ @messages[endpoint].delete
43
+ @messages.delete(endpoint)
44
44
  end
45
45
 
46
46
  next
@@ -48,8 +48,8 @@ class Dashboard
48
48
 
49
49
  embed = qstat_request.to_full_embed
50
50
 
51
- messages[endpoint] = if messages[endpoint]
52
- messages[endpoint].edit(nil, embed)
51
+ @messages[endpoint] = if @messages[endpoint]
52
+ @messages[endpoint].edit(nil, embed)
53
53
  else
54
54
  @channel.send_embed(nil, embed)
55
55
  end
data/lib/qstat_request.rb CHANGED
@@ -17,7 +17,7 @@ class QstatRequest
17
17
  embed = Discordrb::Webhooks::Embed.new
18
18
 
19
19
  teams.each do |team|
20
- embed.add_field << team.to_embed_field
20
+ embed << team.to_embed_field
21
21
  end
22
22
 
23
23
  embed
@@ -45,39 +45,39 @@ class QstatRequest
45
45
  def server_summary
46
46
  return "#{@endpoint} isn't responding" unless game_map
47
47
 
48
- if !has_spectators?
49
- return [
50
- name,
51
- @endpoint,
52
- game_map,
53
- "#{numplayers}/#{maxplayers}"
54
- ].join(MSG_SNIPPET_DELIMITER)
55
- end
48
+ info = [name, @endpoint, game_map]
49
+
50
+ info += if !has_spectators?
51
+ ["#{numplayers}/#{maxplayers}"]
52
+ else
53
+ [
54
+ "#{numplayers}/#{maxplayers} players",
55
+ "#{numspectators}/#{maxspectators} spectators"
56
+ ]
57
+ end
58
+
59
+ info.join(MSG_SNIPPET_DELIMITER)
60
+ end
56
61
 
57
- [
58
- name,
59
- @endpoint,
60
- game_map,
61
- "#{numplayers}/#{maxplayers} players",
62
- "#{numspectators}/#{maxspectators} spectators"
63
- ].join(MSG_SNIPPET_DELIMITER)
62
+ def join_link
63
+ "[Join](http://phobos.baseq.fr:9999/join?url=#{@endpoint})"
64
64
  end
65
65
 
66
66
  def embed_summary
67
- if !has_spectators?
68
- return [
69
- @endpoint,
70
- game_map,
71
- "#{numplayers}/#{maxplayers}"
72
- ].join(MSG_SNIPPET_DELIMITER)
73
- end
67
+ info = [@endpoint, game_map]
68
+
69
+ info += if !has_spectators?
70
+ ["#{numplayers}/#{maxplayers}"]
71
+ else
72
+ [
73
+ "#{numplayers}/#{maxplayers} players",
74
+ "#{numspectators}/#{maxspectators} spectators"
75
+ ]
76
+ end
74
77
 
75
- [
76
- @endpoint,
77
- game_map,
78
- "#{numplayers}/#{maxplayers} players",
79
- "#{numspectators}/#{maxspectators} spectators"
80
- ].join(MSG_SNIPPET_DELIMITER)
78
+ info << join_link
79
+
80
+ info.join(MSG_SNIPPET_DELIMITER)
81
81
  end
82
82
 
83
83
  def is_empty?
@@ -115,7 +115,10 @@ class QstatRequest
115
115
  end
116
116
 
117
117
  def name
118
- data['name']
118
+ name = data['name']
119
+ return address if name.empty?
120
+
121
+ name
119
122
  end
120
123
 
121
124
  def address
@@ -430,7 +430,7 @@ class QwtfDiscordBotPug # :nodoc:
430
430
  ).body
431
431
 
432
432
  send_embedded_message(
433
- description: "#{TEAM_NAMES[winning_team_no]} wins game ##{id}. `!choose` again. [Ratings](http://ratings.fortressone.org)",
433
+ description: "#{TEAM_NAMES[winning_team_no]} wins game ##{id}. `!choose` again. [Ratings](#{discord_channel_leaderboard_url(e.channel.id)})",
434
434
  channel: e.channel
435
435
  )
436
436
  end
@@ -498,7 +498,7 @@ class QwtfDiscordBotPug # :nodoc:
498
498
  ).body
499
499
 
500
500
  send_embedded_message(
501
- description: "Match ##{id} drawn. `!choose` again. [Ratings](http://ratings.fortressone.org)",
501
+ description: "Match ##{id} drawn. `!choose` again. [Ratings](#{discord_channel_leaderboard_url(e.channel.id)})",
502
502
  channel: e.channel
503
503
  )
504
504
  end
@@ -694,7 +694,10 @@ class QwtfDiscordBotPug # :nodoc:
694
694
  channel: event.channel
695
695
  )
696
696
 
697
- combinations = get_fair_teams(pug.joined_players)
697
+ combinations = get_fair_teams(
698
+ channel_id: event.channel.id, players: pug.joined_players
699
+ )
700
+
698
701
  teams = combinations[iteration]
699
702
 
700
703
  if !teams
@@ -814,7 +817,7 @@ class QwtfDiscordBotPug # :nodoc:
814
817
  end
815
818
 
816
819
  def post_results(json)
817
- uri = URI("#{ENV['RATINGS_API_URL']}matches/")
820
+ uri = URI([ENV['RATINGS_API_URL'], 'matches'].join('/'))
818
821
  req = Net::HTTP::Post.new(uri, 'Content-Type' => 'application/json')
819
822
  req.body = json
820
823
 
@@ -823,9 +826,9 @@ class QwtfDiscordBotPug # :nodoc:
823
826
  end
824
827
  end
825
828
 
826
- def get_fair_teams(players)
827
- uri = URI("#{ENV['RATINGS_API_URL']}fair_teams/new")
828
- params = { 'players[]' => players }
829
+ def get_fair_teams(channel_id:, players:)
830
+ uri = URI([ENV['RATINGS_API_URL'], 'fair_teams', 'new'].join('/'))
831
+ params = { :channel_id => channel_id, 'players[]' => players }
829
832
  uri.query = URI.encode_www_form(params)
830
833
  req = Net::HTTP::Get.new(uri)
831
834
 
@@ -839,4 +842,8 @@ class QwtfDiscordBotPug # :nodoc:
839
842
  def ten_minutes_ago
840
843
  Time.now.to_i - TEN_MINUTES
841
844
  end
845
+
846
+ def discord_channel_leaderboard_url(channel_id)
847
+ [ENV['RATINGS_APP_URL'], "discord_channels", channel_id].join('/')
848
+ end
842
849
  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.5.22
4
+ version: 6.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sheldon Johnson
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-02-19 00:00:00.000000000 Z
11
+ date: 2021-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: discordrb