discorb 0.11.0 → 0.11.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3c80c426387c9e5ba44589c5851e7c1a4d54a5de99c82d5b3571c4200dcaf135
4
- data.tar.gz: 2aa6db0900cafe2120793b295b68e5de357e97e0797cd416a06caca9491b09e1
3
+ metadata.gz: 3154cd1b844888bec798cdead182285e335733206758fddea8c2fd8e0015499e
4
+ data.tar.gz: 9d0ba163982a7676045dce791409227f2c99c3e28bce29cae25033b85f7485a5
5
5
  SHA512:
6
- metadata.gz: afe14b35796820b8b7af5baaab6a79a5a770c55d11d30d25b2a9647034658e27346e918be42fb8d4a30edbf27873bd367cf3551cf1b091e82c49150c886ef03e
7
- data.tar.gz: 9c817738b2a4b3763d94182e2b47f583aaa7129a8769cdc9b8f7fc7e10f0656f43183f0d416d72aa20112b6b34addfdd38e36b7710c6405d2f29f658cb238c4c
6
+ metadata.gz: 20ee7dd354fc5be471617ed61367ceb85bad364cd8e2afd95df9c46453665b61c15d387c2bafb36b295836f5cb02f699edfc3118af4fa6c39e30a52f72904e6d
7
+ data.tar.gz: c860a7fa1335a7be40dafa7e9bda5bbfd6a7d7e7790ece875db350b154f3e7ab7f523387b5be4a77f4cae7f43c01b3a726f2c917dd81c2b97502f0097b9b5ecc
@@ -0,0 +1,34 @@
1
+ name: Publish Gem
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - "v*"
7
+ workflow_dispatch:
8
+
9
+ jobs:
10
+ build:
11
+ runs-on: ubuntu-latest
12
+
13
+ steps:
14
+ - uses: actions/checkout@master
15
+
16
+ - name: Set up Ruby
17
+ uses: ruby/setup-ruby@v1
18
+ with:
19
+ ruby-version: "3.0"
20
+
21
+ - name: Setup Release Credentials
22
+ env:
23
+ GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
24
+ run: |
25
+ mkdir -p $HOME/.gem
26
+ touch $HOME/.gem/credentials
27
+ chmod 600 $HOME/.gem/credentials
28
+ echo "---" >$HOME/.gem/credentials
29
+ echo ":github: Bearer ${GITHUB_TOKEN}" >> $HOME/.gem/credentials
30
+ - name: Publish Gem to GitHub Packages
31
+ run: |
32
+ export OWNER=$( echo ${{ github.repository }} | cut -d "/" -f 1 )
33
+ gem build *.gemspec
34
+ gem push --KEY github --host https://rubygems.pkg.github.com/${OWNER} *.gem
data/Changelog.md CHANGED
@@ -4,6 +4,28 @@
4
4
 
5
5
  ## v0.11
6
6
 
7
+ ### v0.11.4
8
+
9
+ - Fix: Fix unpinning messages
10
+
11
+ ### v0.11.3
12
+
13
+ - Add: Add `Snowflake#id` as alias for `Snowflake#to_s`
14
+ - Fix: Fix `Message#unpin`
15
+
16
+ ### v0.11.2
17
+
18
+ - Add: Add `setup` event
19
+ - Fix: Fix gateway resuming
20
+ - Add: Add GitHub Packages
21
+
22
+ ### v0.11.1
23
+
24
+ - Improve: Improve rate limit handling
25
+ - Fix: Fix bug in Integration initalization
26
+ - Change: Change log style
27
+ - Add: Support OP code 7
28
+
7
29
  ### v0.11.0
8
30
 
9
31
  - Add: Improve documents
data/README.md CHANGED
@@ -8,7 +8,7 @@
8
8
 
9
9
  ----
10
10
 
11
- discorb is a Discord API wrapper for Ruby.
11
+ discorb is a Discord API wrapper written in Ruby.
12
12
 
13
13
  ## Installation
14
14
 
