dsu3 1.1.2 → 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.rb +1 -1
- data/lib/dsu3/data/channel.rb +1 -1
- data/lib/dsu3/data/guild.rb +1 -1
- data/lib/dsu3/data/invite.rb +1 -1
- data/lib/dsu3/data/message.rb +3 -2
- data/lib/dsu3/net.rb +19 -9
- 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.rb
CHANGED
@@ -42,7 +42,7 @@ module DSU3
|
|
42
42
|
rescue RestClient::ExceptionWithResponse => e
|
43
43
|
begin
|
44
44
|
data = JSON.parse(e.response.body)
|
45
|
-
raise DSU3::RateLimitError('ratelimit exceeded', data['retry_after']) if e.is_a?(RestClient::TooManyRequests)
|
45
|
+
raise DSU3::RateLimitError.new('ratelimit exceeded', data['retry_after']) if e.is_a?(RestClient::TooManyRequests)
|
46
46
|
raise DSU3::CodeError, "#{data['code']}: #{data['message']}"
|
47
47
|
rescue JSON::ParserError
|
48
48
|
raise e
|
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
|
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
21
|
end
|
data/lib/dsu3/net.rb
CHANGED
@@ -5,33 +5,43 @@ 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]
|
24
|
+
|
25
|
+
mutex = opts[:seq] ? Mutex.new : nil
|
22
26
|
|
23
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
43
|
end
|
34
|
-
end.
|
44
|
+
end.join(&:map)
|
35
45
|
end
|
36
46
|
|
37
47
|
# I'm too lazy to try to document it
|
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
|