qwtf_discord_bot 4.0.3 → 4.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6f51528b3135169de08585ed80d5de3a0c72b29ace36dc27696eccd72cdf7971
4
- data.tar.gz: 1d43f1c94aa6cbc50ad8071fad509d92b131d308dd0555122535700414364554
3
+ metadata.gz: a70ca5bf16d72a2a0ccfc6127011016b1c1e18c3a4212d202dcf5a071b69e194
4
+ data.tar.gz: 055defe76720adc62871dd2c43d342a1161f6698a429c8b6f4ebdd47e9dfc42e
5
5
  SHA512:
6
- metadata.gz: 498504896c72c0285f2a72d6a9a4e9e3bcf2fe7779ded8d10b8a368aa0c418e4a142f8e13b68f4a566e88ca729da5fdba89871808d70398ef609fe1632db0a86
7
- data.tar.gz: f79cdd367a7759560193a506a893cb1641e8bed9d466e03e12ed1e84d842e031e0c108f073982304b1ababdaec1b72add8d77e8bf2c397a0f518607a43834026
6
+ metadata.gz: 754aedabdd94d65c98a224201aff9794cffcd68fb2ad4f8f22346475a09e68e371ee957c338bbbf6a775af744ce73d1fd0b7cd7bcf06e46178dcde3a3c6b8e9c
7
+ data.tar.gz: a414d546bdf7523df42ce3bd3d7a184050a2c2d80143743d23aed52f17298d54acad363d1791a63818df5d696879ad8ec2c691dec0ee400a07d58156ffbe81b7
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- qwtf_discord_bot (4.0.3)
4
+ qwtf_discord_bot (4.1.0)
5
5
  discordrb (~> 3.3)
6
6
  thor (~> 0.20)
7
7
 
data/README.md CHANGED
@@ -16,8 +16,9 @@ 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
- - Create a `config.yaml` file containing your bots credentials and server endpoints. E.G.
19
+ - Create a bot on discord
20
+ - Create a `~/.config/qwtf_discord_bot/config.yaml` file containing your bots
21
+ credentials and server endpoints
21
22
 
22
23
  ```yaml
23
24
  ---
@@ -34,17 +35,37 @@ endpoints:
34
35
  - "dallas.fortressone.org":
35
36
  - channel_ids:
36
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>"
37
59
  ```
38
60
 
39
- - Set the `QWTF_DISCORD_BOT_CONFIG_FILE` environment variable or default to
40
- `config.yaml` in the present working directory
61
+ - Use the `QWTF_DISCORD_BOT_CONFIG_FILE` environment variable or default to
62
+ specify an alternative file
41
63
 
42
64
  ```sh
43
65
  $ export QWTF_DISCORD_BOT_CONFIG_FILE="config.yaml"
44
66
  ```
45
67
 
46
68
 
47
-
48
69
  ### Commands
49
70
 
50
71
  There are two modules:
@@ -95,13 +116,19 @@ Assuming a `./config.yaml` file exists:
95
116
  Server:
96
117
 
97
118
  ```sh
98
- docker run -it --mount type=bind,source="$(pwd)"/config.yaml,target=/discord-bot/config.yaml discord-bot server
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
99
123
  ```
100
124
 
101
125
  Watcher:
102
126
 
103
127
  ```sh
104
- docker run -it --mount type=bind,source="$(pwd)"/config.yaml,target=/discord-bot/config.yaml discord-bot watcher
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
105
132
  ```
106
133
 
107
134
  Both:
@@ -7,7 +7,7 @@ services:
7
7
  restart: always
8
8
  volumes:
9
9
  - type: bind
10
- source: ./config.yaml
10
+ source: /home/ubuntu/.config/qwtf_discord_bot/config.yaml
11
11
  target: /discord-bot/config.yaml
12
12
  discord-watcher-bot:
13
13
  image: fortressone/discord-bot:latest
@@ -15,5 +15,5 @@ services:
15
15
  restart: always
16
16
  volumes:
17
17
  - type: bind
18
- source: ./config.yaml
18
+ source: /home/ubuntu/.config/qwtf_discord_bot/config.yaml
19
19
  target: /discord-bot/config.yaml
@@ -1,30 +1,6 @@
1
1
  class Emoji
2
- LOOKUP = {
3
- 'red' => {
4
- 'scout' => '<:scout_red:424097703127941130>',
5
- 'sniper' => '<:sniper_red:424097704076115978>',
6
- 'soldier' => '<:soldier_red:424097704197619712>',
7
- 'demoman' => '<:demoman_red:424097687739301919>',
8
- 'medic' => '<:medic_red:424097695418941451>',
9
- 'pyro' => '<:pyro_red:424097704403271691>',
10
- 'hwguy' => '<:hwguy_red:424097694030757889>',
11
- 'spy' => '<:spy_red:424097704138899466>',
12
- 'engineer' => '<:engineer_red:424097694680612864>'
13
- },
14
- 'blue' => {
15
- 'scout' => '<:scout_blue:456062063983460353>',
16
- 'sniper' => '<:sniper_blue:456062061953417216>',
17
- 'soldier' => '<:soldier_blue:456062062997536801>',
18
- 'demoman' => '<:demoman_blue:456061938636554240>',
19
- 'medic' => '<:medic_blue:456062056710537217>',
20
- 'pyro' => '<:pyro_blue:456062062460928010>',
21
- 'hwguy' => '<:hwguy_blue:456062063190736926>',
22
- 'spy' => '<:spy_blue:456062062032846849>',
23
- 'engineer' => '<:engineer_blue:456062031125020683>'
24
- }
25
- }.freeze
26
-
27
2
  def self.for(team:, player_class:)