@@ -98,7 +98,7 @@ end
98
98
  client.run(ENV["DISCORD_BOT_TOKEN"])
99
99
  ```
100
100
 
101
- Note: You must run `discorb setup` before using slash commands.
101
+ Note you must run `discorb setup` before using slash commands.
102
102
 
103
103
  ## Contributing
104
104
 
data/discorb.gemspec CHANGED
@@ -13,8 +13,6 @@ Gem::Specification.new do |spec|
13
13
  spec.license = "MIT"
14
14
  spec.required_ruby_version = Gem::Requirement.new(">= 3.0.0")
15
15
 
16
- spec.metadata["allowed_push_host"] = "https://rubygems.org"
17
-
18
16
  spec.metadata["homepage_uri"] = spec.homepage
19
17
  spec.metadata["source_code_uri"] = "https://github.com/discorb-lib/discorb"
20
18
  spec.metadata["changelog_uri"] = "https://discorb-lib.github.io/file.Changelog.html"
File without changes
data/docs/cli/setup.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  # discorb setup
4
4
 
5
- This command will setup application commands.
5
+ This command will setup application commands, and call `setup` event.
6
6
 
7
7
  ## Usage
8
8
 
data/docs/cli.md CHANGED
@@ -16,7 +16,7 @@ Currently, discorb has the following commands:
16
16
 
17
17
  | Command | Description |
18
18
  |---------|-------------|
19
- | {file:docs/cli/init.md `init`} | Create a new project. |
19
+ | {file:docs/cli/new.md `new`} | Create a new project. |
20
20
  | {file:docs/cli/irb.md `irb`} | Start an interactive Ruby shell with connected client. |
21
21
  | {file:docs/cli/run.md `run`} | Run a client. |
22
22
  | {file:docs/cli/setup.md `setup`} | Setup application commands. |
data/docs/events.md CHANGED
@@ -88,6 +88,11 @@ Fires when the client is resumed connection.
88
88
  Fires when an error occurs during an event.
89
89
  Defaults to printing the error to stderr, override to handle it yourself.
90
90
 
91
+ #### `setup()`
92
+
93
+ Fires when `discorb setup` is run.
94
+ This is useful for setting up some dependencies, such as the database.
95
+
91
96
  ### Guild events
92
97
 
93
98
  #### `guild_join(guild)`
@@ -482,48 +482,6 @@ module Discorb
482
482
  end
483
483
  end
484
484
 
485
- #
486
- # Fetch the pinned messages in the channel.
487
- # @macro async
488
- # @macro http
489
- #
490
- # @return [Async::Task<Array<Discorb::Message>>] The pinned messages in the channel.
491
- #
492
- def fetch_pins
493
- Async do
494
- _resp, data = @client.http.get("/channels/#{@id}/pins").wait
495
- data.map { |pin| Message.new(@client, pin) }
496
- end
497
- end
498
-
499
- #
500
- # Pin a message in the channel.
501
- # @macro async
502
- # @macro http
503
- #
504
- # @param [Discorb::Message] message The message to pin.
505
- # @param [String] reason The reason of pinning the message.
506
- #
507
- def pin_message(message, reason: nil)
508
- Async do
509
- @client.http.put("/channels/#{@id}/pins/#{message.id}", {}, audit_log_reason: reason).wait
510
- end
511
- end
512
-
513
- #
514
- # Unpin a message in the channel.
515
- # @macro async
516
- # @macro http
517
- #
518
- # @param [Discorb::Message] message The message to unpin.
519
- # @param [String] reason The reason of unpinning the message.
520
- #
521
- def unpin_message(message, reason: nil)
522
- Async do
523
- @client.http.delete("/channels/#{@id}/pins/#{message.id}", {}, audit_log_reason: reason).wait
524
- end
525
- end
526
-
527
485
  #
528
486
  # Start thread in the channel.
529
487
  # @macro async
@@ -446,16 +446,7 @@ module Discorb
446
446
  ::File.open(options[:log_file], "a")
447
447
  end
448
448
  @log.level = options[:log_level].to_sym
449
- @log.colorize_log = case options[:log_color]
450
- when nil
451
- if @log.out == $stdout || @log.out == $stderr
452
- true
453
- else
454
- false
455
- end
456
- when true, false
457
- options[:log_color]
458
- end
449
+ @log.colorize_log = options[:log_color] == nil ? @log.out.isatty : options[:log_color]
459
450
  end
460
451
  end
461
452
  start_client(token)
@@ -468,6 +459,10 @@ module Discorb
468
459
  guild_ids = false
469
460
  end
470
461
  setup_commands(token, guild_ids: guild_ids).wait
462
+ @events[:setup]&.each do |event|
463
+ event.call
464
+ end
465
+ self.on_setup if respond_to? :on_setup
471
466
  end
472
467
  end
473
468
 
@@ -493,7 +488,7 @@ module Discorb
493
488
  @close_condition = Async::Condition.new
494
489
  @main_task = Async do
495
490
  @status = :running
496
- connect_gateway(true).wait
491
+ connect_gateway(false).wait
497
492
  rescue
498
493
  @status = :stopped
499
494
  @close_condition.signal
data/lib/discorb/color.rb CHANGED
@@ -130,6 +130,7 @@ module Discorb
130
130
  #
131
131
  # Create a color from a Discord's color.
132
132
  # Currently these colors are supported:
133
+ #
133
134
  # | Color Name | Hexadecimal |
134
135
  # |------------|------------|
135
136
  # | `:teal` | `#1abc9c` |
