qwtf_discord_bot 6.1.1 → 6.1.2

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: 1fbbce642ba972a8c0f329cead6f6b0c2eeaaa2d81f8ffc4a72d5efc9ec927e9
4
- data.tar.gz: a9cbe36675e83caeb0d8cdbb9f0cd52cbe8a6847339bd699d09a1b4c37347daf
3
+ metadata.gz: 6ac5cd6d9034e9742121d3a1f73e2b7b4dcfdd88f6d38ac4092857b1c73a1cb2
4
+ data.tar.gz: af41c6aa3d43e94a8e9834d087716df7f7913dea4e5366c416673ed995a53571
5
5
  SHA512:
6
- metadata.gz: 5487069a3f1eb9f4c22f0b6ad3397dbe8f7d18fa9416b2c3a65084d37c74903630d6c4d8a8eb96cc7683d138168338bb3980b29698a72dcd9ac7ab0a24297210
7
- data.tar.gz: f85243fec5e5b0879bc08a3390b0e008b00e31b8f0c78e2b949c378d145a316ace08342c4f08a049641dffcecd930cef27f031fd073ef77955336fd8f9c0348a
6
+ metadata.gz: edc080da2401d91e932fe1a0afc338503e58773fafbaff1290827829e3c30006c529a9cc0f0d9ae0b460feb6d1ef440e12fd8cdebcda74fca941ffa6361c690d
7
+ data.tar.gz: 3864eddf20434aa1e22baf84848b76a871f51453eb95979b5738b275d9438252596eb3ab08c171caa2f2824d77dfcb5e26ef15cf5a9a4f83081b6b4c0f2031b6
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- qwtf_discord_bot (6.0.4)
4
+ qwtf_discord_bot (6.1.2)
5
5
  discordrb (= 3.4.0)
6
6
  redis (~> 4.2)
7
7
  thor (~> 1.1)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 6.1.1
1
+ 6.1.2
data/lib/dashboard.rb CHANGED
@@ -4,7 +4,6 @@ class Dashboard
4
4
  @endpoints = dashboard_config["endpoints"]
5
5
  @messages = {}
6
6
 
7
-
8
7
  channel_name = dashboard_config["name"]
9
8
 
10
9
  old_dashboard_channel = @server.channels.find do |chan|
data/lib/qstat_request.rb CHANGED
@@ -11,28 +11,26 @@ class QstatRequest
11
11
  @result ||= execute
12
12
  end
13
13
 
14
- def to_embed
15
- return nil if is_empty?
16
-
17
- embed = Discordrb::Webhooks::Embed.new
18
-
19
- teams.each do |team|
20
- embed << team.to_embed_field
21
- end
22
-
23
- embed
24
- end
25
-
26
14
  def to_full_embed
27
15
  Discordrb::Webhooks::Embed.new.tap do |embed|
28
16
  embed.add_field(
29
17
  name: name,
30
- value: embed_summary,
18
+ value: join_link,
31
19
  )
32
20
 
33
21
  teams.each do |team|
34
22
  embed << team.to_embed_field
35
23
  end
24
+
25
+ footer = [game_map, "#{numplayers}/#{maxplayers} players"]
26
+
27
+ if has_spectators?
28
+ footer << "#{numspectators}/#{maxspectators} spectators"
29
+ end
30
+
31
+ embed.footer = Discordrb::Webhooks::EmbedFooter.new(
32
+ text: footer.join(MSG_SNIPPET_DELIMITER)
33
+ )
36
34
  end
37
35
  end
38
36
 
@@ -43,9 +41,7 @@ class QstatRequest
43
41
  end
44
42
 
45
43
  def server_summary
46
- return "#{@endpoint} isn't responding" unless game_map
47
-
48
- info = [name, @endpoint, game_map]
44
+ info = [name, game_map]
49
45
 
50
46
  info += if !has_spectators?
51
47
  ["#{numplayers}/#{maxplayers}"]
@@ -56,28 +52,13 @@ class QstatRequest
56
52
  ]
57
53
  end
58
54
 
55
+ info << join_link
56
+
59
57
  info.join(MSG_SNIPPET_DELIMITER)
60
58
  end
61
59
 
62
60
  def join_link
63
- "[Join](http://phobos.baseq.fr:9999/join?url=#{@endpoint})"
64
- end
65
-
66
- def embed_summary
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
77
-
78
- info << join_link
79
-
80
- info.join(MSG_SNIPPET_DELIMITER)
61
+ "<qw://#{@endpoint}>"
81
62
  end
