qwtf_discord_bot 5.4.13 → 5.5.0
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 +4 -4
- data/VERSION +1 -1
- data/docker-compose.yml +13 -0
- data/exe/qwtf_discord_bot +6 -0
- data/lib/dashboard.rb +40 -0
- data/lib/qstat_request.rb +48 -2
- data/lib/qwtf_discord_bot.rb +4 -3
- data/lib/qwtf_discord_bot/config.rb +5 -0
- data/lib/qwtf_discord_bot/qwtf_discord_bot_dashboard.rb +41 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 114b6c7c1ecc4b4cd957b359b58f42af35a29979830fbb397121ef37d26b2fdd
|
4
|
+
data.tar.gz: '0098c992179231b57e8b443b8f658354e5e05bc4e284de739c1e442c771d163f'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c8da38ea19d0f3bd0ebcc0bf82468d8347ec7d343f0f67acafb1fa0bb567b50ad28ad2af268022cf4f1fd6e1f405203740318a6a9112ce9d4971a90d3fa66f68
|
7
|
+
data.tar.gz: c801b72f1614f818816a6ced4737d58cb4b59dfe2c5db779b22cf7d124ceb364bdc58d47307f842efe58992eee31c6c729e769f8b6a3f795b9ad462eb76b7e1c
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
5.
|
1
|
+
5.5.0
|
data/docker-compose.yml
CHANGED
@@ -39,3 +39,16 @@ services:
|
|
39
39
|
- type: bind
|
40
40
|
source: "/home/ubuntu/.config/qwtf_discord_bot/config.yaml"
|
41
41
|
target: /discord-bot/config.yaml
|
42
|
+
discord-dashboard-bot:
|
43
|
+
image: fortressone/discord-bot:latest
|
44
|
+
command: dashboard
|
45
|
+
restart: always
|
46
|
+
depends_on:
|
47
|
+
- redis
|
48
|
+
environment:
|
49
|
+
- REDIS_URL=redis://redis
|
50
|
+
- RATINGS_API_URL
|
51
|
+
volumes:
|
52
|
+
- type: bind
|
53
|
+
source: "/home/ubuntu/.config/qwtf_discord_bot/config.yaml"
|
54
|
+
target: /discord-bot/config.yaml
|
data/exe/qwtf_discord_bot
CHANGED
@@ -26,6 +26,12 @@ class QwtfDiscordBotExe < Thor
|
|
26
26
|
watcher_bot = QwtfDiscordBotWatcher.new
|
27
27
|
watcher_bot.run
|
28
28
|
end
|
29
|
+
|
30
|
+
desc 'dashboard', 'A live dashboard with active server information'
|
31
|
+
def dashboard
|
32
|
+
dashboard_bot = QwtfDiscordBotDashboard.new
|
33
|
+
dashboard_bot.run
|
34
|
+
end
|
29
35
|
end
|
30
36
|
|
31
37
|
QwtfDiscordBotExe.start
|
data/lib/dashboard.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
class Dashboard
|
2
|
+
def initialize(channel, bot)
|
3
|
+
@channel_id = channel["id"]
|
4
|
+
@endpoints = channel["endpoints"]
|
5
|
+
@bot = bot
|
6
|
+
@messages = {}
|
7
|
+
end
|
8
|
+
|
9
|
+
def update
|
10
|
+
@endpoints.each do |endpoint|
|
11
|
+
qstat_request = QstatRequest.new(endpoint)
|
12
|
+
|
13
|
+
if qstat_request.is_empty?
|
14
|
+
next unless @messages[endpoint]
|
15
|
+
|
16
|
+
@messages[endpoint].delete
|
17
|
+
@messages.delete(endpoint)
|
18
|
+
end
|
19
|
+
|
20
|
+
embed = qstat_request.to_full_embed
|
21
|
+
|
22
|
+
@messages[endpoint] = if @messages[endpoint]
|
23
|
+
@messages[endpoint].edit(nil, embed)
|
24
|
+
else
|
25
|
+
channel.send_embed(nil, embed)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def channel
|
33
|
+
data = Discordrb::API::Channel.resolve(
|
34
|
+
"Bot #{QwtfDiscordBot.config.token}",
|
35
|
+
@channel_id
|
36
|
+
)
|
37
|
+
|
38
|
+
Discordrb::Channel.new(JSON.parse(data), @bot)
|
39
|
+
end
|
40
|
+
end
|
data/lib/qstat_request.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
class QstatRequest
|
2
|
+
MSG_SNIPPET_DELIMITER = ' · '
|
3
|
+
|
2
4
|
attr_accessor :result
|
3
5
|
|
4
6
|
def initialize(endpoint)
|
@@ -21,6 +23,19 @@ class QstatRequest
|
|
21
23
|
embed
|
22
24
|
end
|
23
25
|
|
26
|
+
def to_full_embed
|
27
|
+
Discordrb::Webhooks::Embed.new.tap do |embed|
|
28
|
+
embed.add_field(
|
29
|
+
name: name,
|
30
|
+
value: embed_summary,
|
31
|
+
)
|
32
|
+
|
33
|
+
teams.each do |team|
|
34
|
+
embed.add_field(team.to_embed_field)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
24
39
|
def to_message
|
25
40
|
return server_summary if is_empty?
|
26
41
|
|
@@ -29,9 +44,40 @@ class QstatRequest
|
|
29
44
|
|
30
45
|
def server_summary
|
31
46
|
return "#{@endpoint} isn't responding" unless game_map
|
32
|
-
return "#{name} | #{@endpoint} | #{game_map} | #{numplayers}/#{maxplayers}" unless has_spectators?
|
33
47
|
|
34
|
-
|
48
|
+
if !has_spectators?
|
49
|
+
return [
|
50
|
+
name,
|
51
|
+
@endpoint,
|
52
|
+
game_map,
|
53
|
+
"#{numplayers}/#{maxplayers}"
|
54
|
+
].join(MSG_SNIPPET_DELIMITER)
|
55
|
+
end
|
56
|
+
|
57
|
+
[
|
58
|
+
name,
|
59
|
+
@endpoint,
|
60
|
+
game_map,
|
61
|
+
"#{numplayers}/#{maxplayers} players",
|
62
|
+
"#{numspectators}/#{maxspectators} spectators"
|
63
|
+
].join(MSG_SNIPPET_DELIMITER)
|
64
|
+
end
|
65
|
+
|
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
|
74
|
+
|
75
|
+
[
|
76
|
+
@endpoint,
|
77
|
+
game_map,
|
78
|
+
"#{numplayers}/#{maxplayers} players",
|
79
|
+
"#{numspectators}/#{maxspectators} spectators"
|
80
|
+
].join(MSG_SNIPPET_DELIMITER)
|
35
81
|
end
|
36
82
|
|
37
83
|
def is_empty?
|
data/lib/qwtf_discord_bot.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
|
+
require 'discordrb'
|
2
|
+
require 'yaml'
|
3
|
+
require 'redis'
|
1
4
|
require 'qwtf_discord_bot/version'
|
2
5
|
require 'qwtf_discord_bot/qwtf_discord_bot_server'
|
3
6
|
require 'qwtf_discord_bot/qwtf_discord_bot_pug'
|
4
7
|
require 'qwtf_discord_bot/qwtf_discord_bot_watcher'
|
8
|
+
require 'qwtf_discord_bot/qwtf_discord_bot_dashboard'
|
5
9
|
require 'qwtf_discord_bot/config'
|
6
|
-
require 'discordrb'
|
7
|
-
require 'yaml'
|
8
|
-
require 'redis'
|
9
10
|
|
10
11
|
require 'qstat_request'
|
11
12
|
require 'player'
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'endpoint'
|
2
|
+
require 'dashboard'
|
2
3
|
|
3
4
|
class Config
|
4
5
|
def initialize(config)
|
@@ -19,6 +20,10 @@ class Config
|
|
19
20
|
end
|
20
21
|
end
|
21
22
|
|
23
|
+
def dashboards
|
24
|
+
@dashboards ||= @config['dashboards']
|
25
|
+
end
|
26
|
+
|
22
27
|
def emojis
|
23
28
|
@emojis ||= @config['emojis']
|
24
29
|
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
class QwtfDiscordBotDashboard
|
2
|
+
THIRTY_SECONDS = 30
|
3
|
+
|
4
|
+
def run
|
5
|
+
bot = Discordrb::Commands::CommandBot.new(
|
6
|
+
token: QwtfDiscordBot.config.token,
|
7
|
+
client_id: QwtfDiscordBot.config.client_id,
|
8
|
+
help_command: false,
|
9
|
+
prefix: proc do |message|
|
10
|
+
match = /^\!(\w+)(.*)/.match(message.content)
|
11
|
+
if match
|
12
|
+
first = match[1]
|
13
|
+
rest = match[2]
|
14
|
+
# Return the modified string with the first word lowercase:
|
15
|
+
"#{first.downcase}#{rest}"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
)
|
19
|
+
|
20
|
+
@dashboards ||= QwtfDiscordBot.config.dashboards.map do |channel|
|
21
|
+
Dashboard.new(channel, bot)
|
22
|
+
end
|
23
|
+
|
24
|
+
every(THIRTY_SECONDS) do
|
25
|
+
@dashboards.each do |dashboard|
|
26
|
+
dashboard.update
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def every(n_seconds)
|
34
|
+
loop do
|
35
|
+
before = Time.now
|
36
|
+
yield
|
37
|
+
interval = n_seconds - (Time.now - before)
|
38
|
+
sleep(interval) if interval > 0
|
39
|
+
end
|
40
|
+
end
|
41
|
+
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.
|
4
|
+
version: 5.5.0
|
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-11-
|
11
|
+
date: 2020-11-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: discordrb
|
@@ -102,6 +102,7 @@ files:
|
|
102
102
|
- emoji/red_soldier.png
|
103
103
|
- emoji/red_spy.png
|
104
104
|
- exe/qwtf_discord_bot
|
105
|
+
- lib/dashboard.rb
|
105
106
|
- lib/emoji.rb
|
106
107
|
- lib/endpoint.rb
|
107
108
|
- lib/event_decorator.rb
|
@@ -110,6 +111,7 @@ files:
|
|
110
111
|
- lib/qstat_request.rb
|
111
112
|
- lib/qwtf_discord_bot.rb
|
112
113
|
- lib/qwtf_discord_bot/config.rb
|
114
|
+
- lib/qwtf_discord_bot/qwtf_discord_bot_dashboard.rb
|
113
115
|
- lib/qwtf_discord_bot/qwtf_discord_bot_pug.rb
|
114
116
|
- lib/qwtf_discord_bot/qwtf_discord_bot_server.rb
|
115
117
|
- lib/qwtf_discord_bot/qwtf_discord_bot_watcher.rb
|