qwtf_discord_bot 3.0.0 → 4.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/.gitignore +1 -0
- data/Gemfile.lock +1 -1
- data/README.md +35 -38
- data/lib/config.rb +43 -0
- data/lib/qwtf_discord_bot.rb +6 -14
- data/lib/qwtf_discord_bot/qwtf_discord_bot_server.rb +10 -10
- data/lib/qwtf_discord_bot/qwtf_discord_bot_watcher.rb +8 -7
- data/lib/qwtf_discord_bot/version.rb +1 -1
- metadata +2 -2
- data/config/endpoints.yaml +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 53b110507d7aea432897ecfd3ee11c4837df5282b88941163e4fb8dd9b67aa83
|
4
|
+
data.tar.gz: ffe4cefa3aa20ba3f091f157152b083929584a2331be84bb80d20cf3ada2786c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f0701391ba3c5b82dfcef5188af67aeb70db9cb97503c449a4940fd9358512ff65f575fdebac353175b95fcbaac7b3f208cadc0f992921e954f6f1ada6830f5c
|
7
|
+
data.tar.gz: a144dbdef8a1f08260501051e3667069a9f821d8718ec7f3f59dad1d8ab6b6a75fc2ae849e5ba0ae6b54f325421262a066ffbba9053deab9cccd8bc8b03d53b5
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -16,45 +16,55 @@ A Discord bot for checking the status of QuakeWorld Team Fortress servers
|
|
16
16
|
|
17
17
|
## Usage
|
18
18
|
|
19
|
-
Create a bot on discord.
|
20
|
-
|
21
|
-
|
19
|
+
- Create a bot on discord.
|
20
|
+
- Create a `config.yaml` file containing your bots credentials and server endpoints. E.G.
|
21
|
+
|
22
|
+
```yaml
|
23
|
+
---
|
24
|
+
token: "dhjksahdkjhhur43hu4hu5b4b5k34j12b4kj3b4kjb4j32kb4kjb4kb3k2b"
|
25
|
+
client_id: "873298379487294398"
|
26
|
+
endpoints:
|
27
|
+
- "sydney.fortressone.org":
|
28
|
+
- channel_ids:
|
29
|
+
- 832749832749873298
|
30
|
+
- 798437748937298448
|
31
|
+
- "sydney.fortressone.org:27501":
|
32
|
+
- channel_ids:
|
33
|
+
- 590204247224745986
|
34
|
+
- "dallas.fortressone.org":
|
35
|
+
- channel_ids:
|
36
|
+
- 480928490328409328
|
37
|
+
```
|
22
38
|
|
23
|
-
|
39
|
+
- Set the `QWTF_DISCORD_BOT_CONFIG_FILE` environment variable or default to
|
40
|
+
`config.yaml` in the present working directory
|
24
41
|
|
42
|
+
```sh
|
43
|
+
$ export QWTF_DISCORD_BOT_CONFIG_FILE="config.yaml"
|
44
|
+
```
|
25
45
|
|
26
|
-
### List commands
|
27
46
|
|
28
|
-
$ bundle exec exe/qwtf-discord-bot help
|
29
47
|
|
30
|
-
|
48
|
+
### Commands
|
31
49
|
|
50
|
+
There are two modules:
|
32
51
|
|
33
|
-
### Server
|
34
52
|
|
35
|
-
|
36
|
-
server. Defaults to the hostname command line argument, but will accept a
|
37
|
-
hostname from the user. I.E. `!server fortressone.org`
|
53
|
+
#### Server
|
38
54
|
|
39
|
-
|
55
|
+
$ qwtf-discord-bot server
|
40
56
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
Options:
|
46
|
-
[--endpoints=one two three]
|
47
|
-
# Default: ["localhost:27500"]
|
48
|
-
```
|
57
|
+
This responds to discord messages:
|
58
|
+
- `!server`
|
59
|
+
- `!active`
|
60
|
+
- `!all`
|
49
61
|
|
50
|
-
|
62
|
+

|
51
63
|
|
52
|
-
$ qwtf-discord-bot server --endpoints \
|
53
|
-
sydney.fortressone.org:27500 \
|
54
|
-
sydney.fortressone.org:27501
|
55
64
|
|
65
|
+
#### Watcher
|
56
66
|
|
57
|
-
|
67
|
+
$ qwtf-discord-bot watcher
|
58
68
|
|
59
69
|
This watches the game server and announces if anyone has joined the server. It
|
60
70
|
polls the server once every 30 seconds and will only report a player joining if
|
@@ -62,19 +72,6 @@ they haven't been connected for more than ten minutes.
|
|
62
72
|
|
63
73
|

|
64
74
|
|
65
|
-
```
|
66
|
-
Usage:
|
67
|
-
qwtf_discord_bot watcher
|
68
|
-
|
69
|
-
Options:
|
70
|
-
[--endpoints=one two three]
|
71
|
-
# Default: ["localhost:27500"]
|
72
|
-
```
|
73
|
-
|
74
|
-
E.G.
|
75
|
-
|
76
|
-
$ bundle exec exe/qwtf-discord-bot watcher --endpoints sydney.fortressone.org:27501
|
77
|
-
|
78
75
|
|
79
76
|
## License
|
80
77
|
|
data/lib/config.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
class Config
|
2
|
+
def initialize(config)
|
3
|
+
@config = YAML.load_file(config)
|
4
|
+
end
|
5
|
+
|
6
|
+
def token
|
7
|
+
@token ||= @config["token"]
|
8
|
+
end
|
9
|
+
|
10
|
+
def client_id
|
11
|
+
@client_id ||= @config["client_id"]
|
12
|
+
end
|
13
|
+
|
14
|
+
def endpoints
|
15
|
+
@endpoints ||= @config["endpoints"].map do |endpoint|
|
16
|
+
Endpoint.new(endpoint)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class Endpoint
|
22
|
+
def initialize(config)
|
23
|
+
@config = config
|
24
|
+
end
|
25
|
+
|
26
|
+
def address
|
27
|
+
@config.keys.first
|
28
|
+
end
|
29
|
+
|
30
|
+
def channel_ids
|
31
|
+
channel_ids = []
|
32
|
+
|
33
|
+
@config.values.each do |settings|
|
34
|
+
settings.each do |setting|
|
35
|
+
setting["channel_ids"].each do |channel_id|
|
36
|
+
channel_ids << channel_id
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
channel_ids
|
42
|
+
end
|
43
|
+
end
|
data/lib/qwtf_discord_bot.rb
CHANGED
@@ -4,28 +4,20 @@ require 'qwtf_discord_bot/qwtf_discord_bot_watcher'
|
|
4
4
|
require 'discordrb'
|
5
5
|
require 'yaml'
|
6
6
|
|
7
|
+
require 'config'
|
7
8
|
require 'qstat_request'
|
8
9
|
require 'player'
|
9
10
|
require 'team'
|
10
11
|
require 'emoji'
|
11
12
|
require 'roster'
|
12
|
-
require 'endpoint'
|
13
13
|
|
14
14
|
class QwtfDiscordBot # :nodoc:
|
15
|
-
|
16
|
-
QWTF_DISCORD_BOT_TOKEN
|
17
|
-
QWTF_DISCORD_BOT_CLIENT_ID
|
18
|
-
].freeze
|
19
|
-
|
20
|
-
|
21
|
-
if ENV_VARS.any? { |var| !ENV.key?(var) }
|
22
|
-
raise 'Environment variables not configured'
|
23
|
-
end
|
24
|
-
|
25
|
-
TOKEN = ENV['QWTF_DISCORD_BOT_TOKEN'].strip
|
26
|
-
CLIENT_ID = ENV['QWTF_DISCORD_BOT_CLIENT_ID'].strip
|
15
|
+
CONFIG_FILE = ENV['QWTF_DISCORD_BOT_CONFIG_FILE'] || "#{Dir.pwd}/config.yaml"
|
27
16
|
|
28
17
|
def initialize
|
29
|
-
@
|
18
|
+
@config = Config.new(CONFIG_FILE)
|
19
|
+
@token = @config.token
|
20
|
+
@client_id = @config.client_id
|
21
|
+
@endpoints = @config.endpoints
|
30
22
|
end
|
31
23
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
class QwtfDiscordBotServer < QwtfDiscordBot # :nodoc:
|
2
2
|
def run
|
3
3
|
bot = Discordrb::Commands::CommandBot.new(
|
4
|
-
token:
|
5
|
-
client_id:
|
4
|
+
token: @token,
|
5
|
+
client_id: @client_id,
|
6
6
|
prefix: '!'
|
7
7
|
)
|
8
8
|
|
@@ -27,11 +27,11 @@ class QwtfDiscordBotServer < QwtfDiscordBot # :nodoc:
|
|
27
27
|
end
|
28
28
|
|
29
29
|
bot.command :all do |event|
|
30
|
-
@endpoints.each do |endpoint
|
31
|
-
channel_ids.each do |channel_id|
|
32
|
-
next
|
30
|
+
@endpoints.each do |endpoint|
|
31
|
+
endpoint.channel_ids.each do |channel_id|
|
32
|
+
next unless event.channel.id == channel_id
|
33
33
|
|
34
|
-
qstat_request = QstatRequest.new(endpoint)
|
34
|
+
qstat_request = QstatRequest.new(endpoint.address)
|
35
35
|
message = qstat_request.server_summary
|
36
36
|
embed = qstat_request.to_embed
|
37
37
|
|
@@ -48,11 +48,11 @@ class QwtfDiscordBotServer < QwtfDiscordBot # :nodoc:
|
|
48
48
|
end
|
49
49
|
|
50
50
|
bot.command :active do |event|
|
51
|
-
@endpoints.each do |endpoint
|
52
|
-
channel_ids.each do |channel_id|
|
53
|
-
next
|
51
|
+
@endpoints.each do |endpoint|
|
52
|
+
endpoint.channel_ids.each do |channel_id|
|
53
|
+
next unless event.channel.id == channel_id
|
54
54
|
|
55
|
-
qstat_request = QstatRequest.new(endpoint)
|
55
|
+
qstat_request = QstatRequest.new(endpoint.address)
|
56
56
|
next if qstat_request.is_empty?
|
57
57
|
|
58
58
|
message = qstat_request.server_summary
|
@@ -4,13 +4,14 @@ class QwtfDiscordBotWatcher < QwtfDiscordBot
|
|
4
4
|
|
5
5
|
def run
|
6
6
|
every(THIRTY_SECONDS) do
|
7
|
-
@endpoints.each do |endpoint
|
8
|
-
|
7
|
+
@endpoints.each do |endpoint|
|
8
|
+
address = endpoint.address
|
9
|
+
request = QstatRequest.new(address)
|
9
10
|
next if request.is_empty?
|
10
11
|
|
11
12
|
request.player_names.each do |name|
|
12
|
-
unless seen_recently?(endpoint:
|
13
|
-
channel_ids.each do |channel_id|
|
13
|
+
unless seen_recently?(endpoint: address, name: name)
|
14
|
+
endpoint.channel_ids.each do |channel_id|
|
14
15
|
report_joined(
|
15
16
|
name: name,
|
16
17
|
channel_id: channel_id,
|
@@ -19,8 +20,8 @@ class QwtfDiscordBotWatcher < QwtfDiscordBot
|
|
19
20
|
end
|
20
21
|
end
|
21
22
|
|
22
|
-
history[
|
23
|
-
history[
|
23
|
+
history[address] ||= {}
|
24
|
+
history[address][name] = Time.now
|
24
25
|
end
|
25
26
|
end
|
26
27
|
end
|
@@ -42,7 +43,7 @@ class QwtfDiscordBotWatcher < QwtfDiscordBot
|
|
42
43
|
|
43
44
|
def report_joined(name:, channel_id:, server_summary:)
|
44
45
|
Discordrb::API::Channel.create_message(
|
45
|
-
"Bot #{
|
46
|
+
"Bot #{@token}",
|
46
47
|
channel_id,
|
47
48
|
"#{name} has joined #{server_summary}"
|
48
49
|
)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: qwtf_discord_bot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 4.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sheldon Johnson
|
@@ -66,7 +66,6 @@ files:
|
|
66
66
|
- bin/rspec
|
67
67
|
- bin/setup
|
68
68
|
- bin/thor
|
69
|
-
- config/endpoints.yaml
|
70
69
|
- emoji/blue_demoman.png
|
71
70
|
- emoji/blue_engineer.png
|
72
71
|
- emoji/blue_hwguy.png
|
@@ -86,6 +85,7 @@ files:
|
|
86
85
|
- emoji/red_soldier.png
|
87
86
|
- emoji/red_spy.png
|
88
87
|
- exe/qwtf_discord_bot
|
88
|
+
- lib/config.rb
|
89
89
|
- lib/emoji.rb
|
90
90
|
- lib/player.rb
|
91
91
|
- lib/qstat_request.rb
|