@@ -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.0"
7
+ VERSION = "0.11.4"
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
 
@@ -64,6 +64,10 @@ module Discorb
64
64
  # Increment of snowflake.
65
65
  #
66
66
  # @return [Integer] Increment of snowflake.
67
+ # @!attribute [r] id
68
+ # Alias of to_s.
69
+ #
70
+ # @return [String] The snowflake.
67
71
 
68
72
  #
69
73
  # Compares snowflake with other object.
@@ -105,5 +109,7 @@ module Discorb
105
109
  def increment
106
110
  @value & 0xFFF
107
111
  end
112
+
113
+ alias id to_s
108
114
  end
109
115
  end
@@ -481,11 +481,10 @@ module Discorb
481
481
  module Handler
482
482
  private
483
483
 
484
- def connect_gateway(first)
484
+ def connect_gateway(reconnect)
485
485
  @log.info "Connecting to gateway."
486
486
  Async do
487
- @http = HTTP.new(self) if first
488
- @first = first
487
+ @http = HTTP.new(self)
489
488
  _, gateway_response = @http.get("/gateway").wait
490
489
  gateway_url = gateway_response[:url]
491
490
  endpoint = Async::HTTP::Endpoint.parse("#{gateway_url}?v=9&encoding=json&compress=zlib-stream",
@@ -495,36 +494,55 @@ module Discorb
495
494
  @connection = connection
496
495
  @zlib_stream = Zlib::Inflate.new(Zlib::MAX_WBITS)
497
496
  @buffer = +""
498
- while (message = @connection.read)
499
- @buffer << message
500
- if message.end_with?((+"\x00\x00\xff\xff").force_encoding("ASCII-8BIT"))
501
- begin
502
- data = @zlib_stream.inflate(@buffer)
503
- @buffer = +""
504
- message = JSON.parse(data, symbolize_names: true)
505
- rescue JSON::ParserError
506
- @buffer = +""
507
- @log.error "Received invalid JSON from gateway."
508
- @log.debug data
509
- else
510
- handle_gateway(message)
497
+ begin
498
+ while (message = @connection.read)
499
+ @buffer << message
500
+ if message.end_with?((+"\x00\x00\xff\xff").force_encoding("ASCII-8BIT"))
501
+ begin
502
+ data = @zlib_stream.inflate(@buffer)
503
+ @buffer = +""
504
+ message = JSON.parse(data, symbolize_names: true)
505
+ rescue JSON::ParserError
506
+ @buffer = +""
507
+ @log.error "Received invalid JSON from gateway."
508
+ @log.debug "#{data}"
509
+ else
510
+ handle_gateway(message, reconnect)
511
+ end
511
512
  end
512
513
  end
514
+ rescue EOFError, Async::Wrapper::Cancelled, Async::Wrapper::WaitError
515
+ # Ignore
513
516
  end
514
517
  end
515
518
  rescue Protocol::WebSocket::ClosedError => e
516
- case e.message
517
- when "Authentication failed."
518
- @tasks.map(&:stop)
519
- raise ClientError.new("Authentication failed."), cause: nil
520
- when "Discord WebSocket requesting client reconnect."
521
- @log.info "Discord WebSocket requesting client reconnect"
522
- connect_gateway(false)
519
+ @tasks.map(&:stop)
520
+ case e.code
521
+ when 4004
522
+ raise ClientError.new("Authentication failed"), cause: nil
523
+ when 4009
524
+ @log.info "Session timed out, reconnecting."
525
+ connect_gateway(true)
526
+ when 4014
527
+ raise ClientError.new("Disallowed intents were specified"), cause: nil
528
+ when 4002, 4003, 4005, 4007
529
+ raise ClientError.new(<<~EOS), cause: e
530
+ Disconnected from gateway, probably due to library issues.
531
+ #{e.message}
532
+
533
+ Please report this to the library issue tracker.
534
+ https://github.com/discorb-lib/discorb/issues
535
+ EOS
536
+ when 1001
537
+ @log.info "Gateway closed with code 1001, reconnecting."
538
+ connect_gateway(true)
523
539
  else
524
- @log.error "Discord WebSocket closed: #{e.message}"
540
+ @log.error "Discord WebSocket closed with code #{e.code}."
541
+ @log.debug "#{e.message}"
525
542
  connect_gateway(false)
526
543
  end
527
- rescue EOFError, Async::Wrapper::Cancelled
544
+ rescue => e
545
+ @log.error "Discord WebSocket error: #{e.message}"
528
546
  connect_gateway(false)
529
547
  end
530
548
  end
@@ -533,18 +551,26 @@ module Discorb
533
551
  def send_gateway(opcode, **value)
534
552
  @connection.write({ op: opcode, d: value }.to_json)
535
553
  @connection.flush
536
- @log.debug "Sent message: #{{ op: opcode, d: value }.to_json.gsub(@token, "[Token]")}"
554
+ @log.debug "Sent message #{{ op: opcode, d: value }.to_json.gsub(@token, "[Token]")}"
537
555
  end
538
556
 
539
- def handle_gateway(payload)
557
+ def handle_gateway(payload, reconnect)
540
558
  Async do |task|
541
559
  data = payload[:d]
542
560
  @last_s = payload[:s] if payload[:s]
543
- @log.debug "Received message with opcode #{payload[:op]} from gateway: #{data}"
561
+ @log.debug "Received message with opcode #{payload[:op]} from gateway:"
562
+ @log.debug "#{payload.to_json.gsub(@token, "[Token]")}"
544
563
  case payload[:op]
545
564
  when 10
546
565
  @heartbeat_interval = data[:heartbeat_interval]
547
- if @first
566
+ if reconnect
567
+ payload = {
568
+ token: @token,
569
+ session_id: @session_id,
570
+ seq: @last_s,
571
+ }
572
+ send_gateway(6, **payload)
573
+ else
548
574
  payload = {
549
575
  token: @token,
550
576
  intents: @intents.value,
@@ -553,33 +579,22 @@ module Discorb
553
579
  }
554
580
  payload[:presence] = @identify_presence if @identify_presence
555
581
  send_gateway(2, **payload)
556
- Async do
557
- sleep 2
558
- next unless @uncached_guilds.nil?
559
-
560
- raise ClientError, "Failed to connect to gateway.\nHint: This usually means that your intents are invalid."
561
- exit 1
562
- end
563
- else
564
- payload = {
565
- token: @token,
566
- session_id: @session_id,
567
- seq: @last_s,
568
- }
569
- send_gateway(6, **payload)
570
582
  end
583
+ when 7
584
+ @log.info "Received opcode 7, reconnecting"
585
+ @tasks.map(&:stop)
571
586
  when 9
572
587
  @log.warn "Received opcode 9, closed connection"
573
588
  @tasks.map(&:stop)
574
589
  if data
575
590
  @log.info "Connection is resumable, reconnecting"
576
591
  @connection.close
577
- connect_gateway(false)
592
+ connect_gateway(true)
578
593
  else
579
594
  @log.info "Connection is not resumable, reconnecting with opcode 2"
580
- sleep(2)
581
595
  @connection.close
582
- connect_gateway(true)
596
+ sleep(2)
597
+ connect_gateway(false)
583
598
  end
584
599
  when 11
585
600
  @log.debug "Received opcode 11"
@@ -1024,7 +1039,7 @@ module Discorb
1024
1039
  if respond_to?("event_" + event_name.downcase)
1025
1040
  __send__("event_" + event_name.downcase, data)
1026
1041
  else
1027
- @log.debug "Received unknown event: #{event_name}\n#{data.inspect}"
1042
+ @log.debug "#{event_name}\n#{data.inspect}"
1028
1043
  end
1029
1044
  end
1030
1045
  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
- if resp["Via"].nil? && resp.code == "429"
231
- raise CloudFlareBanError.new(resp, @client)
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
- rd = resp.body
234
- if rd.nil? || rd.empty?
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
@@ -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].to_i]
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]
@@ -458,6 +458,7 @@ module Discorb
458
458
  @interaction_type = 4
