qwtf_discord_bot 5.5.24 → 6.0.3

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: e04268c13856cc790d4f097948b514d43a698e4baed69833cd1e9f60f958e5e0
4
- data.tar.gz: b4355be1524b74224a2896d742b1be6e926b264b452d64a7c0f0bd1e093f5800
3
+ metadata.gz: 151d77adaf69b8f02ce8cba749eee97bdc6927956169d673d72917563bb07b91
4
+ data.tar.gz: 781ddacc6d1f792df33553581cdc9a00f583872de3ed6f4581f2024fab7a83bd
5
5
  SHA512:
6
- metadata.gz: 824f14ebed995b4ce6cd55ee452ee0cfc9839d7f157acb62c313ac5f38a6d40373fff0ca4e41e29ab87a0f4dffa5cbe4ee26bbf2215de956f8a9d30a219a449b
7
- data.tar.gz: cedf6ceca11a4d959799aac469653fa09ce32ab06de932a1a72c8d657f1bf8774dd5812a97d0e23ebcbfaaa583d9ae0a542ef58f34e480c330a7105755adc39f
6
+ metadata.gz: b034cd067bc60caaa168f175debfb55f607416a7b7a4efd37f9a0e00b49a693a9722d021989fd3518c8e56134ada4379c9273106fac0a0d8083d493f01d040ec
7
+ data.tar.gz: 74436d2a147f42297fa21f7e20429c8e902bda52535089a6dd8f97ac452686d19ff78702ee413efc69c4f2e1248691456de78c84ba779e79819a04bb077d1363
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- qwtf_discord_bot (5.5.24)
4
+ qwtf_discord_bot (6.0.2)
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.24
1
+ 6.0.3
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/qstat_request.rb CHANGED
@@ -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
@@ -73,7 +73,6 @@ class QwtfDiscordBotPug # :nodoc:
73
73
  0
74
74
  end
75
75
 
76
-
77
76
  message_obj = choose_fair_teams(pug: pug, event: e, iteration: iteration)
78
77
  status(pug: pug, event: e, message_obj: message_obj) if message_obj
79
78
  end
@@ -247,13 +246,6 @@ class QwtfDiscordBotPug # :nodoc:
247
246
  )
248
247
  end
249
248
 
250
- if pug.team(team_no).size >= pug.teamsize
251
- return send_embedded_message(
252
- description: "Team is full",
253
- channel: e.channel
254
- )
255
- end
256
-
257
249
  pug.join_team(team_no: team_no, player_id: user_id)
258
250
 
259
251
  send_embedded_message(
@@ -430,7 +422,7 @@ class QwtfDiscordBotPug # :nodoc:
430
422
  ).body
431
423
 
432
424
  send_embedded_message(
433
- description: "#{TEAM_NAMES[winning_team_no]} wins game ##{id}. `!choose` again. [Ratings](http://ratings.fortressone.org)",
425
+ description: "#{TEAM_NAMES[winning_team_no]} wins game ##{id}. `!choose` again. [Ratings](#{discord_channel_leaderboard_url(e.channel.id)})",
434
426
  channel: e.channel
435
427
  )
436
428
  end
@@ -498,7 +490,7 @@ class QwtfDiscordBotPug # :nodoc:
498
490
  ).body
499
491
 
500
492
  send_embedded_message(
501
- description: "Match ##{id} drawn. `!choose` again. [Ratings](http://ratings.fortressone.org)",
493
+ description: "Match ##{id} drawn. `!choose` again. [Ratings](#{discord_channel_leaderboard_url(e.channel.id)})",
502
494
  channel: e.channel
503
495
  )
504
496
  end
@@ -694,7 +686,10 @@ class QwtfDiscordBotPug # :nodoc:
694
686
  channel: event.channel
695
687
  )
696
688
 
697
- combinations = get_fair_teams(pug.joined_players)
689
+ combinations = get_fair_teams(
690
+ channel_id: event.channel.id, players: pug.joined_players
691
+ )
692
+
698
693
  teams = combinations[iteration]
699
694
 
700
695
  if !teams
@@ -814,7 +809,7 @@ class QwtfDiscordBotPug # :nodoc:
814
809
  end
815
810
 
816
811
  def post_results(json)
817
- uri = URI("#{ENV['RATINGS_API_URL']}matches/")
812
+ uri = URI([ENV['RATINGS_API_URL'], 'matches'].join('/'))
818
813
  req = Net::HTTP::Post.new(uri, 'Content-Type' => 'application/json')
819
814
  req.body = json
820
815
 
@@ -823,9 +818,9 @@ class QwtfDiscordBotPug # :nodoc:
823
818
  end
824
819
  end
825
820
 
826
- def get_fair_teams(players)
827
- uri = URI("#{ENV['RATINGS_API_URL']}fair_teams/new")
828
- params = { 'players[]' => players }
821
+ def get_fair_teams(channel_id:, players:)
822
+ uri = URI([ENV['RATINGS_API_URL'], 'fair_teams', 'new'].join('/'))
823
+ params = { :channel_id => channel_id, 'players[]' => players }
829
824
  uri.query = URI.encode_www_form(params)
830
825
  req = Net::HTTP::Get.new(uri)
831
826
 
@@ -839,4 +834,8 @@ class QwtfDiscordBotPug # :nodoc:
839
834
  def ten_minutes_ago
840
835
  Time.now.to_i - TEN_MINUTES
841
836
  end
837
+
838
+ def discord_channel_leaderboard_url(channel_id)
839
+ [ENV['RATINGS_APP_URL'], "discord_channels", channel_id].join('/')
840
+ end
842
841
  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.24
4
+ version: 6.0.3
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-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: discordrb
@@ -61,6 +61,7 @@ extensions: []
61
61
  extra_rdoc_files: []
62
62
  files:
63
63
  - ".dockerignore"
64
+ - ".env.example"
64
65
  - ".gitignore"
65
66
  - ".rspec"
66
67
  - ".travis.yml"