qwtf_discord_bot 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a6bd91dab755db495a2f8bb351a024fd75f3380693935b1b26b243329a675942
4
+ data.tar.gz: a66321e8a1ccf79ecab2fca9b2b0c98cd8f8bc85feb74c6df9187c5e9cb63e8c
5
+ SHA512:
6
+ metadata.gz: e166e573a07bf48718f1a06021d64f1f161bac41f0903017f646fd209e9b12b442c383b9babf4316ea2615c623648a8c1146ce12e22618a2ca7574d328159e4b
7
+ data.tar.gz: fb871cfca238d28436168a8a0a1ae83c68948602edd89b01fa76dfebeef8f3d5dd9a1a5b34ac8beffd7d3a52d4e7aa247753c46c9b6a0e5ddb659b1fc66994fc
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+ assets/
13
+ .env
14
+ qstat
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.5.0
5
+ before_install: gem install bundler -v 1.16.1
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in qwtf_discord_bot.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,77 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ qwtf_discord_bot (0.2.0)
5
+ discordrb
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ coderay (1.1.2)
11
+ diff-lcs (1.3)
12
+ discordrb (3.2.1)
13
+ discordrb-webhooks (~> 3.2.0.1)
14
+ opus-ruby
15
+ rbnacl (~> 3.4.0)
16
+ rest-client
17
+ websocket-client-simple (>= 0.3.0)
18
+ discordrb-webhooks (3.2.0.1)
19
+ rest-client
20
+ domain_name (0.5.20170404)
21
+ unf (>= 0.0.5, < 1.0.0)
22
+ event_emitter (0.2.6)
23
+ ffi (1.9.25)
24
+ http-cookie (1.0.3)
25
+ domain_name (~> 0.5)
26
+ method_source (0.9.0)
27
+ mime-types (3.1)
28
+ mime-types-data (~> 3.2015)
29
+ mime-types-data (3.2016.0521)
30
+ netrc (0.11.0)
31
+ opus-ruby (1.0.1)
32
+ ffi
33
+ pry (0.11.3)
34
+ coderay (~> 1.1.0)
35
+ method_source (~> 0.9.0)
36
+ rake (10.5.0)
37
+ rbnacl (3.4.0)
38
+ ffi
39
+ rest-client (2.0.2)
40
+ http-cookie (>= 1.0.2, < 2.0)
41
+ mime-types (>= 1.16, < 4.0)
42
+ netrc (~> 0.8)
43
+ rspec (3.7.0)
44
+ rspec-core (~> 3.7.0)
45
+ rspec-expectations (~> 3.7.0)
46
+ rspec-mocks (~> 3.7.0)
47
+ rspec-core (3.7.1)
48
+ rspec-support (~> 3.7.0)
49
+ rspec-expectations (3.7.0)
50
+ diff-lcs (>= 1.2.0, < 2.0)
51
+ rspec-support (~> 3.7.0)
52
+ rspec-mocks (3.7.0)
53
+ diff-lcs (>= 1.2.0, < 2.0)
54
+ rspec-support (~> 3.7.0)
55
+ rspec-support (3.7.1)
56
+ thor (0.20.0)
57
+ unf (0.1.4)
58
+ unf_ext
59
+ unf_ext (0.0.7.5)
60
+ websocket (1.2.5)
61
+ websocket-client-simple (0.3.0)
62
+ event_emitter
63
+ websocket
64
+
65
+ PLATFORMS
66
+ ruby
67
+
68
+ DEPENDENCIES
69
+ bundler (~> 1.16)
70
+ pry
71
+ qwtf_discord_bot!
72
+ rake (~> 10.0)
73
+ rspec (~> 3.0)
74
+ thor
75
+
76
+ BUNDLED WITH
77
+ 1.16.2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Sheldon Johnson
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # QwtfDiscordBot
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/qwtf_discord_bot`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'qwtf_discord_bot'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install qwtf_discord_bot
22
+
23
+ ## Usage
24
+
25
+ $ bundle exec exe\qwtf-discord-bot server
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/qwtf_discord_bot.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "qwtf_discord_bot"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'qwtf_discord_bot'
4
+ require 'qwtf_discord_bot/cli'
5
+
6
+ QwtfDiscordBot::CLI.start
data/lib/emoji.rb ADDED
@@ -0,0 +1,41 @@
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
+ }
26
+
27
+ def initialize(player)
28
+ @player = player
29
+ end
30
+
31
+ def to_s
32
+ id || ""
33
+
34
+ end
35
+
36
+ private
37
+
38
+ def id
39
+ @id ||= LOOKUP[@player.team.to_s] && LOOKUP[@player.team.to_s][@player.player_class]
40
+ end
41
+ end
data/lib/player.rb ADDED
@@ -0,0 +1,47 @@
1
+ class Player
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 to_row
19
+ "#{emoji}#{name}"
20
+ end
21
+
22
+ def team
23
+ @team ||= Team.new(@data["team"].to_sym)
24
+ end
25
+
26
+ def player_class
27
+ PLAYER_CLASSES[short_class]
28
+ end
29
+
30
+ private
31
+
32
+ def emoji
33
+ Emoji.new(self).to_s
34
+ end
35
+
36
+ def name
37
+ @data["name"]
38
+ end
39
+
40
+ def short_class
41
+ skin.split("_").last
42
+ end
43
+
44
+ def skin
45
+ @data["skin"]
46
+ end
47
+ end
@@ -0,0 +1,38 @@
1
+ class QstatRequest
2
+ def initialize(hostname)
3
+ @result = JSON.parse(%x[qstat -json -P -qws #{hostname}]).first
4
+ end
5
+
6
+ def output
7
+ <<~HEREDOC
8
+ **#{address} | #{map} | #{numplayers}/#{maxplayers}**
9
+ #{player_table}
10
+ HEREDOC
11
+ end
12
+
13
+ def address
14
+ @result["address"]
15
+ end
16
+
17
+ def map
18
+ @result["map"]
19
+ end
20
+
21
+ def numplayers
22
+ @result["numplayers"]
23
+ end
24
+
25
+ def maxplayers
26
+ @result["maxplayers"]
27
+ end
28
+
29
+ def player_table
30
+ players.sort_by { |player| player.team.number }.map(&:to_row).join("\n")
31
+ end
32
+
33
+ def players
34
+ @result["players"].map do |player_data|
35
+ Player.new(player_data)
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,25 @@
1
+ require "qwtf_discord_bot/version"
2
+ require "discordrb"
3
+
4
+ require "qstat_request"
5
+ require "player"
6
+ require "team"
7
+ require "emoji"
8
+
9
+ require "pry"
10
+
11
+ module QwtfDiscordBot
12
+ raise "DISCORD_QSTAT_BOT_TOKEN environment variable not set" unless ENV["DISCORD_QSTAT_BOT_TOKEN"]
13
+
14
+ TOKEN = ENV["DISCORD_QSTAT_BOT_TOKEN"].strip
15
+ CLIENT_ID = ENV["DISCORD_CLIENT_ID"].strip
16
+ HOSTNAME = "fortressone.ga"
17
+
18
+ bot = Discordrb::Commands::CommandBot.new token: TOKEN, client_id: CLIENT_ID, prefix: "!"
19
+
20
+ bot.command :server do |event|
21
+ QstatRequest.new(HOSTNAME).output
22
+ end
23
+
24
+ bot.run
25
+ end
@@ -0,0 +1,10 @@
1
+ require 'thor'
2
+
3
+ module QwtfDiscordBot
4
+ class CLI < Thor
5
+ desc "server", "Runs the qwtf-discord-bot"
6
+ def server
7
+ QwtfDiscordBot::Server.run
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,3 @@
1
+ module QwtfDiscordBot
2
+ VERSION = "0.2.0"
3
+ end
data/lib/team.rb ADDED
@@ -0,0 +1,13 @@
1
+ class Team
2
+ attr_accessor :number
3
+
4
+ TEAMS = { spec: 0, blue: 1, red: 2, yell: 3, gren: 4 }
5
+
6
+ def initialize(sym)
7
+ @number = TEAMS[sym] || 0
8
+ end
9
+
10
+ def to_s
11
+ TEAMS.key(@number).to_s
12
+ end
13
+ end
@@ -0,0 +1,31 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "qwtf_discord_bot/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "qwtf_discord_bot"
8
+ spec.version = QwtfDiscordBot::VERSION
9
+ spec.authors = ["Sheldon Johnson"]
10
+ spec.email = ["shayolden@hotmail.com"]
11
+
12
+ spec.description = %q{A discord bot for checking the status of qwtf servers}
13
+ spec.summary = %q{A discord bot for checking the status of qwtf servers}
14
+ spec.homepage = "https://github.com/drzel/qwtf_discord_bot.git"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_runtime_dependency "discordrb", '~> 0'
25
+
26
+ spec.add_development_dependency "thor", '~> 0'
27
+ spec.add_development_dependency "bundler", "~> 1.16"
28
+ spec.add_development_dependency "rake", "~> 10.0"
29
+ spec.add_development_dependency "rspec", "~> 3.0"
30
+ spec.add_development_dependency "pry", '~> 0'
31
+ end
metadata ADDED
@@ -0,0 +1,148 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: qwtf_discord_bot
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Sheldon Johnson
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-07-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: discordrb
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: thor
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.16'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.16'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: A discord bot for checking the status of qwtf servers
98
+ email:
99
+ - shayolden@hotmail.com
100
+ executables:
101
+ - qwtf_discord_bot
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - ".rspec"
107
+ - ".travis.yml"
108
+ - Gemfile
109
+ - Gemfile.lock
110
+ - LICENSE.txt
111
+ - README.md
112
+ - Rakefile
113
+ - bin/console
114
+ - bin/setup
115
+ - exe/qwtf_discord_bot
116
+ - lib/emoji.rb
117
+ - lib/player.rb
118
+ - lib/qstat_request.rb
119
+ - lib/qwtf_discord_bot.rb
120
+ - lib/qwtf_discord_bot/cli.rb
121
+ - lib/qwtf_discord_bot/version.rb
122
+ - lib/team.rb
123
+ - qwtf_discord_bot.gemspec
124
+ homepage: https://github.com/drzel/qwtf_discord_bot.git
125
+ licenses:
126
+ - MIT
127
+ metadata: {}
128
+ post_install_message:
129
+ rdoc_options: []
130
+ require_paths:
131
+ - lib
132
+ required_ruby_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ required_rubygems_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ requirements: []
143
+ rubyforge_project:
144
+ rubygems_version: 2.7.3
145
+ signing_key:
146
+ specification_version: 4
147
+ summary: A discord bot for checking the status of qwtf servers
148
+ test_files: []