dsu3 0.5.0 → 0.7.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: 9572203f08a6ce1f65c4a33b613b51a116c0fc935c6f26c8d0e5b2f0600740b6
4
- data.tar.gz: 89b125202ba866c62599f69fa7f9321b82d4edf3773fdebcbe0dfe6771f1f724
3
+ metadata.gz: 00c308cdbface19a2f537b9221ff0bfa847d3ffeff2bb9632a7411ea73308eac
4
+ data.tar.gz: 307ff5780d040f5a3d465d3c4eba4f013f8d26fa5bcdc2e59c1a82ff2324f857
5
5
  SHA512:
6
- metadata.gz: 5fd28581d81eeead4c8295818ef4f1484218e7771b42709a47991696da2b0eb9c9b936aa0fbaa36b800b5f798d55271e3b5acf333a59895658d1b4c87acdb312
7
- data.tar.gz: 2857ce644817ba1f2965de5d82585322ecd889fa4eb87f5a7980119a22654d623f1e1af84c174c3a029bbbf04bd5e3f82e3b7e1fea1848ffea96ab1dc360ed66
6
+ metadata.gz: a35f9b161e9b36f252b8e600c8bd58da2a2c8aa069a5ed3beb91acb045262da5b42c63cf47bf602f1a3a8f47587a7fc2b06dc8c7174c40e543979350cb4cd0ae
7
+ data.tar.gz: 1a2e1a6b948e8bd22902726cc05088ded20351311e08099efe3bb0d57c4484f3b766a8b68f4af5557a937ef2042261e2bc66c6e0bddcdf708a6812f06a97a016
@@ -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 ID
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,62 @@
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] endpoint Discord API endpoint
21
+ # @param [Hash] headers Additional request headers
22
+ # @param [String] payload
23
+ def raw_request(token, method, endpoint, headers = {}, payload = nil)
24
+ RestClient::Request.execute(
25
+ method: method,
26
+ url: URI.join(API_BASE, endpoint).to_s,
27
+ headers: headers.merge(DSU3::Props::HEADERS, { authorization: token }),
28
+ payload: payload,
29
+ proxy: DSU3.proxies.sample
30
+ )
31
+ end
32
+
33
+ # Makes an API request, includes simple error handling
34
+ # @param (see #raw_request)
35
+ def request(...)
36
+ raw_request(...)
37
+ rescue RestClient::ExceptionWithResponse => e
38
+ data = JSON.parse(e.response)
39
+
40
+ if e.is_a?(RestClient::TooManyRequests)
41
+ retry_after = data['retry_after'] / 1000.0
42
+
43
+ LOGGER.warn("rate limit exceeded, waiting #{retry_after} seconds")
44
+ sleep(retry_after)
45
+ retry
46
+ else
47
+ LOGGER.error("#{data['code']}: #{data['message']}")
48
+ end
49
+ end
50
+
51
+ # Joins guild
52
+ # @param [String] token Discord account token
53
+ # @param [String] invite Invite code
54
+ def join(token, invite)
55
+ request(
56
+ token, :post, "invites/#{invite}",
57
+ { x_context_properties: 'eyJsb2NhdGlvbiI6Ik1hcmtkb3duIExpbmsifQ==' },
58
+ '{}'
59
+ )
60
+ end
61
+ end
62
+ end
data/lib/dsu3/core.rb CHANGED
@@ -1,46 +1,49 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'dsu3/props'
4
- require 'dsu3/bot'
3
+ require 'dsu3/api'
5
4
 
6
5
  module DSU3
7
6
  # Class used to manage multiple bots
8
7
  class Core
9
8
  # @param [Array] tokens List of bot tokens
9
+ # If the list of proxy servers is empty, the proxy will not be used
10
10
  def initialize(*tokens)
11
- @bots = tokens.map(&Bot.method(:new))
11
+ @tokens = tokens
12
12
  end
13
13
 
14
- # (see Bot#type)
14
+ # (see DSU3::API::Channel#type)
15
15
  def typespam(channel)
16
16
  loop do
17
- @bots.each { |bot| bot.type(channel) }
17
+ @tokens.each { |token| DSU3::API::Channel.type(token, channel) }
18
18
  sleep 9
19
19
  end
20
20
  end
21
21
 
22
- # (see Bot#send_message)
23
- def send_message(channel, message)
24
- @bots.each { |bot| bot.send_message(channel, message) }
22
+ # (see DSU3::API::Channel#send)
23
+ def send(channel, message)
24
+ @tokens.each { |token| DSU3::API::Channel.send(token, channel, message) }
25
25
  end
26
26
 
27
27
  # Infinitely calls a block and sends the value it returns to a specific channel
28
+ # @param [String] token Discord account token
28
29
  # @param [String, Integer] channel Channel ID
29
30
  def spam(channel, &block)
30
- loop { @bots.each { |bot| bot.send_message(channel, block.call) } }
31
+ loop do
32
+ @tokens.each { |token| DSU3::API::Channel.send(token, channel, block.call) }
33
+ end
31
34
  end
32
35
 
33
- # (see Bot#join)
36
+ # (see DSU3::API#join)
34
37
  def join(invite)
35
- @bots.each do |bot|
36
- bot.join(invite)
38
+ @tokens.each do |token|
39
+ DSU3::API.join(token, invite)
37
40
  sleep(0.5)
38
41
  end
39
42
  end
40
43
 
41
- # (see Bot#react)
44
+ # (see DSU3::API::Channel#react)
42
45
  def react(channel, message, emoji)
43
- @bots.each { |bot| bot.react(channel, message, emoji) }
46
+ @tokens.each { |token| DSU3::API::Channel.react(token, channel, message, emoji) }
44
47
  end
45
48
  end
46
49
  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'
@@ -14,7 +11,7 @@ module DSU3
14
11
  DATAMINING_COMMITS_URL = 'https://api.github.com/repos/Discord-Datamining/Discord-Datamining/commits/master'
15
12
 
16
13
  # Fetches Discord client build number
17
- def fetch_build_number
14
+ def self.fetch_build_number
18
15
  JSON.parse(RestClient.get(DATAMINING_COMMITS_URL))['commit']['message'].match(/Build (\d+)/)[1]
19
16
  end
20
17
 
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DSU3
4
+ VERSION = '0.7.0'
5
+ end
data/lib/dsu3.rb CHANGED
@@ -1,12 +1,17 @@
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.5.0'
9
-
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.0
4
+ version: 0.7.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-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -33,9 +33,11 @@ extra_rdoc_files:
33
33
  files:
34
34
  - README.md
35
35
  - lib/dsu3.rb
36
- - lib/dsu3/bot.rb
36
+ - lib/dsu3/api.rb
37
+ - lib/dsu3/api/channel.rb
37
38
  - lib/dsu3/core.rb
38
39
  - lib/dsu3/props.rb
40
+ - lib/dsu3/version.rb
39
41
  homepage: https://rubygems.org/gems/dsu3
40
42
  licenses:
41
43
  - MIT
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