dsu3 0.3.1 → 0.5.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 784b8e875ba73a242236edf3a5623de6dba9c8546234f117db8a0e15ceb90ee2
4
- data.tar.gz: 6637133b46a4fe93d22673a6737c66a644b853ef336eb050e099526cf3891162
3
+ metadata.gz: e545e0e38f675b05b374e68e43bed9c5cb794ae4acce2a05eb50830ded1c16ee
4
+ data.tar.gz: a7ccac599af92f1320f561326f8a7e025c91393e496e8baca014afeb5043d3a8
5
5
  SHA512:
6
- metadata.gz: 24883144dbdca199af341c19e213833d887349378ea0dbd2d17cc01e1f92389d31baf9fc889f15a92c9ecfe64d74b96f861e807732861aa5d9834d0c85e0c499
7
- data.tar.gz: 408862f035b692fa792f655ed9f8d887e6ff2fcef75c3dfb39f64bc567a3fe3a3170ce43c808a9d593a20f1785206a04fc87b6518cc61cbef5ce6f0f79680263
6
+ metadata.gz: eef4eadf13de5db7a8dbd4dca2bbf59e4f44956de4175d1cf308df4b009b3b0bdced88ca295bacb18562161c4b2bbcb0567a3462afb3990599cad7762b3fe5fa
7
+ data.tar.gz: f10eef693e3e690a6003a46e802f22d7435eedceaa6b31821b68055cf342be975b74170f6eb1a9afa4df5c61e4947934ebef175bce0bd4632ffab79b83fa14be
data/lib/dsu3/bot.rb CHANGED
@@ -5,20 +5,21 @@ require 'json'
5
5
  require 'uri'
6
6
 
7
7
  module DSU3
8
+ # Class representing Discord bot
8
9
  class Bot
9
10
  API_BASE = 'https://discord.com/api/v9'
10
11
 
11
- # @param [Hash] headers
12
- def initialize(headers)
13
- @headers = headers
12
+ # @param [String] token Discord account token
13
+ def initialize(token)
14
+ @headers = Props::HEADERS.merge(authorization: token)
14
15
  end
15
16
 
16
- # Makes an API request, includes simple rate limit handling
17
+ # Makes an API request without any error handling
17
18
  # @param [Symbol, String] method
18
19
  # @param [String] endpoint Discord API endpoint
19
20
  # @param [Hash] headers Additional request headers
20
21
  # @param [String] payload
21
- def request(method, endpoint, headers = {}, payload = nil)
22
+ def raw_request(method, endpoint, headers = {}, payload = nil)
22
23
  args = {
23
24
  method: method,
24
25
  url: URI.join(API_BASE, endpoint).to_s,
@@ -27,20 +28,24 @@ module DSU3
27
28
 
28
29
  args[:payload] = payload if payload
29
30
 
30
- begin
31
- RestClient::Request.execute(args)
32
- rescue RestClient::ExceptionWithResponse => e
33
- data = JSON.parse(e.response)
31
+ RestClient::Request.execute(args)
32
+ end
33
+
34
+ # Makes an API request, includes simple error handling
35
+ # @param (see #raw_request)
36
+ def request(...)
37
+ raw_request(...)
38
+ rescue RestClient::ExceptionWithResponse => e
39
+ data = JSON.parse(e.response)
34
40
 
35
- if e.is_a?(RestClient::TooManyRequests)
36
- retry_after = data['retry_after'] / 1000.0
41
+ if e.is_a?(RestClient::TooManyRequests)
42
+ retry_after = data['retry_after'] / 1000.0
37
43
 
38
- LOGGER.warn("rate limit exceeded, waiting #{retry_after} seconds")
39
- sleep(retry_after)
40
- retry
41
- else
42
- LOGGER.error("#{data['code']}: #{data['message']}")
43
- end
44
+ LOGGER.warn("rate limit exceeded, waiting #{retry_after} seconds")
45
+ sleep(retry_after)
46
+ retry
47
+ else
48
+ LOGGER.error("#{data['code']}: #{data['message']}")
44
49
  end
45
50
  end
46
51
 
data/lib/dsu3/core.rb CHANGED
@@ -4,12 +4,11 @@ require 'dsu3/props'
4
4
  require 'dsu3/bot'
5
5
 
6
6
  module DSU3
7
- # All DSU3 functionality, used to manage multiple bots
7
+ # Class used to manage multiple bots
8
8
  class Core
9
9
  # @param [Array] tokens List of bot tokens
10
- def initialize(tokens)
11
- headers = Props.headers
12
- @bots = tokens.map { |token| Bot.new(headers.merge(authorization: token)) }
10
+ def initialize(*tokens)
11
+ @bots = tokens.map(&Bot.method(:new))
13
12
  end
14
13
 
15
14
  # (see Bot#type)
data/lib/dsu3/props.rb CHANGED
@@ -5,53 +5,58 @@ require 'json'
5
5
  require 'base64'
6
6
 
7
7
  module DSU3
8
+ # The fundamental class in this vast system, on which all the other parts of the structure depend
9
+ # pretty bad code in this module rests by the way
8
10
  module Props
9
- module_function
10
-
11
11
  # user-agent header
12
- USER_AGENT =
13
- 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) '\
14
- 'discord/0.0.18 Chrome/91.0.4472.164 Electron/13.6.6 Safari/537.36'
12
+ USER_AGENT = 'Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Firefox/91.0'
13
+
14
+ DATAMINING_COMMITS_URL = 'https://api.github.com/repos/Discord-Datamining/Discord-Datamining/commits/master'
15
+
16
+ # Fetches Discord client build number
17
+ def self.fetch_build_number
18
+ JSON.parse(RestClient.get(DATAMINING_COMMITS_URL))['commit']['message'].match(/Build (\d+)/)[1]
19
+ end
15
20
 
