qwtf_discord_bot 4.2.2 → 5.0.1
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/.dockerignore +3 -0
- data/.gitignore +1 -1
- data/Dockerfile +12 -7
- data/Gemfile +1 -0
- data/Gemfile.lock +4 -3
- data/README.md +114 -73
- data/VERSION +1 -0
- data/docker-compose.yml +16 -4
- data/exe/qwtf_discord_bot +7 -0
- data/lib/event_wrapper.rb +58 -0
- data/lib/qwtf_discord_bot.rb +13 -3
- data/lib/qwtf_discord_bot/qwtf_discord_bot_pug.rb +138 -0
- data/lib/qwtf_discord_bot/qwtf_discord_bot_server.rb +20 -12
- data/lib/qwtf_discord_bot/qwtf_discord_bot_watcher.rb +5 -9
- data/lib/qwtf_discord_bot/version.rb +1 -1
- data/qwtf_discord_bot.gemspec +1 -1
- metadata +15 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1952a9bb33cf18bcda01f202ed5900cb5168f0c3e1ad8aa083b1ee0ae54b6ed0
|
4
|
+
data.tar.gz: 31ab6af67990f6479640402bf20ec90fdcfad9943b5cc84697ea2c18776e9676
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ae59b76eda7fe87baa54c6b79d5d0d32de7f2cb947d2631eed2b2d2a3769376727c855a8ba1293c5e00fd23376357a5153cd3bdfa00e328868ee2f1b669f3e3
|
7
|
+
data.tar.gz: c0fd9ef59318cde38734e3f28d9f8a41a9c6ad0a829aae70ee48a07aeb5f509b6a22a58e6e6148a6c4324a1733f6d9d3c7e0104994ccbfd6d4ef6305cda803fb
|
data/.dockerignore
ADDED
data/.gitignore
CHANGED
data/Dockerfile
CHANGED
@@ -1,9 +1,14 @@
|
|
1
1
|
FROM ruby:2.6
|
2
|
-
WORKDIR /discord-bot
|
3
|
-
RUN
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
2
|
+
WORKDIR /discord-bot/
|
3
|
+
RUN git clone https://github.com/multiplay/qstat.git \
|
4
|
+
&& cd /discord-bot/qstat \
|
5
|
+
&& ./autogen.sh \
|
6
|
+
&& ./configure \
|
7
|
+
&& make install \
|
8
|
+
&& cd /discord-bot/
|
9
|
+
ENV PATH="/discord-bot/qstat/:${PATH}"
|
10
|
+
COPY . /discord-bot/
|
11
|
+
RUN bundle install \
|
12
|
+
&& gem build qwtf_discord_bot.gemspec \
|
13
|
+
&& gem install --local /discord-bot/qwtf_discord_bot-$(cat VERSION).gem
|
9
14
|
ENTRYPOINT ["qwtf_discord_bot"]
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
qwtf_discord_bot (4.
|
4
|
+
qwtf_discord_bot (4.2.6)
|
5
5
|
discordrb (~> 3.3)
|
6
|
-
redis
|
6
|
+
redis (~> 4.1)
|
7
7
|
thor (~> 0.20)
|
8
8
|
|
9
9
|
GEM
|
@@ -90,8 +90,9 @@ DEPENDENCIES
|
|
90
90
|
factory_bot
|
91
91
|
pry
|
92
92
|
qwtf_discord_bot!
|
93
|
+
redis
|
93
94
|
rspec
|
94
95
|
thor
|
95
96
|
|
96
97
|
BUNDLED WITH
|
97
|
-
1.17.
|
98
|
+
1.17.2
|
data/README.md
CHANGED
@@ -11,7 +11,7 @@ A Discord bot for checking the status of QuakeWorld Team Fortress servers
|
|
11
11
|
|
12
12
|
## Installation
|
13
13
|
|
14
|
-
|
14
|
+
gem install qwtf_discord_bot
|
15
15
|
|
16
16
|
|
17
17
|
## Usage
|
@@ -20,60 +20,58 @@ A Discord bot for checking the status of QuakeWorld Team Fortress servers
|
|
20
20
|
- Create a `~/.config/qwtf_discord_bot/config.yaml` file containing your bots
|
21
21
|
credentials and server endpoints
|
22
22
|
|
23
|
-
```yaml
|
24
|
-
---
|
25
|
-
token: "dhjksahdkjhhur43hu4hu5b4b5k34j12b4kj3b4kjb4j32kb4kjb4kb3k2b"
|
26
|
-
client_id: "873298379487294398"
|
27
|
-
endpoints:
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
emojis:
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
```
|
60
|
-
|
61
|
-
- Use the `QWTF_DISCORD_BOT_CONFIG_FILE` environment variable
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
$ export QWTF_DISCORD_BOT_CONFIG_FILE="config.yaml"
|
66
|
-
```
|
23
|
+
```yaml
|
24
|
+
---
|
25
|
+
token: "dhjksahdkjhhur43hu4hu5b4b5k34j12b4kj3b4kjb4j32kb4kjb4kb3k2b"
|
26
|
+
client_id: "873298379487294398"
|
27
|
+
endpoints:
|
28
|
+
- "sydney.fortressone.org":
|
29
|
+
- channel_ids:
|
30
|
+
- 832749832749873298
|
31
|
+
- 798437748937298448
|
32
|
+
- "sydney.fortressone.org:27501":
|
33
|
+
- channel_ids:
|
34
|
+
- 590204247224745986
|
35
|
+
- "dallas.fortressone.org":
|
36
|
+
- channel_ids:
|
37
|
+
- 480928490328409328
|
38
|
+
emojis:
|
39
|
+
red:
|
40
|
+
scout: "<:scout_red:424097703127941130>"
|
41
|
+
sniper: "<:sniper_red:424097704076115978>"
|
42
|
+
soldier: "<:soldier_red:424097704197619712>"
|
43
|
+
demoman: "<:demoman_red:424097687739301919>"
|
44
|
+
medic: "<:medic_red:424097695418941451>"
|
45
|
+
pyro: "<:pyro_red:424097704403271691>"
|
46
|
+
hwguy: "<:hwguy_red:424097694030757889>"
|
47
|
+
spy: "<:spy_red:424097704138899466>"
|
48
|
+
engineer: "<:engineer_red:424097694680612864>"
|
49
|
+
blue:
|
50
|
+
scout: "<:scout_blue:456062063983460353>"
|
51
|
+
sniper: "<:sniper_blue:456062061953417216>"
|
52
|
+
soldier: "<:soldier_blue:456062062997536801>"
|
53
|
+
demoman: "<:demoman_blue:456061938636554240>"
|
54
|
+
medic: "<:medic_blue:456062056710537217>"
|
55
|
+
pyro: "<:pyro_blue:456062062460928010>"
|
56
|
+
hwguy: "<:hwguy_blue:456062063190736926>"
|
57
|
+
spy: "<:spy_blue:456062062032846849>"
|
58
|
+
engineer: "<:engineer_blue:456062031125020683>"
|
59
|
+
```
|
60
|
+
|
61
|
+
- Use the `QWTF_DISCORD_BOT_CONFIG_FILE` environment variable to specify an
|
62
|
+
alternative config file path
|
63
|
+
|
64
|
+
export QWTF_DISCORD_BOT_CONFIG_FILE="config.yaml"
|
67
65
|
|
68
66
|
|
69
67
|
### Commands
|
70
68
|
|
71
|
-
There are
|
69
|
+
There are three modules:
|
72
70
|
|
73
71
|
|
74
72
|
#### Server
|
75
73
|
|
76
|
-
|
74
|
+
qwtf-discord-bot server
|
77
75
|
|
78
76
|
This responds to discord messages:
|
79
77
|
- `!server`
|
@@ -83,9 +81,21 @@ This responds to discord messages:
|
|
83
81
|

|
84
82
|
|
85
83
|
|
84
|
+
#### Pug
|
85
|
+
|
86
|
+
qwtf-discord-bot pug
|
87
|
+
|
88
|
+
This responds to discord messages:
|
89
|
+
- `!join`
|
90
|
+
- `!leave`
|
91
|
+
- `!status`
|
92
|
+
- `!maxplayers <no_of_players>`
|
93
|
+
- `!leave`
|
94
|
+
|
95
|
+
|
86
96
|
#### Watcher
|
87
97
|
|
88
|
-
|
98
|
+
qwtf-discord-bot watcher
|
89
99
|
|
90
100
|
This watches the game server and announces if anyone has joined the server. It
|
91
101
|
polls the server once every 30 seconds and will only report a player joining if
|
@@ -94,47 +104,78 @@ they haven't been connected for more than ten minutes.
|
|
94
104
|

|
95
105
|
|
96
106
|
|
97
|
-
##
|
107
|
+
## Gem
|
98
108
|
|
99
109
|
Build:
|
100
110
|
|
101
|
-
|
102
|
-
|
103
|
-
|
111
|
+
gem build qwtf_discrd_bot.gemspec
|
112
|
+
|
113
|
+
|
114
|
+
Install:
|
115
|
+
|
116
|
+
|
117
|
+
gem install --local qwtf_discord_bot-$(cat VERSION).gem
|
118
|
+
|
104
119
|
|
105
120
|
Push:
|
106
121
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
122
|
+
gem push qwtf_discord_bot-$(cat VERSION).gem
|
123
|
+
|
124
|
+
|
125
|
+
## Docker
|
111
126
|
|
112
127
|
Run:
|
113
128
|
|
114
129
|
Assuming a `./config.yaml` file exists:
|
115
130
|
|
116
|
-
|
131
|
+
docker-compose up
|
117
132
|
|
118
|
-
```sh
|
119
|
-
docker run -it \
|
120
|
-
--env QWTF_DISCORD_BOT_CONFIG_FILE=config.yaml \
|
121
|
-
--mount type=bind,source="$(pwd)"/config.yaml,target=/discord-bot/config.yaml \
|
122
|
-
discord-bot server
|
123
|
-
```
|
124
133
|
|
125
|
-
|
134
|
+
Only discord-bot server:
|
135
|
+
|
136
|
+
docker run -it \
|
137
|
+
--env QWTF_DISCORD_BOT_CONFIG_FILE=config.yaml \
|
138
|
+
--mount type=bind,source="$(pwd)"/config.yaml,target=/discord-bot/config.yaml \
|
139
|
+
discord-bot server
|
140
|
+
|
141
|
+
|
142
|
+
Only discord-bot watcher:
|
143
|
+
|
144
|
+
docker run -it \
|
145
|
+
--env QWTF_DISCORD_BOT_CONFIG_FILE=config.yaml \
|
146
|
+
--mount type=bind,source="$(pwd)"/config.yaml,target=/discord-bot/config.yaml \
|
147
|
+
discord-bot watcher
|
148
|
+
|
149
|
+
|
150
|
+
Only discord-bot pug:
|
151
|
+
|
152
|
+
docker run -it \
|
153
|
+
--env QWTF_DISCORD_BOT_CONFIG_FILE=config.yaml \
|
154
|
+
--mount type=bind,source="$(pwd)"/config.yaml,target=/discord-bot/config.yaml \
|
155
|
+
discord-bot pug
|
126
156
|
|
127
|
-
```sh
|
128
|
-
docker run -it \
|
129
|
-
--env QWTF_DISCORD_BOT_CONFIG_FILE=config.yaml \
|
130
|
-
--mount type=bind,source="$(pwd)"/config.yaml,target=/discord-bot/config.yaml \
|
131
|
-
discord-bot watcher
|
132
|
-
```
|
133
157
|
|
134
|
-
|
158
|
+
Build:
|
159
|
+
|
160
|
+
docker build --tag=discord-bot .
|
161
|
+
|
162
|
+
|
163
|
+
Push:
|
135
164
|
|
136
|
-
|
137
|
-
docker-
|
165
|
+
docker tag discord-bot fortressone/discord-bot:latest
|
166
|
+
docker push fortressone/discord-bot:latest
|
167
|
+
|
168
|
+
|
169
|
+
Create AWS instance:
|
170
|
+
|
171
|
+
```
|
172
|
+
docker-machine create \
|
173
|
+
--driver amazonec2 \
|
174
|
+
--amazonec2-access-key <AWS_ACCESS_KEY> \
|
175
|
+
--amazonec2-secret-key <AWS_SECRET_KEY> \
|
176
|
+
--amazonec2-root-size 30 \
|
177
|
+
--amazonec2-region ap-southeast-2 \
|
178
|
+
discord-bot
|
138
179
|
```
|
139
180
|
|
140
181
|
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
5.0.1
|
data/docker-compose.yml
CHANGED
@@ -6,17 +6,17 @@ services:
|
|
6
6
|
restart: always
|
7
7
|
discord-command-bot:
|
8
8
|
image: fortressone/discord-bot:latest
|
9
|
-
command:
|
9
|
+
command: server
|
10
10
|
restart: always
|
11
11
|
depends_on:
|
12
12
|
- redis
|
13
13
|
volumes:
|
14
14
|
- type: bind
|
15
|
-
source: /home/ubuntu/.config/qwtf_discord_bot/config.yaml
|
15
|
+
source: "/home/ubuntu/.config/qwtf_discord_bot/config.yaml"
|
16
16
|
target: /discord-bot/config.yaml
|
17
17
|
discord-watcher-bot:
|
18
18
|
image: fortressone/discord-bot:latest
|
19
|
-
command:
|
19
|
+
command: watcher
|
20
20
|
restart: always
|
21
21
|
depends_on:
|
22
22
|
- redis
|
@@ -24,5 +24,17 @@ services:
|
|
24
24
|
- REDIS_URL=redis://redis
|
25
25
|
volumes:
|
26
26
|
- type: bind
|
27
|
-
source: /home/ubuntu/.config/qwtf_discord_bot/config.yaml
|
27
|
+
source: "/home/ubuntu/.config/qwtf_discord_bot/config.yaml"
|
28
|
+
target: /discord-bot/config.yaml
|
29
|
+
discord-pug-bot:
|
30
|
+
image: fortressone/discord-bot:latest
|
31
|
+
command: pug
|
32
|
+
restart: always
|
33
|
+
depends_on:
|
34
|
+
- redis
|
35
|
+
environment:
|
36
|
+
- REDIS_URL=redis://redis
|
37
|
+
volumes:
|
38
|
+
- type: bind
|
39
|
+
source: "/home/ubuntu/.config/qwtf_discord_bot/config.yaml"
|
28
40
|
target: /discord-bot/config.yaml
|
data/exe/qwtf_discord_bot
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'qwtf_discord_bot'
|
4
4
|
require 'thor'
|
5
|
+
require 'pry'
|
5
6
|
|
6
7
|
class QwtfDiscordBotExe < Thor
|
7
8
|
def self.exit_on_failure?
|
@@ -14,6 +15,12 @@ class QwtfDiscordBotExe < Thor
|
|
14
15
|
server_bot.run
|
15
16
|
end
|
16
17
|
|
18
|
+
desc 'pug', 'Start, join, leave, record pick-up games.'
|
19
|
+
def pug
|
20
|
+
pug_bot = QwtfDiscordBotPug.new
|
21
|
+
pug_bot.run
|
22
|
+
end
|
23
|
+
|
17
24
|
desc 'watcher', 'Watches servers and accounces when a player joins'
|
18
25
|
def watcher
|
19
26
|
watcher_bot = QwtfDiscordBotWatcher.new
|
@@ -0,0 +1,58 @@
|
|
1
|
+
class EventWrapper
|
2
|
+
include QwtfDiscordBot
|
3
|
+
|
4
|
+
DEFAULT_MAXPLAYERS = 8
|
5
|
+
|
6
|
+
def initialize(event)
|
7
|
+
@event = event
|
8
|
+
end
|
9
|
+
|
10
|
+
def user_id
|
11
|
+
@event.user.id
|
12
|
+
end
|
13
|
+
|
14
|
+
def username
|
15
|
+
@event.user.username
|
16
|
+
end
|
17
|
+
|
18
|
+
def maxplayers_key
|
19
|
+
[pug_key, "maxplayers"].join(":")
|
20
|
+
end
|
21
|
+
|
22
|
+
def maxplayers
|
23
|
+
redis.setnx(maxplayers_key, DEFAULT_MAXPLAYERS)
|
24
|
+
redis.get(maxplayers_key).to_i
|
25
|
+
end
|
26
|
+
|
27
|
+
def joined_player_count
|
28
|
+
redis.scard(players_key).to_i
|
29
|
+
end
|
30
|
+
|
31
|
+
def slots_left
|
32
|
+
maxplayers - joined_player_count
|
33
|
+
end
|
34
|
+
|
35
|
+
def pug_key
|
36
|
+
["pug", "channel", @event.channel.id].join(":")
|
37
|
+
end
|
38
|
+
|
39
|
+
def players_key
|
40
|
+
[pug_key, "players"].join(":")
|
41
|
+
end
|
42
|
+
|
43
|
+
def player_slots
|
44
|
+
"#{joined_player_count}/#{maxplayers}"
|
45
|
+
end
|
46
|
+
|
47
|
+
def users
|
48
|
+
@event.server.users
|
49
|
+
end
|
50
|
+
|
51
|
+
def role_key
|
52
|
+
[pug_key, "role"].join(":")
|
53
|
+
end
|
54
|
+
|
55
|
+
def role
|
56
|
+
redis.get(role_key) || "@here"
|
57
|
+
end
|
58
|
+
end
|
data/lib/qwtf_discord_bot.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
require 'qwtf_discord_bot/version'
|
2
2
|
require 'qwtf_discord_bot/qwtf_discord_bot_server'
|
3
|
+
require 'qwtf_discord_bot/qwtf_discord_bot_pug'
|
3
4
|
require 'qwtf_discord_bot/qwtf_discord_bot_watcher'
|
4
5
|
require 'qwtf_discord_bot/config'
|
5
6
|
require 'discordrb'
|
6
7
|
require 'yaml'
|
8
|
+
require 'redis'
|
7
9
|
|
8
10
|
require 'qstat_request'
|
9
11
|
require 'player'
|
@@ -12,9 +14,17 @@ require 'emoji'
|
|
12
14
|
require 'roster'
|
13
15
|
|
14
16
|
module QwtfDiscordBot # :nodoc:
|
15
|
-
CONFIG_FILE = ENV['QWTF_DISCORD_BOT_CONFIG_FILE'] || "#{Dir.pwd}/config.yaml"
|
16
|
-
|
17
17
|
def self.config
|
18
|
-
@config ||= Config.new(
|
18
|
+
@config ||= Config.new(config_file)
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.config_file
|
22
|
+
return ENV['QWTF_DISCORD_BOT_CONFIG_FILE'] if ENV['QWTF_DISCORD_BOT_CONFIG_FILE']
|
23
|
+
return "#{Dir.pwd}/config.yaml" if FileTest.exist?("#{Dir.pwd}/config.yaml")
|
24
|
+
"#{Dir.home}/.config/qwtf_discord_bot/config.yaml"
|
25
|
+
end
|
26
|
+
|
27
|
+
def redis
|
28
|
+
Redis.current
|
19
29
|
end
|
20
30
|
end
|
@@ -0,0 +1,138 @@
|
|
1
|
+
require 'event_wrapper'
|
2
|
+
|
3
|
+
class QwtfDiscordBotPug
|
4
|
+
include QwtfDiscordBot
|
5
|
+
|
6
|
+
FOUR_HOURS = 4 * 60 * 60
|
7
|
+
|
8
|
+
def run
|
9
|
+
bot = Discordrb::Commands::CommandBot.new(
|
10
|
+
token: QwtfDiscordBot.config.token,
|
11
|
+
client_id: QwtfDiscordBot.config.client_id,
|
12
|
+
prefix: '!'
|
13
|
+
)
|
14
|
+
|
15
|
+
bot.command :join do |event, *args|
|
16
|
+
e = EventWrapper.new(event)
|
17
|
+
|
18
|
+
redis.setnx(e.pug_key, Time.now)
|
19
|
+
redis.sadd(e.players_key, e.user_id)
|
20
|
+
|
21
|
+
message = if e.joined_player_count == e.maxplayers
|
22
|
+
mentions = joined_users(e).map do |user|
|
23
|
+
user.mention
|
24
|
+
end
|
25
|
+
"Time to play! #{mentions.join(" ")}"
|
26
|
+
elsif (e.joined_player_count == 1)
|
27
|
+
[
|
28
|
+
"#{e.username} creates a PUG",
|
29
|
+
e.player_slots,
|
30
|
+
e.role,
|
31
|
+
].join(" | ")
|
32
|
+
elsif e.slots_left <= 3
|
33
|
+
[
|
34
|
+
"#{e.username} joins the PUG",
|
35
|
+
e.player_slots,
|
36
|
+
"#{e.slots_left} more",
|
37
|
+
e.role,
|
38
|
+
].join(" | ")
|
39
|
+
else
|
40
|
+
[
|
41
|
+
"#{e.username} joins the PUG",
|
42
|
+
e.player_slots,
|
43
|
+
].join(" | ")
|
44
|
+
end
|
45
|
+
|
46
|
+
send_and_log_message(message, event)
|
47
|
+
end
|
48
|
+
|
49
|
+
bot.command :status do |event, *args|
|
50
|
+
e = EventWrapper.new(event)
|
51
|
+
usernames = joined_users(e).map(&:username)
|
52
|
+
|
53
|
+
message = [
|
54
|
+
"#{usernames.join(", ")} joined",
|
55
|
+
e.player_slots
|
56
|
+
].join(" | ")
|
57
|
+
|
58
|
+
send_and_log_message(message, event)
|
59
|
+
end
|
60
|
+
|
61
|
+
bot.command :maxplayers do |event, *args|
|
62
|
+
e = EventWrapper.new(event)
|
63
|
+
new_maxplayers = args[0]
|
64
|
+
|
65
|
+
message = if new_maxplayers
|
66
|
+
redis.set(e.maxplayers_key, new_maxplayers)
|
67
|
+
"Max number of players set to #{e.maxplayers} | #{e.player_slots}"
|
68
|
+
else
|
69
|
+
"Current max number of players is #{e.maxplayers} | #{e.player_slots}"
|
70
|
+
end
|
71
|
+
|
72
|
+
send_and_log_message(message, event)
|
73
|
+
|
74
|
+
if e.joined_player_count >= e.maxplayers
|
75
|
+
mentions = joined_users(e).map do |user|
|
76
|
+
user.mention
|
77
|
+
end
|
78
|
+
|
79
|
+
message = "Time to play! #{mentions.join(" ")}"
|
80
|
+
send_and_log_message(message, event)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
bot.command :leave do |event, *args|
|
85
|
+
e = EventWrapper.new(event)
|
86
|
+
|
87
|
+
redis.srem(e.players_key, e.user_id)
|
88
|
+
|
89
|
+
message = "#{e.username} leaves the PUG | #{e.player_slots}"
|
90
|
+
|
91
|
+
send_and_log_message(message, event)
|
92
|
+
|
93
|
+
if e.joined_player_count == 0
|
94
|
+
redis.del(e.pug_key)
|
95
|
+
|
96
|
+
message = "PUG ended"
|
97
|
+
send_and_log_message(message, event)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
bot.command :end do |event, *args|
|
102
|
+
e = EventWrapper.new(event)
|
103
|
+
|
104
|
+
redis.del(e.pug_key)
|
105
|
+
redis.del(e.players_key)
|
106
|
+
|
107
|
+
message = "PUG ended"
|
108
|
+
send_and_log_message(message, event)
|
109
|
+
end
|
110
|
+
|
111
|
+
bot.command :role do |event, *args|
|
112
|
+
e = EventWrapper.new(event)
|
113
|
+
role = args[0]
|
114
|
+
|
115
|
+
redis.set(e.role_key, role)
|
116
|
+
|
117
|
+
message = "Notification role set to #{role}"
|
118
|
+
send_and_log_message(message, event)
|
119
|
+
end
|
120
|
+
|
121
|
+
bot.run
|
122
|
+
end
|
123
|
+
|
124
|
+
private
|
125
|
+
|
126
|
+
def send_and_log_message(message, event)
|
127
|
+
event.channel.send_message(message)
|
128
|
+
puts message
|
129
|
+
end
|
130
|
+
|
131
|
+
def joined_users(event)
|
132
|
+
redis.smembers(event.players_key).map do |user_id|
|
133
|
+
event.users.find do |user|
|
134
|
+
user.id.to_s == user_id
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
@@ -8,10 +8,10 @@ class QwtfDiscordBotServer
|
|
8
8
|
|
9
9
|
bot.command :server do |event, *args|
|
10
10
|
if args.empty?
|
11
|
-
|
12
|
-
'
|
13
|
-
|
14
|
-
|
11
|
+
message = 'Provide a server address e.g. `!server ' \
|
12
|
+
'sydney.fortressone.org` or use `!active` or `!all`'
|
13
|
+
event.channel.send_message(message)
|
14
|
+
puts message
|
15
15
|
else
|
16
16
|
endpoint = args.first
|
17
17
|
qstat_response = QstatRequest.new(endpoint)
|
@@ -20,10 +20,13 @@ class QwtfDiscordBotServer
|
|
20
20
|
|
21
21
|
if embed
|
22
22
|
event.channel.send_embed(message, embed)
|
23
|
+
puts message
|
23
24
|
else
|
24
25
|
event.channel.send_message(message)
|
26
|
+
puts message
|
25
27
|
end
|
26
28
|
end
|
29
|
+
|
27
30
|
end
|
28
31
|
|
29
32
|
bot.command :all do |event|
|
@@ -34,9 +37,9 @@ class QwtfDiscordBotServer
|
|
34
37
|
end
|
35
38
|
|
36
39
|
if endpoints_for_this_channel.empty?
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
+
message = 'There are no servers associated with this channel'
|
41
|
+
event.channel.send_message(message)
|
42
|
+
puts message
|
40
43
|
else
|
41
44
|
endpoints_for_this_channel.each do |endpoint|
|
42
45
|
qstat_request = QstatRequest.new(endpoint.address)
|
@@ -45,8 +48,10 @@ class QwtfDiscordBotServer
|
|
45
48
|
|
46
49
|
if embed
|
47
50
|
event.channel.send_embed(message, embed)
|
51
|
+
puts message
|
48
52
|
else
|
49
53
|
event.channel.send_message(message)
|
54
|
+
puts message
|
50
55
|
end
|
51
56
|
end
|
52
57
|
end
|
@@ -62,9 +67,9 @@ class QwtfDiscordBotServer
|
|
62
67
|
end
|
63
68
|
|
64
69
|
if endpoints_for_this_channel.empty?
|
65
|
-
|
66
|
-
|
67
|
-
|
70
|
+
message = 'There are no servers associated with this channel'
|
71
|
+
event.channel.send_message(message)
|
72
|
+
puts message
|
68
73
|
else
|
69
74
|
qstat_requests = endpoints_for_this_channel.map do |endpoint|
|
70
75
|
QstatRequest.new(endpoint.address)
|
@@ -75,7 +80,9 @@ class QwtfDiscordBotServer
|
|
75
80
|
end
|
76
81
|
|
77
82
|
if servers_with_players.empty?
|
78
|
-
|
83
|
+
message = "All ##{event.channel.name} servers are empty"
|
84
|
+
event.channel.send_message(message)
|
85
|
+
puts message
|
79
86
|
else
|
80
87
|
servers_with_players.each do |server|
|
81
88
|
message = server.server_summary
|
@@ -83,13 +90,14 @@ class QwtfDiscordBotServer
|
|
83
90
|
|
84
91
|
if embed
|
85
92
|
event.channel.send_embed(message, embed)
|
93
|
+
puts message
|
86
94
|
else
|
87
95
|
event.channel.send_message(message)
|
96
|
+
puts message
|
88
97
|
end
|
89
98
|
end
|
90
99
|
end
|
91
100
|
end
|
92
|
-
|
93
101
|
return nil
|
94
102
|
end
|
95
103
|
|
@@ -1,5 +1,3 @@
|
|
1
|
-
require "redis"
|
2
|
-
|
3
1
|
class QwtfDiscordBotWatcher
|
4
2
|
include QwtfDiscordBot
|
5
3
|
|
@@ -14,7 +12,7 @@ class QwtfDiscordBotWatcher
|
|
14
12
|
next if request.is_empty?
|
15
13
|
|
16
14
|
request.player_names.each do |name|
|
17
|
-
redis_key = "
|
15
|
+
redis_key = ["watcher", address, name].join(":")
|
18
16
|
|
19
17
|
unless seen_recently?(redis_key)
|
20
18
|
endpoint.channel_ids.each do |channel_id|
|
@@ -51,16 +49,14 @@ class QwtfDiscordBotWatcher
|
|
51
49
|
end
|
52
50
|
|
53
51
|
def report_joined(name:, channel_id:, server_summary:)
|
52
|
+
message = "#{name} joins #{server_summary}"
|
53
|
+
|
54
54
|
Discordrb::API::Channel.create_message(
|
55
55
|
"Bot #{QwtfDiscordBot.config.token}",
|
56
56
|
channel_id,
|
57
|
-
|
57
|
+
message
|
58
58
|
)
|
59
|
-
end
|
60
|
-
|
61
|
-
private
|
62
59
|
|
63
|
-
|
64
|
-
@redis ||= Redis.new
|
60
|
+
puts message
|
65
61
|
end
|
66
62
|
end
|
data/qwtf_discord_bot.gemspec
CHANGED
@@ -28,6 +28,6 @@ Gem::Specification.new do |spec|
|
|
28
28
|
spec.require_paths = ['lib']
|
29
29
|
|
30
30
|
spec.add_runtime_dependency 'discordrb', '~> 3.3'
|
31
|
+
spec.add_runtime_dependency 'redis', '~> 4.1'
|
31
32
|
spec.add_runtime_dependency 'thor', '~> 0.20'
|
32
|
-
spec.add_runtime_dependency 'redis'
|
33
33
|
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: 5.0.1
|
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
|
+
date: 2020-08-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: discordrb
|
@@ -25,33 +25,33 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '3.3'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: redis
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '4.1'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '4.1'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: thor
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
47
|
+
version: '0.20'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
54
|
+
version: '0.20'
|
55
55
|
description: A Discord bot for reporting on QuakeWorld Team Fortress game servers
|
56
56
|
email:
|
57
57
|
- shayolden@hotmail.com
|
@@ -60,6 +60,7 @@ executables:
|
|
60
60
|
extensions: []
|
61
61
|
extra_rdoc_files: []
|
62
62
|
files:
|
63
|
+
- ".dockerignore"
|
63
64
|
- ".gitignore"
|
64
65
|
- ".rspec"
|
65
66
|
- ".travis.yml"
|
@@ -69,6 +70,7 @@ files:
|
|
69
70
|
- LICENSE.txt
|
70
71
|
- README.md
|
71
72
|
- Rakefile
|
73
|
+
- VERSION
|
72
74
|
- bin/bundle
|
73
75
|
- bin/coderay
|
74
76
|
- bin/console
|
@@ -102,10 +104,12 @@ files:
|
|
102
104
|
- exe/qwtf_discord_bot
|
103
105
|
- lib/emoji.rb
|
104
106
|
- lib/endpoint.rb
|
107
|
+
- lib/event_wrapper.rb
|
105
108
|
- lib/player.rb
|
106
109
|
- lib/qstat_request.rb
|
107
110
|
- lib/qwtf_discord_bot.rb
|
108
111
|
- lib/qwtf_discord_bot/config.rb
|
112
|
+
- lib/qwtf_discord_bot/qwtf_discord_bot_pug.rb
|
109
113
|
- lib/qwtf_discord_bot/qwtf_discord_bot_server.rb
|
110
114
|
- lib/qwtf_discord_bot/qwtf_discord_bot_watcher.rb
|
111
115
|
- lib/qwtf_discord_bot/version.rb
|
@@ -133,8 +137,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
133
137
|
- !ruby/object:Gem::Version
|
134
138
|
version: '0'
|
135
139
|
requirements: []
|
136
|
-
|
137
|
-
rubygems_version: 2.7.6.2
|
140
|
+
rubygems_version: 3.1.2
|
138
141
|
signing_key:
|
139
142
|
specification_version: 4
|
140
143
|
summary: Works by wrapping the excellent CLI server query tool qstat. Accepts !server,
|