discorb 0.15.1 → 0.16.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Changelog.md +9 -0
- data/docs/events.md +21 -5
- data/examples/simple/rolepanel.rb +1 -1
- data/examples/simple/shard.rb +17 -0
- data/lib/discorb/app_command/handler.rb +1 -1
- data/lib/discorb/channel.rb +1 -1
- data/lib/discorb/client.rb +133 -53
- data/lib/discorb/common.rb +1 -1
- data/lib/discorb/exe/new.rb +5 -5
- data/lib/discorb/exe/run.rb +1 -15
- data/lib/discorb/gateway.rb +180 -142
- data/lib/discorb/http.rb +2 -2
- data/lib/discorb/interaction/autocomplete.rb +2 -2
- data/lib/discorb/interaction/command.rb +2 -2
- data/lib/discorb/interaction/components.rb +1 -1
- data/lib/discorb/interaction/root.rb +1 -1
- data/lib/discorb/rate_limit.rb +2 -2
- data/lib/discorb/shard.rb +74 -0
- data/lib/discorb.rb +2 -2
- data/sig/discorb.rbs +7234 -6850
- metadata +4 -3
- data/lib/discorb/log.rb +0 -81
@@ -100,7 +100,7 @@ module Discorb
|
|
100
100
|
interaction = klass.make_interaction(client, data) if !klass.interaction_type.nil? && klass.interaction_type == data[:type]
|
101
101
|
end
|
102
102
|
if interaction.nil?
|
103
|
-
client.
|
103
|
+
client.logger.warn("Unknown interaction type #{data[:type]}, initialized Interaction")
|
104
104
|
interaction = Interaction.new(client, data)
|
105
105
|
end
|
106
106
|
interaction
|
data/lib/discorb/rate_limit.rb
CHANGED
@@ -32,7 +32,7 @@ module Discorb
|
|
32
32
|
# return if path.url.start_with?("https://")
|
33
33
|
if @global && @global > Time.now.to_f
|
34
34
|
time = @global - Time.now.to_f
|
35
|
-
@client.
|
35
|
+
@client.logger.info("global rate limit reached, waiting #{time} seconds")
|
36
36
|
sleep(time)
|
37
37
|
@global = false
|
38
38
|
end
|
@@ -48,7 +48,7 @@ module Discorb
|
|
48
48
|
return if (bucket[:remaining]).positive?
|
49
49
|
|
50
50
|
time = bucket[:reset_at] - Time.now.to_f
|
51
|
-
@client.
|
51
|
+
@client.logger.info("rate limit for #{path.identifier} with #{path.major_param} reached, waiting #{time.round(4)} seconds")
|
52
52
|
sleep(time)
|
53
53
|
end
|
54
54
|
|
@@ -0,0 +1,74 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Discorb
|
4
|
+
#
|
5
|
+
# Represents a shard.
|
6
|
+
#
|
7
|
+
class Shard
|
8
|
+
# @return [Integer] The ID of the shard.
|
9
|
+
attr_reader :id
|
10
|
+
# @return [Thread] The thread of the shard.
|
11
|
+
attr_reader :thread
|
12
|
+
# @return [Logger] The logger of the shard.
|
13
|
+
attr_reader :logger
|
14
|
+
# @private
|
15
|
+
# @return [Integer] The internal index of the shard.
|
16
|
+
attr_reader :index
|
17
|
+
# @private
|
18
|
+
attr_accessor :status, :connection, :session_id, :next_shard, :main_task
|
19
|
+
|
20
|
+
#
|
21
|
+
# Initializes a new shard.
|
22
|
+
# @private
|
23
|
+
#
|
24
|
+
# @param [Discorb::Client] client The client.
|
25
|
+
# @param [Integer] id The ID of the shard.
|
26
|
+
# @param [Integer] count The number of shards.
|
27
|
+
# @param [Integer] index The index of the shard.
|
28
|
+
#
|
29
|
+
def initialize(client, id, count, index)
|
30
|
+
@client = client
|
31
|
+
@id = id
|
32
|
+
@shard_count = count
|
33
|
+
@status = :idle
|
34
|
+
@index = index
|
35
|
+
@session_id = nil
|
36
|
+
@next_shard = nil
|
37
|
+
@main_task = nil
|
38
|
+
@logger = client.logger.dup.tap { |l| l.progname = "discorb: shard #{id}" }
|
39
|
+
@thread = Thread.new do
|
40
|
+
Thread.current.thread_variable_set("shard_id", id)
|
41
|
+
Thread.current.thread_variable_set("shard", self)
|
42
|
+
if @index.positive?
|
43
|
+
Thread.stop
|
44
|
+
sleep 5 # Somehow discord disconnects the shard without a little sleep.
|
45
|
+
end
|
46
|
+
client.send(:main_loop, id)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
#
|
51
|
+
# Starts the shard.
|
52
|
+
#
|
53
|
+
# @return [void]
|
54
|
+
#
|
55
|
+
def start
|
56
|
+
@thread.wakeup
|
57
|
+
end
|
58
|
+
|
59
|
+
#
|
60
|
+
# Stops the shard.
|
61
|
+
#
|
62
|
+
# @return [void]
|
63
|
+
#
|
64
|
+
def close!
|
65
|
+
@status = :closed
|
66
|
+
@main_task&.stop
|
67
|
+
@thread.kill
|
68
|
+
end
|
69
|
+
|
70
|
+
def inspect
|
71
|
+
"#<#{self.class} #{id}/#{@shard_count} #{@status}>"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
data/lib/discorb.rb
CHANGED
@@ -45,10 +45,10 @@ require_order = %w[common flag dictionary error rate_limit http intents emoji_ta
|
|
45
45
|
%w[message_meta allowed_mentions] +
|
46
46
|
%w[user member guild emoji channel embed message] +
|
47
47
|
%w[application audit_logs color components event event_handler] +
|
48
|
-
%w[attachment guild_template image integration interaction invite
|
48
|
+
%w[attachment guild_template image integration interaction invite permission] +
|
49
49
|
%w[presence reaction role sticker utils voice_state webhook] +
|
50
50
|
%w[gateway_requests gateway app_command] +
|
51
|
-
%w[asset extension client extend]
|
51
|
+
%w[asset extension shard client extend]
|
52
52
|
require_order.each do |name|
|
53
53
|
require_relative "discorb/#{name}.rb"
|
54
54
|
end
|