qwtf_discord_bot 0.2.2 → 0.3.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 +17 -10
- data/README.md +11 -19
- data/exe/qwtf_discord_bot +20 -2
- data/lib/player.rb +45 -45
- data/lib/qstat_request.rb +27 -27
- data/lib/qwtf_discord_bot.rb +68 -9
- data/lib/qwtf_discord_bot/cli.rb +22 -10
- data/lib/qwtf_discord_bot/version.rb +2 -2
- data/qwtf_discord_bot.gemspec +10 -3
- data/screenshot.png +0 -0
- metadata +21 -6
- data/qwtf_discord_bot-0.2.0.gem +0 -0
- data/qwtf_discord_bot-0.2.1.gem +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: af5a91eea63cee06b63358f91be5473c89aaac89dbbd8bbb06141b7ba3b0d7dd
|
4
|
+
data.tar.gz: '0815fbb7ba17b9232561f9fa10581c883fcf9ac8f41a4427949ecd32e4f3bebb'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 235a0377e67ea4d2289f4dee19d08c7f7ee58b43c4218653c461dc4f859c17d803498ed30c7daa13bce64c35468905697d31b7f15260a5afa169ff654f40767d
|
7
|
+
data.tar.gz: f9378c160a7acebab7f648349e17021cbb8a31975a3e4cd713fe13fea9dd912d4471e6c119801d1ffe44ffa49e13b9b643e7a1419ece9b02ecd89eea843bd067
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,13 +1,19 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
qwtf_discord_bot (0.2.
|
4
|
+
qwtf_discord_bot (0.2.2)
|
5
|
+
activesupport
|
5
6
|
discordrb
|
6
7
|
|
7
8
|
GEM
|
8
9
|
remote: https://rubygems.org/
|
9
10
|
specs:
|
10
|
-
|
11
|
+
activesupport (5.2.0)
|
12
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
13
|
+
i18n (>= 0.7, < 2)
|
14
|
+
minitest (~> 5.1)
|
15
|
+
tzinfo (~> 1.1)
|
16
|
+
concurrent-ruby (1.0.5)
|
11
17
|
diff-lcs (1.3)
|
12
18
|
discordrb (3.2.1)
|
13
19
|
discordrb-webhooks (~> 3.2.0.1)
|
@@ -17,22 +23,21 @@ GEM
|
|
17
23
|
websocket-client-simple (>= 0.3.0)
|
18
24
|
discordrb-webhooks (3.2.0.1)
|
19
25
|
rest-client
|
20
|
-
domain_name (0.5.
|
26
|
+
domain_name (0.5.20180417)
|
21
27
|
unf (>= 0.0.5, < 1.0.0)
|
22
28
|
event_emitter (0.2.6)
|
23
29
|
ffi (1.9.25)
|
24
30
|
http-cookie (1.0.3)
|
25
31
|
domain_name (~> 0.5)
|
26
|
-
|
32
|
+
i18n (1.0.1)
|
33
|
+
concurrent-ruby (~> 1.0)
|
27
34
|
mime-types (3.1)
|
28
35
|
mime-types-data (~> 3.2015)
|
29
36
|
mime-types-data (3.2016.0521)
|
37
|
+
minitest (5.11.3)
|
30
38
|
netrc (0.11.0)
|
31
39
|
opus-ruby (1.0.1)
|
32
40
|
ffi
|
33
|
-
pry (0.11.3)
|
34
|
-
coderay (~> 1.1.0)
|
35
|
-
method_source (~> 0.9.0)
|
36
41
|
rake (10.5.0)
|
37
42
|
rbnacl (3.4.0)
|
38
43
|
ffi
|
@@ -54,10 +59,13 @@ GEM
|
|
54
59
|
rspec-support (~> 3.7.0)
|
55
60
|
rspec-support (3.7.1)
|
56
61
|
thor (0.20.0)
|
62
|
+
thread_safe (0.3.6)
|
63
|
+
tzinfo (1.2.5)
|
64
|
+
thread_safe (~> 0.1)
|
57
65
|
unf (0.1.4)
|
58
66
|
unf_ext
|
59
67
|
unf_ext (0.0.7.5)
|
60
|
-
websocket (1.2.
|
68
|
+
websocket (1.2.8)
|
61
69
|
websocket-client-simple (0.3.0)
|
62
70
|
event_emitter
|
63
71
|
websocket
|
@@ -67,11 +75,10 @@ PLATFORMS
|
|
67
75
|
|
68
76
|
DEPENDENCIES
|
69
77
|
bundler (~> 1.16)
|
70
|
-
pry
|
71
78
|
qwtf_discord_bot!
|
72
79
|
rake (~> 10.0)
|
73
80
|
rspec (~> 3.0)
|
74
|
-
thor
|
81
|
+
thor (~> 0)
|
75
82
|
|
76
83
|
BUNDLED WITH
|
77
84
|
1.16.2
|
data/README.md
CHANGED
@@ -1,38 +1,30 @@
|
|
1
1
|
# QwtfDiscordBot
|
2
2
|
|
3
|
-
|
3
|
+
A Discord bot for checking the status of QuakeWorld Team Fortress servers
|
4
4
|
|
5
|
-
|
5
|
+

|
6
6
|
|
7
|
-
## Installation
|
8
|
-
|
9
|
-
Add this line to your application's Gemfile:
|
10
7
|
|
11
|
-
|
12
|
-
gem 'qwtf_discord_bot'
|
13
|
-
```
|
8
|
+
## Dependencies
|
14
9
|
|
15
|
-
|
10
|
+
- Ruby >= 2.5.0
|
11
|
+
- [qstat](https://github.com/multiplay/qstat) version with JSON support. Tested with commit [2ab78bd5c30fbd47b2bdd4a6279296d66424b37e](https://github.com/multiplay/qstat/tree/2ab78bd5c30fbd47b2bdd4a6279296d66424b37e). Should be added to `$PATH`.
|
16
12
|
|
17
|
-
$ bundle
|
18
13
|
|
19
|
-
|
14
|
+
## Installation
|
20
15
|
|
21
16
|
$ gem install qwtf_discord_bot
|
22
17
|
|
23
|
-
## Usage
|
24
|
-
|
25
|
-
$ bundle exec exe\qwtf-discord-bot server
|
26
18
|
|
27
|
-
##
|
19
|
+
## Usage
|
28
20
|
|
29
|
-
|
21
|
+
Create a bot on discord.
|
30
22
|
|
31
|
-
|
23
|
+
Edit the `.env.example` file, update with your bot's `client_id` and `token` and save as `.env`. Then:
|
32
24
|
|
33
|
-
|
25
|
+
$ source .env
|
26
|
+
$ bundle exec exe\qwtf-discord-bot server
|
34
27
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/qwtf_discord_bot.
|
36
28
|
|
37
29
|
## License
|
38
30
|
|
data/exe/qwtf_discord_bot
CHANGED
@@ -1,6 +1,24 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
require 'qwtf_discord_bot'
|
4
|
-
require
|
4
|
+
require "thor"
|
5
5
|
|
6
|
-
|
6
|
+
class QwtfDiscordBotExe < Thor
|
7
|
+
def self.exit_on_failure?
|
8
|
+
true
|
9
|
+
end
|
10
|
+
|
11
|
+
desc "server", "Runs the qwtf-discord-bot server"
|
12
|
+
def server
|
13
|
+
server_bot = QwtfDiscordBot::Server.new
|
14
|
+
server_bot.run
|
15
|
+
end
|
16
|
+
|
17
|
+
desc "watcher", "Runs the qwtf-discord-bot watcher"
|
18
|
+
def watcher
|
19
|
+
watcher_bot = QwtfDiscordBot::Watcher.new
|
20
|
+
watcher_bot.run
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
QwtfDiscordBotExe.start
|
data/lib/player.rb
CHANGED
@@ -1,47 +1,47 @@
|
|
1
1
|
class Player
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
2
|
+
PLAYER_CLASSES = {
|
3
|
+
"sco" => "scout",
|
4
|
+
"sni" => "sniper",
|
5
|
+
"sol" => "soldier",
|
6
|
+
"dem" => "demoman",
|
7
|
+
"med" => "medic",
|
8
|
+
"pyr" => "pyro",
|
9
|
+
"hwg" => "hwguy",
|
10
|
+
"spy" => "spy",
|
11
|
+
"eng" => "engineer"
|
12
|
+
}
|
13
|
+
|
14
|
+
def initialize(data)
|
15
|
+
@data = data
|
16
|
+
end
|
17
|
+
|
18
|
+
def name
|
19
|
+
@data["name"]
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_row
|
23
|
+
"#{emoji}#{name}"
|
24
|
+
end
|
25
|
+
|
26
|
+
def team
|
27
|
+
@team ||= Team.new(@data["team"].to_sym)
|
28
|
+
end
|
29
|
+
|
30
|
+
def player_class
|
31
|
+
PLAYER_CLASSES[short_class]
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def emoji
|
37
|
+
Emoji.new(self).to_s
|
38
|
+
end
|
39
|
+
|
40
|
+
def short_class
|
41
|
+
skin.split("_").last
|
42
|
+
end
|
43
|
+
|
44
|
+
def skin
|
45
|
+
@data["skin"]
|
46
|
+
end
|
47
47
|
end
|
data/lib/qstat_request.rb
CHANGED
@@ -1,38 +1,38 @@
|
|
1
1
|
class QstatRequest
|
2
|
-
|
3
|
-
|
4
|
-
|
2
|
+
def initialize(hostname)
|
3
|
+
@result = JSON.parse(%x[qstat -json -P -qws #{hostname}]).first
|
4
|
+
end
|
5
5
|
|
6
|
-
|
7
|
-
|
6
|
+
def output
|
7
|
+
<<~HEREDOC
|
8
8
|
**#{address} | #{map} | #{numplayers}/#{maxplayers}**
|
9
9
|
#{player_table}
|
10
|
-
|
11
|
-
|
10
|
+
HEREDOC
|
11
|
+
end
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
def address
|
14
|
+
@result["address"]
|
15
|
+
end
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
def map
|
18
|
+
@result["map"]
|
19
|
+
end
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
21
|
+
def numplayers
|
22
|
+
@result["numplayers"]
|
23
|
+
end
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
def maxplayers
|
26
|
+
@result["maxplayers"]
|
27
|
+
end
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
|
29
|
+
def player_table
|
30
|
+
players.sort_by { |player| player.team.number }.map(&:to_row).join("\n")
|
31
|
+
end
|
32
32
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
33
|
+
def players
|
34
|
+
@result["players"].map do |player_data|
|
35
|
+
Player.new(player_data)
|
36
|
+
end
|
37
|
+
end
|
38
38
|
end
|
data/lib/qwtf_discord_bot.rb
CHANGED
@@ -1,23 +1,82 @@
|
|
1
1
|
require "qwtf_discord_bot/version"
|
2
2
|
require "discordrb"
|
3
|
+
require 'active_support/core_ext/string'
|
3
4
|
|
4
5
|
require "qstat_request"
|
5
6
|
require "player"
|
6
7
|
require "team"
|
7
8
|
require "emoji"
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
CLIENT_ID = ENV["DISCORD_CLIENT_ID"].strip
|
10
|
+
class QwtfDiscordBot
|
11
|
+
TOKEN = ENV["QWTF_DISCORD_BOT_TOKEN"].strip
|
12
|
+
CLIENT_ID = ENV["QWTF_DISCORD_BOT_CLIENT_ID"].strip
|
13
|
+
CHANNEL_ID = ENV["QWTF_DISCORD_BOT_CHANNEL_ID"].strip
|
14
14
|
HOSTNAME = "fortressone.ga"
|
15
15
|
|
16
|
-
|
16
|
+
class Server
|
17
|
+
def initialize
|
18
|
+
@bot ||= Discordrb::Commands::CommandBot.new(
|
19
|
+
token: TOKEN,
|
20
|
+
client_id: CLIENT_ID,
|
21
|
+
prefix: "!"
|
22
|
+
)
|
23
|
+
|
24
|
+
@bot.command :server do |event|
|
25
|
+
QstatRequest.new(HOSTNAME).output
|
26
|
+
end
|
27
|
+
end
|
17
28
|
|
18
|
-
|
19
|
-
|
29
|
+
def run
|
30
|
+
@bot.run
|
31
|
+
end
|
20
32
|
end
|
21
33
|
|
22
|
-
|
34
|
+
class Watcher
|
35
|
+
THIRTY_SECONDS = 30
|
36
|
+
TEN_MINUTES = 10 * 60
|
37
|
+
|
38
|
+
def initialize
|
39
|
+
@history = {}
|
40
|
+
end
|
41
|
+
|
42
|
+
def run
|
43
|
+
every(THIRTY_SECONDS) do
|
44
|
+
request = QstatRequest.new(HOSTNAME)
|
45
|
+
player_names = request.players.map(&:name)
|
46
|
+
numplayers = request.numplayers
|
47
|
+
|
48
|
+
player_names.each do |name|
|
49
|
+
report_joined(name, numplayers) unless seen_recently?(name)
|
50
|
+
@history[name] = Time.now
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def report_joined(name, numplayers)
|
58
|
+
number_of_other_players = numplayers - 1
|
59
|
+
|
60
|
+
Discordrb::API::Channel.create_message(
|
61
|
+
"Bot #{TOKEN}",
|
62
|
+
CHANNEL_ID,
|
63
|
+
"**#{name}** has joined **#{number_of_other_players}** " \
|
64
|
+
"#{"other player".pluralize(number_of_other_players)} on **#{HOSTNAME}**"
|
65
|
+
)
|
66
|
+
end
|
67
|
+
|
68
|
+
def seen_recently?(name)
|
69
|
+
last_seen = @history[name]
|
70
|
+
last_seen && (Time.now - last_seen < TEN_MINUTES)
|
71
|
+
end
|
72
|
+
|
73
|
+
def every(n)
|
74
|
+
loop do
|
75
|
+
before = Time.now
|
76
|
+
yield
|
77
|
+
interval = n-(Time.now-before)
|
78
|
+
sleep(interval) if interval > 0
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
23
82
|
end
|
data/lib/qwtf_discord_bot/cli.rb
CHANGED
@@ -1,10 +1,22 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'qwtf_discord_bot'
|
4
|
+
require "thor"
|
5
|
+
|
6
|
+
class QwtfDiscordBot < Thor
|
7
|
+
def self.exit_on_failure?
|
8
|
+
true
|
9
|
+
end
|
10
|
+
|
11
|
+
desc "server", "Runs the qwtf-discord-bot server"
|
12
|
+
def server
|
13
|
+
QwtfDiscordBot::Server.run
|
14
|
+
end
|
15
|
+
|
16
|
+
desc "watcher", "Runs the qwtf-discord-bot watcher"
|
17
|
+
def watcher
|
18
|
+
QwtfDiscordBot::Watcher.run
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
QwtfDiscordBot.start
|
@@ -1,3 +1,3 @@
|
|
1
|
-
|
2
|
-
VERSION = "0.
|
1
|
+
class QwtfDiscordBot
|
2
|
+
VERSION = "0.3.0"
|
3
3
|
end
|
data/qwtf_discord_bot.gemspec
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
|
2
1
|
lib = File.expand_path("../lib", __FILE__)
|
3
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
3
|
require "qwtf_discord_bot/version"
|
@@ -9,19 +8,27 @@ Gem::Specification.new do |spec|
|
|
9
8
|
spec.authors = ["Sheldon Johnson"]
|
10
9
|
spec.email = ["shayolden@hotmail.com"]
|
11
10
|
|
12
|
-
spec.description =
|
13
|
-
|
11
|
+
spec.description = "A Discord bot for reporting on QuakeWorld Team " \
|
12
|
+
"Fortress game servers"
|
13
|
+
|
14
|
+
spec.summary = "Works by wrapping the excellent CLI server query tool" \
|
15
|
+
"qstat. Accepts the !server command from users and " \
|
16
|
+
"also periodically checks for new players on the " \
|
17
|
+
"server and reports about them."
|
18
|
+
|
14
19
|
spec.homepage = "https://github.com/drzel/qwtf_discord_bot.git"
|
15
20
|
spec.license = "MIT"
|
16
21
|
|
17
22
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
23
|
f.match(%r{^(test|spec|features)/})
|
19
24
|
end
|
25
|
+
|
20
26
|
spec.bindir = "exe"
|
21
27
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
28
|
spec.require_paths = ["lib"]
|
23
29
|
|
24
30
|
spec.add_dependency "discordrb"
|
31
|
+
spec.add_dependency "activesupport"
|
25
32
|
|
26
33
|
spec.add_development_dependency "thor", '~> 0'
|
27
34
|
spec.add_development_dependency "bundler", "~> 1.16"
|
data/screenshot.png
ADDED
Binary file
|
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: 0.
|
4
|
+
version: 0.3.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: 2018-08-
|
11
|
+
date: 2018-08-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: discordrb
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: thor
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -80,7 +94,7 @@ dependencies:
|
|
80
94
|
- - "~>"
|
81
95
|
- !ruby/object:Gem::Version
|
82
96
|
version: '3.0'
|
83
|
-
description: A
|
97
|
+
description: A Discord bot for reporting on QuakeWorld Team Fortress game servers
|
84
98
|
email:
|
85
99
|
- shayolden@hotmail.com
|
86
100
|
executables:
|
@@ -106,9 +120,8 @@ files:
|
|
106
120
|
- lib/qwtf_discord_bot/cli.rb
|
107
121
|
- lib/qwtf_discord_bot/version.rb
|
108
122
|
- lib/team.rb
|
109
|
-
- qwtf_discord_bot-0.2.0.gem
|
110
|
-
- qwtf_discord_bot-0.2.1.gem
|
111
123
|
- qwtf_discord_bot.gemspec
|
124
|
+
- screenshot.png
|
112
125
|
homepage: https://github.com/drzel/qwtf_discord_bot.git
|
113
126
|
licenses:
|
114
127
|
- MIT
|
@@ -132,5 +145,7 @@ rubyforge_project:
|
|
132
145
|
rubygems_version: 2.7.3
|
133
146
|
signing_key:
|
134
147
|
specification_version: 4
|
135
|
-
summary:
|
148
|
+
summary: Works by wrapping the excellent CLI server query toolqstat. Accepts the !server
|
149
|
+
command from users and also periodically checks for new players on the server and
|
150
|
+
reports about them.
|
136
151
|
test_files: []
|
data/qwtf_discord_bot-0.2.0.gem
DELETED
Binary file
|
data/qwtf_discord_bot-0.2.1.gem
DELETED
Binary file
|