Skip to content

Commit cf6ad3d

Browse files
authored
Merge pull request #22 from fastruby/log-level-control
Add log-level control through env var
2 parents c00c22a + d4bd9f8 commit cf6ad3d

File tree

5 files changed

+6
-4
lines changed

5 files changed

+6
-4
lines changed

app/jobs/application_job.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ class ApplicationJob < ActiveJob::Base
44
def bot
55
@bot ||= Discord::Bot.configure do |config|
66
config.token = ENV.fetch("DISCORD_BOT_TOKEN", "")
7+
config.log_mode = ENV.fetch("DISCORD_LOG_MODE", "normal").to_sym
78
end
89
end
910
end

app/jobs/puzzle_inventory_check_job.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def send_low_inventory_notification(count)
1919

2020
def send_message(message, channel_id:)
2121
SlackClient::Client.instance.chat_postMessage(channel: channel_id, blocks: message)
22-
rescue Slack::Web::Api::Errors::SlackError
23-
head :unprocessable_entity
22+
rescue Slack::Web::Api::Errors::SlackError => e
23+
Rails.logger.error "Failed to send Slack message: #{e.message} #{e.response_metadata}"
2424
end
2525
end

app/lib/discord/bot.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,9 @@ def configure
1818
delegate :send_message, to: :bot
1919

2020
def initialize(configuration)
21-
@bot = Discordrb::Bot.new(token: configuration.token)
21+
@bot = Discordrb::Bot.new(token: configuration.token, log_mode: configuration.log_mode)
2222
@bot.ready do
2323
Rails.logger.info "✅ Bot is online and connected to Discord!"
24-
puts "✅ Bot is online and connected to Discord!"
2524
setup
2625
end
2726
end

app/lib/discord/configuration.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ class Configuration
55

66
def initialize
77
@token = nil
8+
@log_mode = :normal
89
end
910
end
1011
end

lib/tasks/discord.rake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def bot
2626
@bot ||= begin
2727
bot_wrapper = Discord::Bot.configure do |config|
2828
config.token = ENV.fetch("DISCORD_BOT_TOKEN")
29+
config.log_mode = ENV.fetch("DISCORD_LOG_MODE", "normal").to_sym
2930
end
3031
bot_wrapper.bot
3132
end

0 commit comments

Comments
 (0)