459
459
  @interaction_name = :auto_complete
460
460
 
461
+ # @private
461
462
  def _set_data(data)
462
463
  super
463
464
  Sync do
@@ -511,6 +512,7 @@ module Discorb
511
512
  end
512
513
  end
513
514
 
515
+ # @private
514
516
  def send_complete_result(val)
515
517
  @client.http.post("/interactions/#{@id}/#{@token}/callback", {
516
518
  type: 8,
data/lib/discorb/log.rb CHANGED
@@ -65,10 +65,11 @@ module Discorb
65
65
  return
66
66
  end
67
67
 
68
+ time = Time.now.iso8601
68
69
  if @colorize_log
69
- @out.puts("\e[2;90m[#{Time.now.iso8601}] #{color}#{name}\e[m -- #{message}")
70
+ @out.puts("\e[90m#{time}\e[0m #{color}#{name.ljust(5)}\e[0m #{message}")
70
71
  else
71
- @out.puts("[#{Time.now.iso8601}] #{name} -- #{message}")
72
+ @out.puts("#{time} #{name.ljust(5)} #{message}")
72
73
  end
73
74
  end
74
75
  end
@@ -455,7 +455,9 @@ module Discorb
455
455
  # @macro async
456
456
  # @macro http
457
457
  #
458
- def unpin
458
+ # @param [String] reason The reason for unpinning the message.
459
+ #
460
+ def unpin(reason: nil)
459
461
  Async do
460
462
  channel.unpin_message(self, reason: reason).wait
461
463
  end
@@ -142,6 +142,48 @@ module Discorb
142
142
  end
143
143
  end
144
144
 
145
+ #
146
+ # Fetch the pinned messages in the channel.
147
+ # @macro async
148
+ # @macro http
149
+ #
150
+ # @return [Async::Task<Array<Discorb::Message>>] The pinned messages in the channel.
151
+ #
152
+ def fetch_pins
153
+ Async do
154
+ _resp, data = @client.http.get("/channels/#{channel_id.wait}/pins").wait
155
+ data.map { |pin| Message.new(@client, pin) }
156
+ end
157
+ end
158
+
159
+ #
160
+ # Pin a message in the channel.
161
+ # @macro async
162
+ # @macro http
163
+ #
164
+ # @param [Discorb::Message] message The message to pin.
165
+ # @param [String] reason The reason of pinning the message.
166
+ #
167
+ def pin_message(message, reason: nil)
168
+ Async do
169
+ @client.http.put("/channels/#{channel_id.wait}/pins/#{message.id}", {}, audit_log_reason: reason).wait
170
+ end
171
+ end
172
+
173
+ #
174
+ # Unpin a message in the channel.
175
+ # @macro async
176
+ # @macro http
177
+ #
178
+ # @param [Discorb::Message] message The message to unpin.
179
+ # @param [String] reason The reason of unpinning the message.
180
+ #
181
+ def unpin_message(message, reason: nil)
182
+ Async do
183
+ @client.http.delete("/channels/#{channel_id.wait}/pins/#{message.id}", audit_log_reason: reason).wait
184
+ end
185
+ end
186
+
145
187
  #
146
188
  # Trigger the typing indicator in the channel.
147
189
  # @macro async
@@ -9,8 +9,8 @@ module Discorb
9
9
  # @private
10
10
  def initialize(client)
11
11
  @client = client
12
- @ratelimit_hash = {}
13
- @path_ratelimit_hash = {}
12
+ @current_ratelimits = {}
13
+ @path_ratelimit_bucket = {}
14
14
  @global = false
15
15
  end
16
16
 
@@ -24,25 +24,24 @@ module Discorb
24
24
  return if path.start_with?("https://")
25
25
 
26
26
  if @global
27
- time = b[:reset_at] - Time.now.to_i
28
- @client.log.info("Global ratelimit reached, waiting #{time} seconds")
27
+ time = b[:reset_at] - Time.now.to_f
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 = @path_ratelimit_hash[method + path]
33
+ return unless hash = @path_ratelimit_bucket[method + path]
35
34
 
36
- return unless b = @ratelimit_hash[hash]
35
+ return unless b = @current_ratelimits[hash]
37
36
 
38
- if b[:reset_at] < Time.now.to_i
39
- @ratelimit_hash.delete(hash)
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.to_i
45
- @client.log.info("Ratelimit reached, waiting #{time} seconds")
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
 
@@ -55,14 +54,14 @@ module Discorb
55
54
  #
56
55
  def save(method, path, resp)
57
56
  if resp["X-Ratelimit-Global"] == "true"
58
- @global = Time.now.to_i + JSON.parse(resp.body, symbolize_names: true)[:retry_after]
57
+ @global = Time.now.to_f + JSON.parse(resp.body, symbolize_names: true)[:retry_after]
59
58
  end
60
59
  return unless resp["X-RateLimit-Remaining"]
61
60
 
62
- @path_ratelimit_hash[method + path] = resp["X-RateLimit-Bucket"]
63
- @ratelimit_hash[resp["X-RateLimit-Bucket"]] = {
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"].to_i,
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.0
4
+ version: 0.11.4
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-10 00:00:00.000000000 Z
11
+ date: 2021-10-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: async
@@ -79,6 +79,7 @@ files:
79
79
  - ".github/ISSUE_TEMPLATE/feature_request.md"
80
80
  - ".github/workflows/build_main.yml"
81
81
  - ".github/workflows/build_version.yml"
82
+ - ".github/workflows/package_register.yml"
82
83
  - ".gitignore"
83
84
  - ".yardopts"
84
85
  - Changelog.md
@@ -103,8 +104,8 @@ files:
103
104
  - docs/assets/08_hello_once.png
104
105
  - docs/assets/unused_ping_pong.png
105
106
  - docs/cli.md
106
- - docs/cli/init.md
107
107
  - docs/cli/irb.md
108
+ - docs/cli/new.md
108
109
  - docs/cli/run.md
109
110
  - docs/cli/setup.md
110
111
  - docs/events.md
@@ -191,7 +192,6 @@ homepage: https://github.com/discorb-lib/discorb
191
192
  licenses:
192
193
  - MIT
193
194
  metadata:
194
- allowed_push_host: https://rubygems.org
195
195
  homepage_uri: https://github.com/discorb-lib/discorb
196
196
  source_code_uri: https://github.com/discorb-lib/discorb
197
197
  changelog_uri: https://discorb-lib.github.io/file.Changelog.html