dsu3 0.3.1 → 0.4
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/lib/dsu3/bot.rb +22 -17
- data/lib/dsu3/core.rb +3 -4
- data/lib/dsu3/props.rb +6 -14
- data/lib/dsu3.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e9a0705c6d460fe073239d8637574b0fa3e8abfb618064aca5d79271f34a0d70
|
4
|
+
data.tar.gz: c622c03008ec604396abf1309d7fc87155bc9dca09650c7486305ec05214d6cb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: db0f31beb357f9e01751305fa00c0e914c0b2e9a51664afdbf88a2940e8b23fef2488e84597eb44c1e155d4bb6f6641f51ba86067dc7ca3fa537f86da13088b5
|
7
|
+
data.tar.gz: 9a9c5288a110b35e13db5b5879c8d79ab9ba2b26f952b91b203a87ed628c1b100f0f69cfb8c27a267d1cbcd50cff43e770e3f80e5f50161492c051b2039d314d
|
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 [
|
12
|
-
def initialize(
|
13
|
-
@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
|
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
|
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
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
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
|
-
|
36
|
-
|
41
|
+
if e.is_a?(RestClient::TooManyRequests)
|
42
|
+
retry_after = data['retry_after'] / 1000.0
|
37
43
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
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
|
-
#
|
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
|
-
|
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
@@ -6,8 +6,6 @@ require 'base64'
|
|
6
6
|
|
7
7
|
module DSU3
|
8
8
|
module Props
|
9
|
-
module_function
|
10
|
-
|
11
9
|
# user-agent header
|
12
10
|
USER_AGENT =
|
13
11
|
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) '\
|
@@ -28,7 +26,9 @@ module DSU3
|
|
28
26
|
client_event_source: nil
|
29
27
|
}.freeze
|
30
28
|
|
31
|
-
|
29
|
+
resp = RestClient.get('https://discord.com/api/v9/experiments')
|
30
|
+
|
31
|
+
# Headers necessary for normal interaction with the Discord API
|
32
32
|
HEADERS = {
|
33
33
|
accept: '*/*',
|
34
34
|
accept_encoding: 'gzip, deflate, br',
|
@@ -41,17 +41,9 @@ module DSU3
|
|
41
41
|
x_discord_locale: 'en-US',
|
42
42
|
x_super_properties: Base64.strict_encode64(SUPER_PROPERTIES.to_json),
|
43
43
|
content_type: 'application/json',
|
44
|
-
origin: 'https://discord.com'
|
44
|
+
origin: 'https://discord.com',
|
45
|
+
cookie: HTTP::Cookie.cookie_value(resp.cookie_jar.cookies),
|
46
|
+
x_fingerprint: JSON.parse(resp.body)['fingerprint']
|
45
47
|
}.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
48
|
end
|
57
49
|
end
|
data/lib/dsu3.rb
CHANGED
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.
|
4
|
+
version: '0.4'
|
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-
|
11
|
+
date: 2022-07-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|
@@ -51,7 +51,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
51
51
|
requirements:
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 2.
|
54
|
+
version: 2.7.0
|
55
55
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
56
|
requirements:
|
57
57
|
- - ">="
|