From fdae47e2751c8089a1e8382a58cca74d1be934b5 Mon Sep 17 00:00:00 2001 From: biqqles Date: Wed, 20 Jul 2022 23:59:16 +0100 Subject: [PATCH 1/3] fix: improve help message for disallowed intents --- lib/discordrb/gateway.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/discordrb/gateway.rb b/lib/discordrb/gateway.rb index 4b4cf9bbe..bdee06243 100644 --- a/lib/discordrb/gateway.rb +++ b/lib/discordrb/gateway.rb @@ -807,9 +807,12 @@ def handle_close(e) if e.code == 4014 LOGGER.error(<<~ERROR) - You attempted to identify with privileged intents that your bot is not authorized to use - Please enable the privileged intents on the bot page of your application on the discord developer page. - Read more here https://discord.com/developers/docs/topics/gateway#privileged-intents + + Your bot attempted to identify with privileged intents that it is not authorized to use. + You must either enable these for your application on the Discord Developer Portal, or + set the intents: parameter of Bot#initialize to request only the intents that you need. + Read more here: https://discord.com/developers/docs/topics/gateway#privileged-intents + https://drb.shardlab.dev/main/Discordrb/Bot.html#initialize-instance_method ERROR end From 70c9287376412a7aa752ed6f3640bb39ecad59a6 Mon Sep 17 00:00:00 2001 From: biqqles Date: Thu, 21 Jul 2022 17:38:35 +0100 Subject: [PATCH 2/3] fix: clarify log messages for gateway connection --- lib/discordrb/gateway.rb | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/lib/discordrb/gateway.rb b/lib/discordrb/gateway.rb index bdee06243..202b8b51f 100644 --- a/lib/discordrb/gateway.rb +++ b/lib/discordrb/gateway.rb @@ -166,7 +166,7 @@ def run_async @ws_thread = Thread.new do Thread.current[:discordrb_name] = 'websocket' connect_loop - LOGGER.warn('The WS loop exited! Not sure if this is a good thing') + LOGGER.debug('The WS loop exited! Not sure if this is a good thing') end LOGGER.debug('WS thread created! Now waiting for confirmation that everything worked') @@ -553,7 +553,7 @@ def process_gateway end def connect - LOGGER.debug('Connecting') + LOGGER.info('Connecting to gateway') # Get the URI we should connect to url = process_gateway @@ -745,13 +745,7 @@ def handle_reconnect # Op 9 def handle_invalidate_session LOGGER.debug('Received op 9, invalidating session and re-identifying.') - - if @session - @session.invalidate - else - LOGGER.warn('Received op 9 without a running session! Not invalidating, we *should* be fine though.') - end - + @session&.invalidate identify end @@ -819,10 +813,10 @@ def handle_close(e) @should_reconnect = false if FATAL_CLOSE_CODES.include?(e.code) elsif e.is_a? Exception # Log the exception - LOGGER.error('The websocket connection has closed due to an error!') + LOGGER.error('The gateway connection has closed due to an error!') LOGGER.log_exception(e) else - LOGGER.error("The websocket connection has closed: #{e&.inspect || '(no information)'}") + LOGGER.error("The gateway connection has closed: #{e&.inspect}") end end From 909f8c5b4359bd22dfd9ae154b19db4caf9ee2c6 Mon Sep 17 00:00:00 2001 From: biqqles Date: Thu, 21 Jul 2022 19:30:09 +0100 Subject: [PATCH 3/3] refactor: prefer case over responds_to? and is_a? --- lib/discordrb/gateway.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/discordrb/gateway.rb b/lib/discordrb/gateway.rb index 202b8b51f..03b25ff20 100644 --- a/lib/discordrb/gateway.rb +++ b/lib/discordrb/gateway.rb @@ -793,7 +793,8 @@ def handle_internal_close(e) def handle_close(e) @bot.__send__(:raise_event, Events::DisconnectEvent.new(@bot)) - if e.respond_to? :code + case e + when ::WebSocket::Frame::Incoming::Client # It is a proper close frame we're dealing with, print reason and message to console LOGGER.error('Websocket close frame received!') LOGGER.error("Code: #{e.code}") @@ -811,7 +812,7 @@ def handle_close(e) end @should_reconnect = false if FATAL_CLOSE_CODES.include?(e.code) - elsif e.is_a? Exception + when Exception # Log the exception LOGGER.error('The gateway connection has closed due to an error!') LOGGER.log_exception(e)