Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjustments #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions lib/discordrb/bot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ class Bot
# @return [Gateway] the underlying {Gateway} object.
attr_reader :gateway

# The number of seconds to wait for unavailable servers since READY
# @return [Integer]
attr_reader :dispatch_timeout

include EventContainer
include Cache

Expand Down Expand Up @@ -113,7 +117,7 @@ class Bot
def initialize(
log_mode: :normal,
token: nil, client_id: nil,
type: nil, name: '', fancy_log: false, suppress_ready: false, parse_self: false,
type: nil, name: '', fancy_log: false, dispatch_timeout: 10, suppress_ready: false, parse_self: false,
shard_id: nil, num_shards: nil, redact_token: true, ignore_bots: false,
compress_mode: :large, intents: :all
)
Expand All @@ -130,6 +134,7 @@ def initialize(
@shard_key = num_shards ? [shard_id, num_shards] : nil

LOGGER.fancy = fancy_log
@dispatch_timeout = dispatch_timeout
@prevent_ready = suppress_ready

@compress_mode = compress_mode
Expand Down Expand Up @@ -1218,8 +1223,8 @@ def process_token(type, token)
end

def handle_dispatch(type, data)
# Check whether there are still unavailable servers and there have been more than 10 seconds since READY
if @unavailable_servers&.positive? && (Time.now - @unavailable_timeout_time) > 10 && !((@intents || 0) & INTENTS[:servers]).zero?
# Check whether there are still unavailable servers and there have been more than dispatch_timeout seconds since READY
if @unavailable_servers&.positive? && (Time.now - @unavailable_timeout_time) > dispatch_timeout && !((@intents || 0) & INTENTS[:servers]).zero?
# The server streaming timed out!
LOGGER.debug("Server streaming timed out with #{@unavailable_servers} servers remaining")
LOGGER.debug('Calling ready now because server loading is taking a long time. Servers may be unavailable due to an outage, or your bot is on very large servers.')
Expand Down