qwtf_discord_bot 2.2.1 → 3.0.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/Gemfile.lock +1 -1
- data/config/endpoints.yaml +5 -0
- data/exe/qwtf_discord_bot +4 -6
- data/lib/qwtf_discord_bot.rb +11 -10
- data/lib/qwtf_discord_bot/qwtf_discord_bot_server.rb +21 -28
- data/lib/qwtf_discord_bot/qwtf_discord_bot_watcher.rb +15 -10
- data/lib/qwtf_discord_bot/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d474c40842701016d9431def0c11f0802e1e9f760b8cd46906b6c1813165da69
|
4
|
+
data.tar.gz: bbee37ae5f25bbc63395ac866704994c1e6bdbfc7399ea12e7147f44c918c1f6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3130bb1aa93eac85706b2294f0bf607061bc3ae3f6ad17c76b83dc76fd302d69014aab4448b3f02878fdf878558b21e0a8415c6a79a9157b45b2ad55624a8184
|
7
|
+
data.tar.gz: 998f5873f02adafd23ad4bfded8728b0df7c0a7ca5507a348cf642c2291e1239fd1a61c887d7c025104bdb3f003ce6c1f658db3d85dc73b18541e55d6873d395
|
data/Gemfile.lock
CHANGED
data/exe/qwtf_discord_bot
CHANGED
@@ -8,17 +8,15 @@ class QwtfDiscordBotExe < Thor
|
|
8
8
|
true
|
9
9
|
end
|
10
10
|
|
11
|
-
desc 'server', 'Responds to
|
12
|
-
method_option :endpoints, type: :array, alias: '-e', default: ['localhost:27500']
|
11
|
+
desc 'server', 'Responds to user commands with server information'
|
13
12
|
def server
|
14
|
-
server_bot = QwtfDiscordBotServer.new
|
13
|
+
server_bot = QwtfDiscordBotServer.new
|
15
14
|
server_bot.run
|
16
15
|
end
|
17
16
|
|
18
|
-
desc 'watcher', 'Watches
|
19
|
-
method_option :endpoints, type: :array, alias: '-e', default: ['localhost:27500']
|
17
|
+
desc 'watcher', 'Watches servers and accounces when a player joins'
|
20
18
|
def watcher
|
21
|
-
watcher_bot = QwtfDiscordBotWatcher.new
|
19
|
+
watcher_bot = QwtfDiscordBotWatcher.new
|
22
20
|
watcher_bot.run
|
23
21
|
end
|
24
22
|
end
|
data/lib/qwtf_discord_bot.rb
CHANGED
@@ -2,29 +2,30 @@ require 'qwtf_discord_bot/version'
|
|
2
2
|
require 'qwtf_discord_bot/qwtf_discord_bot_server'
|
3
3
|
require 'qwtf_discord_bot/qwtf_discord_bot_watcher'
|
4
4
|
require 'discordrb'
|
5
|
+
require 'yaml'
|
5
6
|
|
6
7
|
require 'qstat_request'
|
7
8
|
require 'player'
|
8
9
|
require 'team'
|
9
10
|
require 'emoji'
|
10
11
|
require 'roster'
|
12
|
+
require 'endpoint'
|
13
|
+
|
14
|
+
class QwtfDiscordBot # :nodoc:
|
15
|
+
ENV_VARS = %w[
|
16
|
+
QWTF_DISCORD_BOT_TOKEN
|
17
|
+
QWTF_DISCORD_BOT_CLIENT_ID
|
18
|
+
].freeze
|
11
19
|
|
12
|
-
class QwtfDiscordBot
|
13
|
-
ENV_VARS = [
|
14
|
-
'QWTF_DISCORD_BOT_TOKEN',
|
15
|
-
'QWTF_DISCORD_BOT_CLIENT_ID',
|
16
|
-
'QWTF_DISCORD_BOT_CHANNEL_ID'
|
17
|
-
]
|
18
20
|
|
19
21
|
if ENV_VARS.any? { |var| !ENV.key?(var) }
|
20
|
-
raise
|
22
|
+
raise 'Environment variables not configured'
|
21
23
|
end
|
22
24
|
|
23
25
|
TOKEN = ENV['QWTF_DISCORD_BOT_TOKEN'].strip
|
24
26
|
CLIENT_ID = ENV['QWTF_DISCORD_BOT_CLIENT_ID'].strip
|
25
|
-
CHANNEL_ID = ENV['QWTF_DISCORD_BOT_CHANNEL_ID'].strip
|
26
27
|
|
27
|
-
def initialize
|
28
|
-
@endpoints = endpoints
|
28
|
+
def initialize
|
29
|
+
@endpoints = YAML.load_file('config/endpoints.yaml')
|
29
30
|
end
|
30
31
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
class QwtfDiscordBotServer < QwtfDiscordBot
|
1
|
+
class QwtfDiscordBotServer < QwtfDiscordBot # :nodoc:
|
2
2
|
def run
|
3
3
|
bot = Discordrb::Commands::CommandBot.new(
|
4
4
|
token: TOKEN,
|
@@ -7,11 +7,10 @@ class QwtfDiscordBotServer < QwtfDiscordBot
|
|
7
7
|
)
|
8
8
|
|
9
9
|
bot.command :server do |event, *args|
|
10
|
-
return unless event.channel.id.to_s == CHANNEL_ID
|
11
|
-
|
12
10
|
if args.empty?
|
13
11
|
event.channel.send_message(
|
14
|
-
|
12
|
+
'Provide a server address e.g. `!server sydney.fortressone.org` ' \
|
13
|
+
'or use `!active` or `!all`'
|
15
14
|
)
|
16
15
|
else
|
17
16
|
endpoint = args.first
|
@@ -28,20 +27,20 @@ class QwtfDiscordBotServer < QwtfDiscordBot
|
|
28
27
|
end
|
29
28
|
|
30
29
|
bot.command :all do |event|
|
31
|
-
|
30
|
+
@endpoints.each do |endpoint, channel_ids|
|
31
|
+
channel_ids.each do |channel_id|
|
32
|
+
next if event.channel.id != channel_id
|
32
33
|
|
33
|
-
|
34
|
-
|
35
|
-
|
34
|
+
qstat_request = QstatRequest.new(endpoint)
|
35
|
+
message = qstat_request.server_summary
|
36
|
+
embed = qstat_request.to_embed
|
36
37
|
|
37
|
-
qstat_responses.each do |server|
|
38
|
-
message = server.server_summary
|
39
|
-
embed = server.to_embed
|
40
38
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
39
|
+
if embed
|
40
|
+
event.channel.send_embed(message, embed)
|
41
|
+
else
|
42
|
+
event.channel.send_message(message)
|
43
|
+
end
|
45
44
|
end
|
46
45
|
end
|
47
46
|
|
@@ -49,22 +48,16 @@ class QwtfDiscordBotServer < QwtfDiscordBot
|
|
49
48
|
end
|
50
49
|
|
51
50
|
bot.command :active do |event|
|
52
|
-
|
51
|
+
@endpoints.each do |endpoint, channel_ids|
|
52
|
+
channel_ids.each do |channel_id|
|
53
|
+
next if event.channel.id != channel_id
|
53
54
|
|
54
|
-
|
55
|
-
|
56
|
-
end
|
55
|
+
qstat_request = QstatRequest.new(endpoint)
|
56
|
+
next if qstat_request.is_empty?
|
57
57
|
|
58
|
-
|
58
|
+
message = qstat_request.server_summary
|
59
|
+
embed = qstat_request.to_embed
|
59
60
|
|
60
|
-
if servers_with_players.empty?
|
61
|
-
event.channel.send_message(
|
62
|
-
"All ##{event.channel.name} servers are empty"
|
63
|
-
)
|
64
|
-
else
|
65
|
-
servers_with_players.each do |server|
|
66
|
-
message = server.server_summary
|
67
|
-
embed = server.to_embed
|
68
61
|
|
69
62
|
if embed
|
70
63
|
event.channel.send_embed(message, embed)
|
@@ -4,18 +4,23 @@ class QwtfDiscordBotWatcher < QwtfDiscordBot
|
|
4
4
|
|
5
5
|
def run
|
6
6
|
every(THIRTY_SECONDS) do
|
7
|
-
@endpoints.each do |endpoint|
|
7
|
+
@endpoints.each do |endpoint, channel_ids|
|
8
8
|
request = QstatRequest.new(endpoint)
|
9
|
+
next if request.is_empty?
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
report_joined(
|
11
|
+
request.player_names.each do |name|
|
12
|
+
unless seen_recently?(endpoint: endpoint, name: name)
|
13
|
+
channel_ids.each do |channel_id|
|
14
|
+
report_joined(
|
15
|
+
name: name,
|
16
|
+
channel_id: channel_id,
|
17
|
+
server_summary: request.server_summary
|
18
|
+
)
|
14
19
|
end
|
15
|
-
|
16
|
-
history[endpoint] ||= {}
|
17
|
-
history[endpoint][name] = Time.now
|
18
20
|
end
|
21
|
+
|
22
|
+
history[endpoint] ||= {}
|
23
|
+
history[endpoint][name] = Time.now
|
19
24
|
end
|
20
25
|
end
|
21
26
|
end
|
@@ -35,10 +40,10 @@ class QwtfDiscordBotWatcher < QwtfDiscordBot
|
|
35
40
|
last_seen && (Time.now - last_seen < TEN_MINUTES)
|
36
41
|
end
|
37
42
|
|
38
|
-
def report_joined(name:, server_summary:)
|
43
|
+
def report_joined(name:, channel_id:, server_summary:)
|
39
44
|
Discordrb::API::Channel.create_message(
|
40
45
|
"Bot #{TOKEN}",
|
41
|
-
|
46
|
+
channel_id,
|
42
47
|
"#{name} has joined #{server_summary}"
|
43
48
|
)
|
44
49
|
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:
|
4
|
+
version: 3.0.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: 2019-06-
|
11
|
+
date: 2019-06-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: discordrb
|
@@ -66,6 +66,7 @@ files:
|
|
66
66
|
- bin/rspec
|
67
67
|
- bin/setup
|
68
68
|
- bin/thor
|
69
|
+
- config/endpoints.yaml
|
69
70
|
- emoji/blue_demoman.png
|
70
71
|
- emoji/blue_engineer.png
|
71
72
|
- emoji/blue_hwguy.png
|