dsu3 0.5.1 → 0.8.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: e545e0e38f675b05b374e68e43bed9c5cb794ae4acce2a05eb50830ded1c16ee
4
- data.tar.gz: a7ccac599af92f1320f561326f8a7e025c91393e496e8baca014afeb5043d3a8
3
+ metadata.gz: db7f39a723112f9cbe182b9e25cf006a798aac0466808b3d60ae8234eb077df6
4
+ data.tar.gz: 998c0a9747d636b39ca2bcb431ce021556b90e67986e022cfee42352cf17cbf7
5
5
  SHA512:
6
- metadata.gz: eef4eadf13de5db7a8dbd4dca2bbf59e4f44956de4175d1cf308df4b009b3b0bdced88ca295bacb18562161c4b2bbcb0567a3462afb3990599cad7762b3fe5fa
7
- data.tar.gz: f10eef693e3e690a6003a46e802f22d7435eedceaa6b31821b68055cf342be975b74170f6eb1a9afa4df5c61e4947934ebef175bce0bd4632ffab79b83fa14be
6
+ metadata.gz: d423cdcbbbf40cdbe7d2918f26d08f3ffc7bd385ad0f5b9879cea35e013263a8ac45698292bbf7edd60366071c17a2e7783229f3b7e1d85cef4adfdf5068163b
7
+ data.tar.gz: 1f114e4c310383024912019216f0338252bf23c6eca4dfc914c6d584dce4188b5d919cafe5b9f70b57456de6e2a8495dbeee0c2835034673fce02422cf06c98c
data/README.md CHANGED
@@ -5,3 +5,11 @@ dsu3 is a simple library for working with discord selfbots
5
5
  ```sh
6
6
  sudo gem install dsu3
7
7
  ```
