discorb 0.7.3 → 0.7.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Changelog.md +13 -1
- data/lib/discorb/common.rb +1 -1
- data/lib/discorb/gateway.rb +44 -29
- 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: a2d341757256d728ba6bb750b068a06f859e5d796d9e44bb1e4d616f4b439444
|
4
|
+
data.tar.gz: 3d4f6aaf740f8366a7f714011f60688871a9b4698bce9a37b6fd4c35cd31ab10
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dd2620d3de3cf9e1b024701a9312d63a0990ac5360c9b5e65d096cc3792dd81effb79b26577812e6ac229f155d53ccf4a8f5aa093103e56d05c677eb8904936b
|
7
|
+
data.tar.gz: a04ab3bb0982d21d0d40d132b0b217ee4b95b214c848d970229e8f66bf0a4d5e2d07dce2006822ab07954f5a0de343a7769b1e36181778ccd501e5a02b6456fb
|
data/Changelog.md
CHANGED
@@ -190,4 +190,16 @@ end
|
|
190
190
|
|
191
191
|
## 0.7.3
|
192
192
|
|
193
|
-
- Add: Improve `discorb init`
|
193
|
+
- Add: Improve `discorb init`
|
194
|
+
|
195
|
+
## 0.7.4 (yanked)
|
196
|
+
|
197
|
+
- Fix: Fix disconnected client
|
198
|
+
|
199
|
+
## 0.7.5 (yanked)
|
200
|
+
|
201
|
+
- Fix: Fix critical error
|
202
|
+
|
203
|
+
## 0.7.6
|
204
|
+
|
205
|
+
- Fix: Fix heartbeating error
|
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.7.
|
7
|
+
VERSION = "0.7.6"
|
8
8
|
# @return [String] The user agent for the bot.
|
9
9
|
USER_AGENT = "DiscordBot (https://github.com/discorb-lib/discorb #{VERSION}) Ruby/#{RUBY_VERSION}"
|
10
10
|
|
data/lib/discorb/gateway.rb
CHANGED
@@ -488,7 +488,7 @@ module Discorb
|
|
488
488
|
_, gateway_response = @http.get("/gateway").wait
|
489
489
|
gateway_url = gateway_response[:url]
|
490
490
|
endpoint = Async::HTTP::Endpoint.parse("#{gateway_url}?v=9&encoding=json&compress=zlib-stream",
|
491
|
-
|
491
|
+
alpn_protocols: Async::HTTP::Protocol::HTTP11.names)
|
492
492
|
begin
|
493
493
|
Async::WebSocket::Client.connect(endpoint, headers: [["User-Agent", Discorb::USER_AGENT]], handler: RawConnection) do |connection|
|
494
494
|
@connection = connection
|
@@ -510,7 +510,9 @@ module Discorb
|
|
510
510
|
raise ClientError.new("Authentication failed."), cause: nil
|
511
511
|
when "Discord WebSocket requesting client reconnect."
|
512
512
|
@log.info "Discord WebSocket requesting client reconnect"
|
513
|
-
|
513
|
+
connect_gateway(false)
|
514
|
+
else
|
515
|
+
@log.error "Discord WebSocket closed: #{e.message}"
|
514
516
|
connect_gateway(false)
|
515
517
|
end
|
516
518
|
rescue EOFError, Async::Wrapper::Cancelled
|
@@ -579,15 +581,18 @@ module Discorb
|
|
579
581
|
end
|
580
582
|
end
|
581
583
|
|
582
|
-
def handle_heartbeat
|
584
|
+
def handle_heartbeat
|
583
585
|
Async do |task|
|
586
|
+
interval = @heartbeat_interval
|
584
587
|
sleep((interval / 1000.0 - 1) * rand)
|
585
588
|
loop do
|
586
|
-
@
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
589
|
+
unless @connection.closed?
|
590
|
+
@heartbeat_before = Time.now.to_f
|
591
|
+
@connection.write({ op: 1, d: @last_s }.to_json)
|
592
|
+
@connection.flush
|
593
|
+
@log.debug "Sent opcode 1."
|
594
|
+
@log.debug "Waiting for heartbeat."
|
595
|
+
end
|
591
596
|
sleep(interval / 1000.0 - 1)
|
592
597
|
end
|
593
598
|
end
|
@@ -609,7 +614,7 @@ module Discorb
|
|
609
614
|
dispatch(:ready)
|
610
615
|
@log.info("Successfully connected to Discord.")
|
611
616
|
end
|
612
|
-
@tasks << handle_heartbeat
|
617
|
+
@tasks << handle_heartbeat
|
613
618
|
when "GUILD_CREATE"
|
614
619
|
if @uncached_guilds.include?(data[:id])
|
615
620
|
Guild.new(self, data, true)
|
@@ -839,12 +844,12 @@ module Discorb
|
|
839
844
|
dispatch(:voice_state_update, old, current)
|
840
845
|
if old&.channel != current&.channel
|
841
846
|
dispatch(:voice_channel_update, old, current)
|
842
|
-
case [old&.channel
|
843
|
-
|
847
|
+
case [old&.channel.nil?, current&.channel.nil?]
|
848
|
+
when [true, false]
|
844
849
|
dispatch(:voice_channel_connect, current)
|
845
|
-
|
850
|
+
when [false, true]
|
846
851
|
dispatch(:voice_channel_disconnect, old)
|
847
|
-
|
852
|
+
when [false, false]
|
848
853
|
dispatch(:voice_channel_move, old, current)
|
849
854
|
end
|
850
855
|
end
|
@@ -980,9 +985,9 @@ module Discorb
|
|
980
985
|
dispatch(:reaction_add, ReactionEvent.new(self, data))
|
981
986
|
when "MESSAGE_REACTION_REMOVE"
|
982
987
|
if (target_message = @messages[data[:message_id]]) &&
|
983
|
-
|
984
|
-
|
985
|
-
|
988
|
+
(target_reaction = target_message.reactions.find do |r|
|
989
|
+
data[:emoji][:id].nil? ? r.emoji.name == data[:emoji][:name] : r.emoji.id == data[:emoji][:id]
|
990
|
+
end)
|
986
991
|
target_reaction.instance_variable_set(:@count, target_reaction.count - 1)
|
987
992
|
target_message.reactions.delete(target_reaction) if target_reaction.count.zero?
|
988
993
|
end
|
@@ -994,7 +999,7 @@ module Discorb
|
|
994
999
|
dispatch(:reaction_remove_all, ReactionRemoveAllEvent.new(self, data))
|
995
1000
|
when "MESSAGE_REACTION_REMOVE_EMOJI"
|
996
1001
|
if (target_message = @messages[data[:message_id]]) &&
|
997
|
-
|
1002
|
+
(target_reaction = target_message.reactions.find { |r| data[:emoji][:id].nil? ? r.name == data[:emoji][:name] : r.id == data[:emoji][:id] })
|
998
1003
|
target_message.reactions.delete(target_reaction)
|
999
1004
|
end
|
1000
1005
|
dispatch(:reaction_remove_emoji, ReactionRemoveEmojiEvent.new(data))
|
@@ -1017,25 +1022,35 @@ module Discorb
|
|
1017
1022
|
end
|
1018
1023
|
end
|
1019
1024
|
end
|
1020
|
-
|
1025
|
+
|
1021
1026
|
#
|
1022
1027
|
# A class for connecting websocket with raw bytes data.
|
1023
1028
|
# @private
|
1024
1029
|
#
|
1025
|
-
class RawConnection < Async::WebSocket::Connection
|
1026
|
-
def initialize(
|
1030
|
+
class RawConnection < Async::WebSocket::Connection
|
1031
|
+
def initialize(*, **)
|
1027
1032
|
super
|
1033
|
+
@closed = false
|
1028
1034
|
end
|
1029
|
-
|
1030
|
-
|
1031
|
-
|
1035
|
+
|
1036
|
+
def closed?
|
1037
|
+
@closed
|
1038
|
+
end
|
1039
|
+
|
1040
|
+
def close
|
1041
|
+
super
|
1042
|
+
@closed = true
|
1043
|
+
end
|
1044
|
+
|
1045
|
+
def parse(buffer)
|
1046
|
+
# noop
|
1032
1047
|
buffer.to_s
|
1033
|
-
|
1034
|
-
|
1035
|
-
|
1036
|
-
|
1048
|
+
end
|
1049
|
+
|
1050
|
+
def dump(object)
|
1051
|
+
# noop
|
1037
1052
|
object.to_s
|
1038
|
-
|
1053
|
+
end
|
1039
1054
|
end
|
1040
1055
|
end
|
1041
|
-
end
|
1056
|
+
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.7.
|
4
|
+
version: 0.7.6
|
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-09-
|
11
|
+
date: 2021-09-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: async
|