dsu3 0.6.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 +4 -4
- data/lib/dsu3/api/channel.rb +46 -0
- data/lib/dsu3/api.rb +62 -0
- data/lib/dsu3/core.rb +17 -16
- data/lib/dsu3/props.rb +0 -2
- data/lib/dsu3/version.rb +1 -1
- data/lib/dsu3.rb +5 -0
- metadata +4 -3
- data/lib/dsu3/bot.rb +0 -94
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 00c308cdbface19a2f537b9221ff0bfa847d3ffeff2bb9632a7411ea73308eac
|
4
|
+
data.tar.gz: 307ff5780d040f5a3d465d3c4eba4f013f8d26fa5bcdc2e59c1a82ff2324f857
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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,48 +1,49 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'dsu3/
|
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
|
10
|
-
# @param [Array] proxies List of proxy servers
|
11
9
|
# If the list of proxy servers is empty, the proxy will not be used
|
12
|
-
def initialize(*tokens
|
13
|
-
@
|
10
|
+
def initialize(*tokens)
|
11
|
+
@tokens = tokens
|
14
12
|
end
|
15
13
|
|
16
|
-
# (see
|
14
|
+
# (see DSU3::API::Channel#type)
|
17
15
|
def typespam(channel)
|
18
16
|
loop do
|
19
|
-
@
|
17
|
+
@tokens.each { |token| DSU3::API::Channel.type(token, channel) }
|
20
18
|
sleep 9
|
21
19
|
end
|
22
20
|
end
|
23
21
|
|
24
|
-
# (see
|
25
|
-
def
|
26
|
-
@
|
22
|
+
# (see DSU3::API::Channel#send)
|
23
|
+
def send(channel, message)
|
24
|
+
@tokens.each { |token| DSU3::API::Channel.send(token, channel, message) }
|
27
25
|
end
|
28
26
|
|
29
27
|
# Infinitely calls a block and sends the value it returns to a specific channel
|
28
|
+
# @param [String] token Discord account token
|
30
29
|
# @param [String, Integer] channel Channel ID
|
31
30
|
def spam(channel, &block)
|
32
|
-
loop
|
31
|
+
loop do
|
32
|
+
@tokens.each { |token| DSU3::API::Channel.send(token, channel, block.call) }
|
33
|
+
end
|
33
34
|
end
|
34
35
|
|
35
|
-
# (see
|
36
|
+
# (see DSU3::API#join)
|
36
37
|
def join(invite)
|
37
|
-
@
|
38
|
-
|
38
|
+
@tokens.each do |token|
|
39
|
+
DSU3::API.join(token, invite)
|
39
40
|
sleep(0.5)
|
40
41
|
end
|
41
42
|
end
|
42
43
|
|
43
|
-
# (see
|
44
|
+
# (see DSU3::API::Channel#react)
|
44
45
|
def react(channel, message, emoji)
|
45
|
-
@
|
46
|
+
@tokens.each { |token| DSU3::API::Channel.react(token, channel, message, emoji) }
|
46
47
|
end
|
47
48
|
end
|
48
49
|
end
|
data/lib/dsu3/props.rb
CHANGED
data/lib/dsu3/version.rb
CHANGED
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.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-
|
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,7 +33,8 @@ extra_rdoc_files:
|
|
33
33
|
files:
|
34
34
|
- README.md
|
35
35
|
- lib/dsu3.rb
|
36
|
-
- lib/dsu3/
|
36
|
+
- lib/dsu3/api.rb
|
37
|
+
- lib/dsu3/api/channel.rb
|
37
38
|
- lib/dsu3/core.rb
|
38
39
|
- lib/dsu3/props.rb
|
39
40
|
- lib/dsu3/version.rb
|
data/lib/dsu3/bot.rb
DELETED
@@ -1,94 +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
|
-
# @param [Array] proxies List of proxy servers
|
14
|
-
# If the list of proxy servers is empty, the proxy will not be used
|
15
|
-
def initialize(token, proxies = [])
|
16
|
-
@headers = Props::HEADERS.merge(authorization: token)
|
17
|
-
@proxies = proxies
|
18
|
-
end
|
19
|
-
|
20
|
-
# Makes an API request without any error handling
|
21
|
-
# @param [Symbol, String] method
|
22
|
-
# @param [String] endpoint Discord API endpoint
|
23
|
-
# @param [Hash] headers Additional request headers
|
24
|
-
# @param [String] payload
|
25
|
-
def raw_request(method, endpoint, headers = {}, payload = nil)
|
26
|
-
RestClient::Request.execute(
|
27
|
-
method: method,
|
28
|
-
url: URI.join(API_BASE, endpoint).to_s,
|
29
|
-
headers: @headers.merge(headers),
|
30
|
-
payload: payload,
|
31
|
-
proxy: @proxies.sample
|
32
|
-
)
|
33
|
-
end
|
34
|
-
|
35
|
-
# Makes an API request, includes simple error handling
|
36
|
-
# @param (see #raw_request)
|
37
|
-
def request(...)
|
38
|
-
raw_request(...)
|
39
|
-
rescue RestClient::ExceptionWithResponse => e
|
40
|
-
data = JSON.parse(e.response)
|
41
|
-
|
42
|
-
if e.is_a?(RestClient::TooManyRequests)
|
43
|
-
retry_after = data['retry_after'] / 1000.0
|
44
|
-
|
45
|
-
LOGGER.warn("rate limit exceeded, waiting #{retry_after} seconds")
|
46
|
-
sleep(retry_after)
|
47
|
-
retry
|
48
|
-
else
|
49
|
-
LOGGER.error("#{data['code']}: #{data['message']}")
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
# Types text into a particular channel
|
54
|
-
# @param [String, Integer] channel Channel ID
|
55
|
-
def type(channel)
|
56
|
-
request(:post, "channels/#{channel}/typing")
|
57
|
-
end
|
58
|
-
|
59
|
-
# Sends a message to a specific channel
|
60
|
-
# @param [String, Integer] channel Channel ID
|
61
|
-
# @param [String] message Message ID
|
62
|
-
def send_message(channel, message)
|
63
|
-
request(
|
64
|
-
:post, "channels/#{channel}/messages",
|
65
|
-
{}, { content: message }.to_json
|
66
|
-
)
|
67
|
-
end
|
68
|
-
|
69
|
-
# Joins guild
|
70
|
-
# @param [String] invite Invite code
|
71
|
-
def join(invite)
|
72
|
-
request(
|
73
|
-
:post, "invites/#{invite}",
|
74
|
-
{ x_context_properties: 'eyJsb2NhdGlvbiI6Ik1hcmtkb3duIExpbmsifQ==' },
|
75
|
-
'{}'
|
76
|
-
)
|
77
|
-
end
|
78
|
-
|
79
|
-
# Reacts to a message
|
80
|
-
# @note To use custom emoji, you must encode it in the format name:id with the emoji name and emoji id
|
81
|
-
# @param [String, Integer] channel Channel ID
|
82
|
-
# @param [String, Integer] message Message ID
|
83
|
-
# @param [String] emoji
|
84
|
-
def react(channel, message, emoji)
|
85
|
-
emoji = URI.encode_www_form_component(emoji)
|
86
|
-
|
87
|
-
request(
|
88
|
-
:put,
|
89
|
-
"channels/#{channel}/messages/#{message}/reactions/#{emoji}/@me",
|
90
|
-
{ params: { location: 'Message' } }
|
91
|
-
)
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|