8
+
9
+ # usage
10
+ execute
11
+ ```sh
12
+ dsu3 path/to/token/file
13
+ ```
14
+ to run irb with dsu3 already required and a net instance already initialised
15
+ more info is available here www.rubydoc.info/gems/dsu3
data/bin/dsu3 ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'dsu3'
4
+
5
+ # read
6
+ c = DSU3::Core.new(File.readlines(ARGV.shift))
7
+
8
+ require 'irb'
9
+
10
+ IRB.start
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DSU3
4
+ module API
5
+ # Channels resource
6
+ module Channel
7
+ module_function
8
+
9
+ # Types text into a particular channel
10
+ # @param [String] token Discord account token
11
+ # @param [String, Integer] channel Channel ID
12
+ def type(token, channel)
13
+ DSU3::API.request(
14
+ token, :post, "channels/#{channel}/typing"
15
+ )
16
+ end
17
+
18
+ # Sends a message to a specific channel
19
+ # @param [String] token Discord account token
20
+ # @param [String, Integer] channel Channel ID
21
+ # @param [String, Integer] message Message contents
22
+ def send(token, channel, message)
23
+ DSU3::API.request(
24
+ token, :post, "channels/#{channel}/messages",
25
+ {}, { content: message }.to_json
26
+ )
27
+ end
28
+
29
+ # Reacts to a message
30
+ # @note To use custom emoji, you must encode it in the format name:id with the emoji name and emoji id
31
+ # @param [String] token Discord account token
32
+ # @param [String, Integer] channel Channel ID
33
+ # @param [String, Integer] message Message ID
34
+ # @param [String] emoji
35
+ def react(token, channel, message, emoji)
36
+ emoji = URI.encode_www_form_component(emoji)
37
+
38
+ DSU3::API.request(
39
+ token, :put,
40
+ "channels/#{channel}/messages/#{message}/reactions/#{emoji}/@me",
41
+ { params: { location: 'Message' } }
42
+ )
43
+ end
44
+ end
45
+ end
46
+ end
data/lib/dsu3/api.rb ADDED
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rest-client'
4
+ require 'json'
5
+ require 'uri'
6
+
7
+ require 'dsu3/props'
8
+ require 'dsu3/api/channel'
9
+
10
+ module DSU3
11
+ # Namespace for all methods representing Discord API endpoints
12
+ module API
13
+ API_BASE = 'https://discord.com/api/v9'
14
+
15
+ module_function
16
+
17
+ # Makes an API request without any error handling
18
+ # @param [String] token Discord account token
19
+ # @param [Symbol, String] method
20
+ # @param [String] route Discord API route
21
+ # @param [Hash] headers Additional request headers
22
+ # @param [String] payload
23
+ # @return [RestClient::Response] Response object
24
+ def raw_request(token, method, route, headers = {}, payload = nil)
25
+ RestClient::Request.execute(
26
+ method: method,
27
+ url: URI.join(API_BASE, route).to_s,
28
+ headers: headers.merge(DSU3::Props::HEADERS, { authorization: token }),
29
+ payload: payload,
30
+ proxy: DSU3.proxies.sample
31
+ )
32
+ end
33
+
34
+ # Makes an API request, includes simple error handling
35
+ # @param (see #raw_request)
36
+ # @return (see #raw_request)
37
+ def request(...)
38
+ raw_request(...)
39
+ rescue RestClient::ExceptionWithResponse => e
40
+ if e.is_a?(RestClient::TooManyRequests)
41
+ LOGGER.warn('ratelimit exceeded')
42
+ elsif e.response.headers[:content_type] == 'application/json'
43
+ LOGGER.error("#{data['code']}: #{data['message']}")
44
+ else
45
+ LOGGER.error(e.message)
46
+ end
47
+ e.response
48
+ end
49
+
50
+ # Joins guild
51
+ # @param [String] token Discord account token
52
+ # @param [String] invite Invite code
53
+ def join(token, invite)
54
+ request(
55
+ token, :post, "invites/#{invite}",
56
+ { x_context_properties: 'eyJsb2NhdGlvbiI6Ik1hcmtkb3duIExpbmsifQ==' },
57
+ '{}'
58
+ )
59
+ end
60
+ end
61
+ end
data/lib/dsu3/net.rb ADDED
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'dsu3/api'
4
+
5
+ module DSU3
6
+ # Class used to manage multiple bots
7
+ class Net
8
+ # @param [Array] tokens List of bot tokens
9
+ def initialize(*tokens)
10
+ @tokens = tokens
11
+ end
12
+
13
+ # (see DSU3::API::Channel#type)
14
+ def typespam(channel)
15
+ loop do
16
+ @tokens.each { |token| DSU3::API::Channel.type(token, channel) }
17
+ sleep 9
18
+ end
19
+ end
20
+
21
+ # (see DSU3::API::Channel#send)
22
+ def send(channel, message)
23
+ @tokens.each { |token| DSU3::API::Channel.send(token, channel, message) }
24
+ end
25
+
26
+ # Infinitely calls a block and sends the value it returns to a specific channel
27
+ # @param [String] token Discord account token
28
+ # @param [String, Integer] channel Channel ID
29
+ def spam(channel, &block)
30
+ loop do
31
+ @tokens.each { |token| DSU3::API::Channel.send(token, channel, block.call) }
32
+ end
33
+ end
34
+
35
+ # (see DSU3::API#join)
36
+ def join(invite)
37
+ @tokens.each do |token|
38
+ DSU3::API.join(token, invite)
39
+ sleep(0.5)
40
+ end
41
+ end
42
+
43
+ # (see DSU3::API::Channel#react)
44
+ def react(channel, message, emoji)
45
+ @tokens.each { |token| DSU3::API::Channel.react(token, channel, message, emoji) }
46
+ end
47
+ end
48
+ end
data/lib/dsu3/props.rb CHANGED
@@ -1,12 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rest-client'
4
- require 'json'
5
3
  require 'base64'
6
4
 
7
5
  module DSU3
8
6
  # 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
10
7
  module Props
11
8
  # user-agent header
12
9
  USER_AGENT = 'Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Firefox/91.0'
data/lib/dsu3/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DSU3
4
- VERSION = '0.5.1'
4
+ VERSION = '0.8.0'
5
5
  end
data/lib/dsu3.rb CHANGED
@@ -3,10 +3,15 @@
3
3
  require 'logger'
4
4
 
5
5
  require 'dsu3/version'
6
- require 'dsu3/core'
6
+ require 'dsu3/net'
7
7
 
8
8
  # Main DSU3 namespace
9
9
  module DSU3
10
10
  LOGGER = Logger.new($stdout)
11
11
  LOGGER.level = Logger::WARN
12
+
13
+ @proxies = []
14
+ class << self
15
+ attr_accessor :proxies
16
+ end
12
17
  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.5.1
4
+ version: 0.8.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-18 00:00:00.000000000 Z
11
+ date: 2022-08-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -26,15 +26,18 @@ dependencies:
26
26
  version: '2.0'
27
27
  description:
28
28
  email:
29
- executables: []
29
+ executables:
30
+ - dsu3
30
31
  extensions: []
31
32
  extra_rdoc_files:
