discorb 0.11.0 → 0.11.1
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/Changelog.md +7 -0
- data/lib/discorb/common.rb +1 -1
- data/lib/discorb/gateway.rb +13 -4
- data/lib/discorb/http.rb +12 -7
- data/lib/discorb/integration.rb +1 -1
- data/lib/discorb/rate_limit.rb +12 -13
- 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: 6b979da1f1325d5d9cae229e0262cce1d6cf16b6aca91feba731ec6a0146fe42
|
4
|
+
data.tar.gz: e6e1fcbe4265cfb54828fef5c7e2d6304dd306544e941cb787233ad563d9abaf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bb35c0736b2e549964030103dfb1202ef7711fd3c36323710d3f94631b958a9976f7c111f340d03cf2ed67032a8f74f5165f66b5ff92c59d0628af25b4a95e79
|
7
|
+
data.tar.gz: 01d59859fb5e84beaafdc48e333ba841398a8fe5867c52bb9621b2d676493dbc776297c94e303297ffeef591c7f2e527ea30aaae381323e4ed8e8b1ce632b1ef
|
data/Changelog.md
CHANGED
data/lib/discorb/common.rb
CHANGED
@@ -4,7 +4,7 @@ module Discorb
|
|
4
4
|
# @return [String] The API base URL.
|
5
5
|
API_BASE_URL = "https://discord.com/api/v9"
|
6
6
|
# @return [String] The version of discorb.
|
7
|
-
VERSION = "0.11.
|
7
|
+
VERSION = "0.11.1"
|
8
8
|
# @return [String] The user agent for the bot.
|
9
9
|
USER_AGENT = "DiscordBot (https://discorb-lib.github.io #{VERSION}) Ruby/#{RUBY_VERSION}"
|
10
10
|
|
data/lib/discorb/gateway.rb
CHANGED
@@ -495,6 +495,7 @@ module Discorb
|
|
495
495
|
@connection = connection
|
496
496
|
@zlib_stream = Zlib::Inflate.new(Zlib::MAX_WBITS)
|
497
497
|
@buffer = +""
|
498
|
+
|
498
499
|
while (message = @connection.read)
|
499
500
|
@buffer << message
|
500
501
|
if message.end_with?((+"\x00\x00\xff\xff").force_encoding("ASCII-8BIT"))
|
@@ -505,7 +506,7 @@ module Discorb
|
|
505
506
|
rescue JSON::ParserError
|
506
507
|
@buffer = +""
|
507
508
|
@log.error "Received invalid JSON from gateway."
|
508
|
-
@log.debug data
|
509
|
+
@log.debug "#{data}"
|
509
510
|
else
|
510
511
|
handle_gateway(message)
|
511
512
|
end
|
@@ -524,7 +525,10 @@ module Discorb
|
|
524
525
|
@log.error "Discord WebSocket closed: #{e.message}"
|
525
526
|
connect_gateway(false)
|
526
527
|
end
|
527
|
-
rescue EOFError, Async::Wrapper::Cancelled
|
528
|
+
rescue EOFError, Async::Wrapper::Cancelled, Async::Wrapper::WaitError
|
529
|
+
connect_gateway(false)
|
530
|
+
rescue => e
|
531
|
+
@log.error "Discord WebSocket error: #{e.message}"
|
528
532
|
connect_gateway(false)
|
529
533
|
end
|
530
534
|
end
|
@@ -533,7 +537,7 @@ module Discorb
|
|
533
537
|
def send_gateway(opcode, **value)
|
534
538
|
@connection.write({ op: opcode, d: value }.to_json)
|
535
539
|
@connection.flush
|
536
|
-
@log.debug "Sent message
|
540
|
+
@log.debug "Sent message #{{ op: opcode, d: value }.to_json.gsub(@token, "[Token]")}"
|
537
541
|
end
|
538
542
|
|
539
543
|
def handle_gateway(payload)
|
@@ -568,6 +572,11 @@ module Discorb
|
|
568
572
|
}
|
569
573
|
send_gateway(6, **payload)
|
570
574
|
end
|
575
|
+
when 7
|
576
|
+
@log.info "Received opcode 7, reconnecting"
|
577
|
+
@tasks.map(&:stop)
|
578
|
+
@connection.close
|
579
|
+
connect_gateway(false)
|
571
580
|
when 9
|
572
581
|
@log.warn "Received opcode 9, closed connection"
|
573
582
|
@tasks.map(&:stop)
|
@@ -1024,7 +1033,7 @@ module Discorb
|
|
1024
1033
|
if respond_to?("event_" + event_name.downcase)
|
1025
1034
|
__send__("event_" + event_name.downcase, data)
|
1026
1035
|
else
|
1027
|
-
@log.debug "
|
1036
|
+
@log.debug "#{event_name}\n#{data.inspect}"
|
1028
1037
|
end
|
1029
1038
|
end
|
1030
1039
|
end
|
data/lib/discorb/http.rb
CHANGED
@@ -175,6 +175,7 @@ module Discorb
|
|
175
175
|
def handle_response(method, resp, data, path, body, headers, audit_log_reason, kwargs)
|
176
176
|
case resp.code
|
177
177
|
when "429"
|
178
|
+
@client.log.info("Rate limit exceeded for #{method} #{path}, waiting #{data[:retry_after]} seconds")
|
178
179
|
sleep(data[:retry_after])
|
179
180
|
if body
|
180
181
|
__send__(method, path, body, headers: headers, audit_log_reason: audit_log_reason, **kwargs).wait
|
@@ -227,15 +228,19 @@ module Discorb
|
|
227
228
|
end
|
228
229
|
|
229
230
|
def get_response_data(resp)
|
230
|
-
|
231
|
-
|
231
|
+
begin
|
232
|
+
data = JSON.parse(resp.body, symbolize_names: true)
|
233
|
+
rescue JSON::ParserError, TypeError
|
234
|
+
if resp.body.nil? || resp.body.empty?
|
235
|
+
data = nil
|
236
|
+
else
|
237
|
+
data = resp.body
|
238
|
+
end
|
232
239
|
end
|
233
|
-
|
234
|
-
|
235
|
-
nil
|
236
|
-
else
|
237
|
-
JSON.parse(rd, symbolize_names: true)
|
240
|
+
if resp["Via"].nil? && resp.code == "429" && data.is_a?(String)
|
241
|
+
raise CloudFlareBanError.new(resp, @client)
|
238
242
|
end
|
243
|
+
data
|
239
244
|
end
|
240
245
|
|
241
246
|
def http
|
data/lib/discorb/integration.rb
CHANGED
@@ -80,7 +80,7 @@ module Discorb
|
|
80
80
|
@enable_emoticons = data[:enable_emoticons]
|
81
81
|
@expire_behavior = self.class.expire_behavior[data[:expire_behavior]]
|
82
82
|
@expire_grace_period = data[:expire_grace_period]
|
83
|
-
@user = @client.users[data[:user].
|
83
|
+
@user = @client.users[data[:user][:id]] or Discorb::User.new(@client, data[:user])
|
84
84
|
@account = Account.new(data[:account])
|
85
85
|
@subscriber_count = data[:subscriber_count]
|
86
86
|
@revoked = data[:revoked]
|
data/lib/discorb/rate_limit.rb
CHANGED
@@ -9,8 +9,8 @@ module Discorb
|
|
9
9
|
# @private
|
10
10
|
def initialize(client)
|
11
11
|
@client = client
|
12
|
-
@
|
13
|
-
@
|
12
|
+
@current_ratelimits = {}
|
13
|
+
@path_ratelimit_bucket = {}
|
14
14
|
@global = false
|
15
15
|
end
|
16
16
|
|
@@ -25,24 +25,23 @@ module Discorb
|
|
25
25
|
|
26
26
|
if @global
|
27
27
|
time = b[:reset_at] - Time.now.to_i
|
28
|
-
@client.log.info("
|
28
|
+
@client.log.info("global rate limit reached, waiting #{time} seconds")
|
29
29
|
sleep(time)
|
30
30
|
@global = false
|
31
|
-
|
32
31
|
end
|
33
32
|
|
34
|
-
return unless hash = @
|
33
|
+
return unless hash = @path_ratelimit_bucket[method + path]
|
35
34
|
|
36
|
-
return unless b = @
|
35
|
+
return unless b = @current_ratelimits[hash]
|
37
36
|
|
38
|
-
if b[:reset_at] < Time.now.
|
39
|
-
@
|
37
|
+
if b[:reset_at] < Time.now.to_f
|
38
|
+
@current_ratelimits.delete(hash)
|
40
39
|
return
|
41
40
|
end
|
42
41
|
return if b[:remaining] > 0
|
43
42
|
|
44
|
-
time = b[:reset_at] - Time.now.
|
45
|
-
@client.log.info("
|
43
|
+
time = b[:reset_at] - Time.now.to_f
|
44
|
+
@client.log.info("rate limit for #{method} #{path} reached, waiting #{time} seconds")
|
46
45
|
sleep(time)
|
47
46
|
end
|
48
47
|
|
@@ -59,10 +58,10 @@ module Discorb
|
|
59
58
|
end
|
60
59
|
return unless resp["X-RateLimit-Remaining"]
|
61
60
|
|
62
|
-
@
|
63
|
-
@
|
61
|
+
@path_ratelimit_bucket[method + path] = resp["X-RateLimit-Bucket"]
|
62
|
+
@current_ratelimits[resp["X-RateLimit-Bucket"]] = {
|
64
63
|
remaining: resp["X-RateLimit-Remaining"].to_i,
|
65
|
-
reset_at: resp["X-RateLimit-Reset"].
|
64
|
+
reset_at: Time.now.to_f + resp["X-RateLimit-Reset-After"].to_f,
|
66
65
|
}
|
67
66
|
end
|
68
67
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: discorb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.11.
|
4
|
+
version: 0.11.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- sevenc-nanashi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-10-
|
11
|
+
date: 2021-10-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: async
|