16
21
  # Decoded x-super-properties header
17
22
  SUPER_PROPERTIES = {
18
23
  os: 'Linux',
19
- browser: 'Discord Client',
24
+ browser: 'Firefox',
25
+ device: '',
26
+ system_locale: 'en',
27
+ browser_user_agent: USER_AGENT,
28
+ browser_version: '91.0',
29
+ os_version: '',
30
+ referrer: '',
31
+ referring_domain: '',
32
+ referrer_current: '',
33
+ referring_domain_current: '',
20
34
  release_channel: 'stable',
21
- client_version: '0.0.18',
22
- os_version: '5.10.0-14-amd64',
23
- os_arch: 'x64',
24
- system_locale: 'en-US',
25
- window_manager: 'XFCE,xfce',
26
- distro: 'Debian GNU/Linux 11 (bullseye)',
27
- client_build_number: 136_921,
35
+ client_build_number: fetch_build_number,
28
36
  client_event_source: nil
29
37
  }.freeze
30
38
 
31
- # Main headers
39
+ resp = RestClient.get('https://discord.com/api/v9/experiments')
40
+
41
+ # Headers necessary for normal interaction with the Discord API
32
42
  HEADERS = {
33
43
  accept: '*/*',
34
44
  accept_encoding: 'gzip, deflate, br',
35
- accept_language: 'en-US',
45
+ accept_language: 'en',
46
+ alt_used: 'discord.com',
47
+ connection: 'keep-alive',
48
+ host: 'discord.com',
36
49
  sec_fetch_dest: 'empty',
37
50
  sec_fetch_mode: 'cors',
38
51
  sec_fetch_site: 'same-origin',
52
+ te: 'trailers',
39
53
  user_agent: USER_AGENT,
40
54
  x_debug_options: 'bugReporterEnabled',
41
55
  x_discord_locale: 'en-US',
42
56
  x_super_properties: Base64.strict_encode64(SUPER_PROPERTIES.to_json),
43
57
  content_type: 'application/json',
44
- origin: 'https://discord.com'
58
+ cookie: HTTP::Cookie.cookie_value(resp.cookie_jar.cookies),
59
+ x_fingerprint: JSON.parse(resp.body)['fingerprint']
45
60
  }.freeze
46
-
47
- # Gets the headers necessary for normal interaction with the Discord API
48
- def headers
49
- resp = RestClient.get('https://discord.com/api/v9/experiments')
50
-
51
- {
52
- cookie: HTTP::Cookie.cookie_value(resp.cookie_jar.cookies),
53
- x_fingerprint: JSON.parse(resp.body)['fingerprint']
54
- }.merge(HEADERS)
55
- end
56
61
  end
57
62
  end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DSU3
4
+ VERSION = '0.5.1'
5
+ end
data/lib/dsu3.rb CHANGED
@@ -1,12 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'logger'
4
+
5
+ require 'dsu3/version'
4
6
  require 'dsu3/core'
5
7
 
6
8
  # Main DSU3 namespace
7
9
  module DSU3
8
- VERSION = '0.3.1'
9
-
10
10
  LOGGER = Logger.new($stdout)
11
11
  LOGGER.level = Logger::WARN
12
12
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dsu3
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Artur Sheremetjev IV
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-07-17 00:00:00.000000000 Z
11
+ date: 2022-07-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -36,6 +36,7 @@ files:
36
36
  - lib/dsu3/bot.rb
37
37
  - lib/dsu3/core.rb
38
38
  - lib/dsu3/props.rb
39
+ - lib/dsu3/version.rb
39
40
  homepage: https://rubygems.org/gems/dsu3
40
41
  licenses:
41
42
  - MIT
@@ -51,7 +52,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
51
52
  requirements:
52
53
  - - ">="
53
54
  - !ruby/object:Gem::Version
54
- version: 2.0.0
55
+ version: 2.7.0
55
56
  required_rubygems_version: !ruby/object:Gem::Requirement
56
57
  requirements:
57
58
  - - ">="