82
63
 
83
64
  def is_empty?
@@ -92,6 +73,10 @@ class QstatRequest
92
73
  numplayers && numplayers > 0
93
74
  end
94
75
 
76
+ def live_server?
77
+ !game_map.nil?
78
+ end
79
+
95
80
  private
96
81
 
97
82
  def has_spectators?
@@ -16,20 +16,17 @@ class QwtfDiscordBotServer
16
16
  message = 'Provide a server address e.g. `!server ' \
17
17
  'sydney.fortressone.org` or use `!active` or `!all`'
18
18
  event.channel.send_message(message)
19
- puts message
19
+
20
+ return puts message
21
+ end
22
+
23
+ endpoint = args.first
24
+ request = QstatRequest.new(endpoint)
25
+
26
+ if !request.live_server?
27
+ event.channel.send_message("#{endpoint} isn't responding")
20
28
  else
21
- endpoint = args.first
22
- qstat_response = QstatRequest.new(endpoint)
23
- message = qstat_response.server_summary
24
- embed = qstat_response.to_embed
25
-
26
- if embed
27
- event.channel.send_embed(message, embed)
28
- puts message
29
- else
30
- event.channel.send_message(message)
31
- puts message
32
- end
29
+ event.channel.send_embed(nil, request.to_full_embed)
33
30
  end
34
31
  end
35
32
 
@@ -43,20 +40,16 @@ class QwtfDiscordBotServer
43
40
  if endpoints_for_this_channel.empty?
44
41
  message = 'There are no servers associated with this channel'
45
42
  event.channel.send_message(message)
46
- puts message
47
- else
48
- endpoints_for_this_channel.each do |endpoint|
49
- qstat_request = QstatRequest.new(endpoint.address)
50
- message = qstat_request.server_summary
51
- embed = qstat_request.to_embed
52
-
53
- if embed
54
- event.channel.send_embed(message, embed)
55
- puts message
56
- else
57
- event.channel.send_message(message)
58
- puts message
59
- end
43
+ return puts message
44
+ end
45
+
46
+ endpoints_for_this_channel.each do |endpoint|
47
+ request = QstatRequest.new(endpoint.address)
48
+
49
+ if !request.live_server?
50
+ event.channel.send_message("#{endpoint} isn't responding")
51
+ else
52
+ event.channel.send_embed(nil, request.to_full_embed)
60
53
  end
61
54
  end
62
55
 
@@ -73,35 +66,27 @@ class QwtfDiscordBotServer
73
66
  if endpoints_for_this_channel.empty?
74
67
  message = 'There are no servers associated with this channel'
75
68
  event.channel.send_message(message)
76
- puts message
77
- else
78
- qstat_requests = endpoints_for_this_channel.map do |endpoint|
79
- QstatRequest.new(endpoint.address)
80
- end
69
+ return puts message
70
+ end
81
71
 
82
- servers_with_players = qstat_requests.reject do |server|
83
- server.is_empty?
84
- end
72
+ qstat_requests = endpoints_for_this_channel.map do |endpoint|
73
+ QstatRequest.new(endpoint.address)
74
+ end
85
75
 
86
- if servers_with_players.empty?
87
- message = "All ##{event.channel.name} servers are empty"
88
- event.channel.send_message(message)
89
- puts message
90
- else
91
- servers_with_players.each do |server|
92
- message = server.server_summary
93
- embed = server.to_embed
94
-
95
- if embed
96
- event.channel.send_embed(message, embed)
97
- puts message
98
- else
99
- event.channel.send_message(message)
100
- puts message
101
- end
102
- end
103
- end
76
+ servers_with_players = qstat_requests.reject do |server|
77
+ server.is_empty?
104
78
  end
79
+
80
+ if servers_with_players.empty?
81
+ message = "All ##{event.channel.name} servers are empty"
82
+ event.channel.send_message(message)
83
+ return puts message
84
+ end
85
+
86
+ servers_with_players.each do |server|
87
+ event.channel.send_embed(nil, server.to_full_embed)
88
+ end
89
+
105
90
  return nil
106
91
  end
107
92
 
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: 6.1.1
4
+ version: 6.1.2
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-06-11 00:00:00.000000000 Z
11
+ date: 2021-06-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: discordrb