32
33
  - README.md
33
34
  files:
34
35
  - README.md
36
+ - bin/dsu3
35
37
  - lib/dsu3.rb
36
- - lib/dsu3/bot.rb
37
- - lib/dsu3/core.rb
38
+ - lib/dsu3/api.rb
39
+ - lib/dsu3/api/channel.rb
40
+ - lib/dsu3/net.rb
38
41
  - lib/dsu3/props.rb
39
42
  - lib/dsu3/version.rb
40
43
  homepage: https://rubygems.org/gems/dsu3
data/lib/dsu3/bot.rb DELETED
@@ -1,93 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rest-client'
4
- require 'json'
5
- require 'uri'
6
-
7
- module DSU3
8
- # Class representing Discord bot
9
- class Bot
10
- API_BASE = 'https://discord.com/api/v9'
11
-
12
- # @param [String] token Discord account token
13
- def initialize(token)
14
- @headers = Props::HEADERS.merge(authorization: token)
15
- end
16
-
17
- # Makes an API request without any error handling
18
- # @param [Symbol, String] method
19
- # @param [String] endpoint Discord API endpoint
20
- # @param [Hash] headers Additional request headers
21
- # @param [String] payload
22
- def raw_request(method, endpoint, headers = {}, payload = nil)
23
- args = {
24
- method: method,
25
- url: URI.join(API_BASE, endpoint).to_s,
26
- headers: @headers.merge(headers)
27
- }
28
-
29
- args[:payload] = payload if payload
30
-
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)
40
-
41
- if e.is_a?(RestClient::TooManyRequests)
42
- retry_after = data['retry_after'] / 1000.0
43
-
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']}")
49
- end
50
- end
51
-
52
- # Types text into a particular channel
53
- # @param [String, Integer] channel Channel ID
54
- def type(channel)
55
- request(:post, "channels/#{channel}/typing")
56
- end
57
-
58
- # Sends a message to a specific channel
59
- # @param [String, Integer] channel Channel ID
60
- # @param [String] message
61
- def send_message(channel, message)
62
- request(
63
- :post, "channels/#{channel}/messages",
64
- {}, { content: message }.to_json
65
- )
66
- end
67
-
68
- # Joins guild
69
- # @param [String] invite Invite code
70
- def join(invite)
71
- request(
72
- :post, "invites/#{invite}",
73
- { x_context_properties: 'eyJsb2NhdGlvbiI6Ik1hcmtkb3duIExpbmsifQ==' },
74
- '{}'
75
- )
76
- end
77
-
78
- # Reacts to a message
79
- # @note To use custom emoji, you must encode it in the format name:id with the emoji name and emoji id
80
- # @param [String, Integer] channel Channel ID
81
- # @param [String, Integer] message Message ID
82
- # @param [String] emoji
83
- def react(channel, message, emoji)
84
- emoji = URI.encode_www_form_component(emoji)
85
-
86
- request(
87
- :put,
88
- "channels/#{channel}/messages/#{message}/reactions/#{emoji}/@me",
89
- { params: { location: 'Message' } }
90
- )
91
- end
92
- end
93
- end
data/lib/dsu3/core.rb DELETED
@@ -1,46 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'dsu3/props'
4
- require 'dsu3/bot'
5
-
6
- module DSU3
7
- # Class used to manage multiple bots
8
- class Core
9
- # @param [Array] tokens List of bot tokens
10
- def initialize(*tokens)
11
- @bots = tokens.map(&Bot.method(:new))
12
- end
13
-
14
- # (see Bot#type)
15
- def typespam(channel)
16
- loop do
17
- @bots.each { |bot| bot.type(channel) }
18
- sleep 9
19
- end
20
- end
21
-
22
- # (see Bot#send_message)
23
- def send_message(channel, message)
24
- @bots.each { |bot| bot.send_message(channel, message) }
25
- end
26
-
27
- # Infinitely calls a block and sends the value it returns to a specific channel
28
- # @param [String, Integer] channel Channel ID
29
- def spam(channel, &block)
30
- loop { @bots.each { |bot| bot.send_message(channel, block.call) } }
31
- end
32
-
33
- # (see Bot#join)
34
- def join(invite)
35
- @bots.each do |bot|
36
- bot.join(invite)
37
- sleep(0.5)
38
- end
39
- end
40
-
41
- # (see Bot#react)
42
- def react(channel, message, emoji)
43
- @bots.each { |bot| bot.react(channel, message, emoji) }
44
- end
45
- end
46
- end