dsu3 1.1.0 → 1.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 +4 -4
- data/lib/dsu3/api/message.rb +1 -1
- data/lib/dsu3/api/user.rb +1 -1
- data/lib/dsu3/api.rb +7 -11
- data/lib/dsu3/data/channel.rb +2 -2
- data/lib/dsu3/data/guild.rb +2 -2
- data/lib/dsu3/data/invite.rb +2 -2
- data/lib/dsu3/data/message.rb +4 -3
- data/lib/dsu3/data.rb +3 -1
- data/lib/dsu3/dobject.rb +1 -1
- data/lib/dsu3/errors.rb +1 -1
- data/lib/dsu3/net.rb +22 -12
- data/lib/dsu3/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cab6805b66145e0cd335d4431b7d16146ecc05b119159eaf741d2cb986c9bd7d
|
4
|
+
data.tar.gz: 11c4787411fb7fb0210e8e2599f8d1d3205745447d0ba380963e8687837e6497
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 05fd5a369ad65fe3fe4330ee216b4108f894695964211389c16d3996c7c428a2e387eda909f3e96689511112f39fe526777b25053d3fd493958d67b13c85ccfb
|
7
|
+
data.tar.gz: aad9ef63b68458829d85845015d2f70e8f93611d85fc4e2e86f19136cccbf1cbf213d764be3a15b512c86c8f42d882dba653c4c121f84b7d63088fbee5028257
|
data/lib/dsu3/api/message.rb
CHANGED
data/lib/dsu3/api/user.rb
CHANGED
data/lib/dsu3/api.rb
CHANGED
@@ -15,8 +15,6 @@ module DSU3
|
|
15
15
|
module API
|
16
16
|
API_BASE = 'https://discord.com/api/v9/'
|
17
17
|
|
18
|
-
@ratelimits = []
|
19
|
-
|
20
18
|
module_function
|
21
19
|
|
22
20
|
# Makes an API request without any error handling
|
@@ -40,16 +38,14 @@ module DSU3
|
|
40
38
|
# @param (see #raw_request)
|
41
39
|
# @return (see #raw_request)
|
42
40
|
def request(...)
|
41
|
+
raw_request(...)
|
42
|
+
rescue RestClient::ExceptionWithResponse => e
|
43
43
|
begin
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
raise DSU3::CodeError.new("#{data['code']}: #{data['message']}")
|
50
|
-
rescue JSON::ParserError
|
51
|
-
raise e
|
52
|
-
end
|
44
|
+
data = JSON.parse(e.response.body)
|
45
|
+
raise DSU3::RateLimitError.new('ratelimit exceeded', data['retry_after']) if e.is_a?(RestClient::TooManyRequests)
|
46
|
+
raise DSU3::CodeError, "#{data['code']}: #{data['message']}"
|
47
|
+
rescue JSON::ParserError
|
48
|
+
raise e
|
53
49
|
end
|
54
50
|
end
|
55
51
|
end
|
data/lib/dsu3/data/channel.rb
CHANGED
@@ -5,7 +5,7 @@ module DSU3
|
|
5
5
|
class Channel < DObject
|
6
6
|
# Types text into a channel
|
7
7
|
def type
|
8
|
-
@net.request(
|
8
|
+
@net.request(loop: true, cooldown: 9) { DSU3::API::Channel.type(_1, @id) }
|
9
9
|
end
|
10
10
|
|
11
11
|
# Sends a message to a channel
|
@@ -27,7 +27,7 @@ module DSU3
|
|
27
27
|
# Returns Message instance
|
28
28
|
# @param [String, Integer] message Message ID
|
29
29
|
def message(message_id)
|
30
|
-
DSU3::Message.new(
|
30
|
+
DSU3::Message.new(self, message_id)
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
data/lib/dsu3/data/guild.rb
CHANGED
data/lib/dsu3/data/invite.rb
CHANGED
data/lib/dsu3/data/message.rb
CHANGED
@@ -13,8 +13,9 @@ module DSU3
|
|
13
13
|
# Reacts to a message
|
14
14
|
# @note To use custom emoji, you must encode it in the format name:id with the emoji name and emoji id
|
15
15
|
# @param [String] emoji
|
16
|
-
|
17
|
-
|
16
|
+
# @param [Integer] cooldown
|
17
|
+
def react(emoji, cooldown = 0)
|
18
|
+
@net.request(seq: true, cooldown: cooldown) { DSU3::API::Message.react(_1, @channel_id, @id, emoji) }
|
18
19
|
end
|
19
20
|
end
|
20
|
-
end
|
21
|
+
end
|
data/lib/dsu3/data.rb
CHANGED
data/lib/dsu3/dobject.rb
CHANGED
data/lib/dsu3/errors.rb
CHANGED
data/lib/dsu3/net.rb
CHANGED
@@ -5,37 +5,47 @@ require 'dsu3/data'
|
|
5
5
|
module DSU3
|
6
6
|
# Class used to manage multiple bots
|
7
7
|
class Net
|
8
|
-
attr_reader :tokens, :mutex
|
9
|
-
|
10
8
|
# @param [Array] tokens List of bot tokens
|
11
9
|
def initialize(*tokens)
|
12
10
|
raise 'There must be at least one token' if tokens.empty?
|
13
11
|
|
14
|
-
@tokens = tokens
|
15
|
-
@mutex = Mutex.new
|
12
|
+
@tokens = tokens.uniq
|
16
13
|
end
|
17
14
|
|
18
|
-
#
|
15
|
+
# Make Discord API calls
|
19
16
|
# @param [Hash] opts Options
|
17
|
+
# @option opts [Bool] :seq Whether we have to make API calls consecutively
|
18
|
+
# @option opts [Bool] :loop If threads should loop
|
19
|
+
# @option opts [Integer, Float] :cooldown Cooldown between API calls
|
20
20
|
def request(opts = {})
|
21
|
-
opts = {
|
21
|
+
opts = { seq: false, loop: false, cooldown: 0 }.merge(opts)
|
22
|
+
|
23
|
+
raise 'sequential requests do not support looping' if opts[:seq] && opts[:loop]
|
22
24
|
|
23
|
-
|
25
|
+
mutex = opts[:seq] ? Mutex.new : nil
|
26
|
+
|
27
|
+
@tokens.map do |token|
|
24
28
|
Thread.new do
|
25
29
|
begin
|
26
|
-
|
30
|
+
mutex&.lock
|
31
|
+
|
32
|
+
yield token
|
27
33
|
sleep(opts[:cooldown])
|
34
|
+
|
35
|
+
mutex&.unlock
|
28
36
|
rescue DSU3::RateLimitError => e
|
37
|
+
mutex&.unlock
|
38
|
+
|
29
39
|
DSU3::LOGGER.warn('ratelimit exceeded')
|
30
|
-
|
40
|
+
sleep(e.retry_after)
|
31
41
|
retry
|
32
42
|
end while opts[:loop]
|
33
|
-
end
|
34
|
-
end
|
43
|
+
end
|
44
|
+
end.join(&:map)
|
35
45
|
end
|
36
46
|
|
37
47
|
# I'm too lazy to try to document it
|
38
|
-
%w
|
48
|
+
%w[channel guild invite].each do |s|
|
39
49
|
define_method s do |id|
|
40
50
|
DSU3.const_get(s.capitalize).new(self, id)
|
41
51
|
end
|
data/lib/dsu3/version.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: 1.
|
4
|
+
version: 1.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-08-
|
11
|
+
date: 2022-08-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|