28
- LOOKUP[team] && LOOKUP[team][player_class]
3
+ emojis = QwtfDiscordBot.config.emojis
4
+ emojis[team] && emojis[team][player_class]
29
5
  end
30
6
  end
@@ -1,23 +1,3 @@
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
1
  class Endpoint
22
2
  def initialize(config)
23
3
  @config = config
@@ -1,23 +1,20 @@
1
1
  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
+ require 'qwtf_discord_bot/config'
4
5
  require 'discordrb'
5
6
  require 'yaml'
6
7
 
7
- require 'config'
8
8
  require 'qstat_request'
9
9
  require 'player'
10
10
  require 'team'
11
11
  require 'emoji'
12
12
  require 'roster'
13
13
 
14
- class QwtfDiscordBot # :nodoc:
14
+ module QwtfDiscordBot # :nodoc:
15
15
  CONFIG_FILE = ENV['QWTF_DISCORD_BOT_CONFIG_FILE'] || "#{Dir.pwd}/config.yaml"
16
16
 
17
- def initialize
18
- @config = Config.new(CONFIG_FILE)
19
- @token = @config.token
20
- @client_id = @config.client_id
21
- @endpoints = @config.endpoints
17
+ def self.config
18
+ @config ||= Config.new(CONFIG_FILE)
22
19
  end
23
20
  end
@@ -0,0 +1,25 @@
1
+ require 'endpoint'
2
+
3
+ class Config
4
+ def initialize(config)
5
+ @config = YAML.load_file(config)
6
+ end
7
+
8
+ def token
9
+ @token ||= @config["token"]
10
+ end
11
+
12
+ def client_id
13
+ @client_id ||= @config["client_id"]
14
+ end
15
+
16
+ def endpoints
17
+ @endpoints ||= @config["endpoints"].map do |endpoint|
18
+ Endpoint.new(endpoint)
19
+ end
20
+ end
21
+
22
+ def emojis
23
+ @emojis ||= @config["emojis"]
24
+ end
25
+ end
@@ -1,8 +1,8 @@
1
- class QwtfDiscordBotServer < QwtfDiscordBot # :nodoc:
1
+ class QwtfDiscordBotServer
2
2
  def run
3
3
  bot = Discordrb::Commands::CommandBot.new(
4
- token: @token,
5
- client_id: @client_id,
4
+ token: QwtfDiscordBot.config.token,
5
+ client_id: QwtfDiscordBot.config.client_id,
6
6
  prefix: '!'
7
7
  )
8
8
 
@@ -27,7 +27,7 @@ class QwtfDiscordBotServer < QwtfDiscordBot # :nodoc:
27
27
  end
28
28
 
29
29
  bot.command :all do |event|
30
- endpoints_for_this_channel = @endpoints.select do |endpoint|
30
+ endpoints_for_this_channel = QwtfDiscordBot.config.endpoints.select do |endpoint|
31
31
  endpoint.channel_ids.any? do |channel_id|
32
32
  event.channel.id == channel_id
33
33
  end
@@ -55,7 +55,7 @@ class QwtfDiscordBotServer < QwtfDiscordBot # :nodoc:
55
55
  end
56
56
 
57
57
  bot.command :active do |event|
58
- endpoints_for_this_channel = @endpoints.select do |endpoint|
58
+ endpoints_for_this_channel = QwtfDiscordBot.config.endpoints.select do |endpoint|
59
59
  endpoint.channel_ids.any? do |channel_id|
60
60
  event.channel.id == channel_id
61
61
  end
@@ -1,10 +1,12 @@
1
- class QwtfDiscordBotWatcher < QwtfDiscordBot
1
+ class QwtfDiscordBotWatcher
2
+ include QwtfDiscordBot
3
+
2
4
  THIRTY_SECONDS = 30
3
5
  TEN_MINUTES = 10 * 60
4
6
 
5
7
  def run
6
8
  every(THIRTY_SECONDS) do
7
- @endpoints.each do |endpoint|
9
+ QwtfDiscordBot.config.endpoints.each do |endpoint|
8
10
  address = endpoint.address
9
11
  request = QstatRequest.new(address)
10
12
  next if request.is_empty?
@@ -43,7 +45,7 @@ class QwtfDiscordBotWatcher < QwtfDiscordBot
43
45
 
44
46
  def report_joined(name:, channel_id:, server_summary:)
45
47
  Discordrb::API::Channel.create_message(
46
- "Bot #{@token}",
48
+ "Bot #{QwtfDiscordBot.config.token}",
47
49
  channel_id,
48
50
  "#{name} has joined #{server_summary}"
49
51
  )
@@ -1,3 +1,3 @@
1
- class QwtfDiscordBot
2
- VERSION = '4.0.3'.freeze
1
+ module QwtfDiscordBot
2
+ VERSION = '4.1.0'.freeze
3
3
  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.0.3
4
+ version: 4.1.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-24 00:00:00.000000000 Z
11
+ date: 2019-07-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: discordrb
@@ -86,11 +86,12 @@ files:
86
86
  - emoji/red_soldier.png
87
87
  - emoji/red_spy.png
88
88
  - exe/qwtf_discord_bot
89
- - lib/config.rb
90
89
  - lib/emoji.rb
90
+ - lib/endpoint.rb
91
91
  - lib/player.rb
92
92
  - lib/qstat_request.rb
93
93
  - lib/qwtf_discord_bot.rb
94
+ - lib/qwtf_discord_bot/config.rb
94
95
  - lib/qwtf_discord_bot/qwtf_discord_bot_server.rb
95
96
  - lib/qwtf_discord_bot/qwtf_discord_bot_watcher.rb
96
97
  - lib/qwtf_discord_bot/version.rb