From 00ee509df05d32fec43de4f8ebf92f0d827322a7 Mon Sep 17 00:00:00 2001 From: amandabizzinotto Date: Wed, 17 Sep 2025 00:06:23 -0300 Subject: [PATCH 1/2] Add log-level control through env var --- app/jobs/application_job.rb | 1 + app/lib/discord/bot.rb | 3 +-- app/lib/discord/configuration.rb | 1 + lib/tasks/discord.rake | 1 + 4 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/jobs/application_job.rb b/app/jobs/application_job.rb index 16d96d8..85f52aa 100644 --- a/app/jobs/application_job.rb +++ b/app/jobs/application_job.rb @@ -4,6 +4,7 @@ class ApplicationJob < ActiveJob::Base def bot @bot ||= Discord::Bot.configure do |config| config.token = ENV.fetch("DISCORD_BOT_TOKEN", "") + config.log_mode = ENV.fetch("DISCORD_LOG_MODE", "normal").to_sym end end end diff --git a/app/lib/discord/bot.rb b/app/lib/discord/bot.rb index 360b09a..9250321 100644 --- a/app/lib/discord/bot.rb +++ b/app/lib/discord/bot.rb @@ -18,10 +18,9 @@ def configure delegate :send_message, to: :bot def initialize(configuration) - @bot = Discordrb::Bot.new(token: configuration.token) + @bot = Discordrb::Bot.new(token: configuration.token, log_mode: configuration.log_mode) @bot.ready do Rails.logger.info "✅ Bot is online and connected to Discord!" - puts "✅ Bot is online and connected to Discord!" setup end end diff --git a/app/lib/discord/configuration.rb b/app/lib/discord/configuration.rb index ffa7ac4..5374079 100644 --- a/app/lib/discord/configuration.rb +++ b/app/lib/discord/configuration.rb @@ -5,6 +5,7 @@ class Configuration def initialize @token = nil + @log_mode = :normal end end end diff --git a/lib/tasks/discord.rake b/lib/tasks/discord.rake index 02104aa..d6b9e39 100644 --- a/lib/tasks/discord.rake +++ b/lib/tasks/discord.rake @@ -26,6 +26,7 @@ def bot @bot ||= begin bot_wrapper = Discord::Bot.configure do |config| config.token = ENV.fetch("DISCORD_BOT_TOKEN") + config.log_mode = ENV.fetch("DISCORD_LOG_MODE", "normal").to_sym end bot_wrapper.bot end From d4bd9f82075d298ec0ada243587c96bc60e47d21 Mon Sep 17 00:00:00 2001 From: amandabizzinotto Date: Wed, 17 Sep 2025 00:51:20 -0300 Subject: [PATCH 2/2] Replace invalid line with log --- app/jobs/puzzle_inventory_check_job.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/jobs/puzzle_inventory_check_job.rb b/app/jobs/puzzle_inventory_check_job.rb index e7d0bf0..656e42c 100644 --- a/app/jobs/puzzle_inventory_check_job.rb +++ b/app/jobs/puzzle_inventory_check_job.rb @@ -19,7 +19,7 @@ def send_low_inventory_notification(count) def send_message(message, channel_id:) SlackClient::Client.instance.chat_postMessage(channel: channel_id, blocks: message) - rescue Slack::Web::Api::Errors::SlackError - head :unprocessable_entity + rescue Slack::Web::Api::Errors::SlackError => e + Rails.logger.error "Failed to send Slack message: #{e.message} #{e.response_metadata}" end end