Skip to content

Commit

Permalink
code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-exz committed Dec 23, 2024
1 parent 3266cb6 commit f10eeb4
Show file tree
Hide file tree
Showing 12 changed files with 98 additions and 144 deletions.
31 changes: 31 additions & 0 deletions bot/commands/channel_auto_answer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module WhoIsOnDutyTodaySlackBotModule
module Commands
class ChannelAutoAnswer < SlackRubyBot::Commands::Base
DESCRIPTION = 'Bot will answer on any message in channel at working time'.freeze
EXAMPLE = 'channel auto_answer_enabled=<boolean> example `channel auto_answer_enabled=true`'.freeze

def self.call(client:, data:, match:)
value = match['expression'].split('=').last.strip

unless %w[true false].include?(value)
client.say(
channel: data.channel,
text: "Invalid value for auto-answer. Please use 'true' or 'false'.",
thread_ts: data.thread_ts || data.ts
)
return
end

channel = Channel.find_or_initialize_by(slack_channel_id: data.channel)
channel.update(auto_answer_enabled: value)
channel.save

client.say(
channel: data.channel,
text: "Channel auto-answer has been set to '#{value}'.",
thread_ts: data.thread_ts || data.ts
)
end
end
end
end
19 changes: 0 additions & 19 deletions bot/commands/channel_auto_answer_disable.rb

This file was deleted.

19 changes: 0 additions & 19 deletions bot/commands/channel_auto_answer_enable.rb

This file was deleted.

27 changes: 27 additions & 0 deletions bot/commands/channel_reminder.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module WhoIsOnDutyTodaySlackBotModule
module Commands
class ChannelReminder < SlackRubyBot::Commands::Base
DESCRIPTION = 'Enable or disable channel reminders.'.freeze
EXAMPLE = 'example `channel reminder=true` or `channel reminder=false`'.freeze

def self.call(client:, data:, match:)
value = match['expression'].split('=').last.strip

unless %w[true false].include?(value)
client.say(channel: data.channel, text: "Invalid value for reminder. Please use 'true' or 'false'.")
return
end

channel = Channel.find_or_initialize_by(slack_channel_id: data.channel)
channel.update(reminder_enabled: value)
channel.save

client.say(
channel: data.channel,
text: "Channel reminder has been set to '#{value}'.",
thread_ts: data.thread_ts || data.ts
)
end
end
end
end
19 changes: 0 additions & 19 deletions bot/commands/channel_reminder_disabled.rb

This file was deleted.

19 changes: 0 additions & 19 deletions bot/commands/channel_reminder_enabled.rb

This file was deleted.

28 changes: 28 additions & 0 deletions bot/commands/channel_tag_reporter_in_thread.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module WhoIsOnDutyTodaySlackBotModule
module Commands
class ChannelTagReporterInThread < SlackRubyBot::Commands::Base

DESCRIPTION = 'Enable or disable tagging the reporter in the thread.'.freeze
EXAMPLE = 'example `channel tag_reporter_enabled=true` or `channel tag_reporter_enabled=false`'.freeze

def self.call(client:, data:, match:)
value = match['expression'].split('=').last.strip

unless %w[true false].include?(value)
client.say(channel: data.channel, text: "Invalid value for tagging the reporter. Please use 'true' or 'false'.")
return
end

channel = Channel.find_or_initialize_by(slack_channel_id: data.channel)
channel.update(tag_reporter_enabled: value)
channel.save

client.say(
channel: data.channel,
text: "Tagging the reporter in the thread has been set to '#{value}'.",
thread_ts: data.thread_ts || data.ts
)
end
end
end
end
19 changes: 0 additions & 19 deletions bot/commands/channel_tag_reporter_in_thread_disable.rb

This file was deleted.

19 changes: 0 additions & 19 deletions bot/commands/channel_tag_reporter_in_thread_enable.rb

This file was deleted.

9 changes: 3 additions & 6 deletions bot/commands/help.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,9 @@ def self.generate_help_text
Checked,
DutyCreate,
CreateDutyForUser,
ChannelReminderEnabled,
ChannelReminderDisabled,
ChannelAutoAnswerEnable,
ChannelAutoAnswerDisable,
ChannelTagReporterInThreadEnable,
ChannelTagReporterInThreadDisable,
ChannelReminder,
ChannelAutoAnswer,
ChannelTagReporterInThread,
ChannelLabelsStatistic,
ChannelLabelsList,
ChannelLabelsMerge,
Expand Down
9 changes: 3 additions & 6 deletions bot/commands/main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
require_relative 'answer_enable_hide_reason'
require_relative 'answer_set_custom_text'
require_relative 'call_duty_person'
require_relative 'channel_reminder_disabled'
require_relative 'channel_reminder_enabled'
require_relative 'checked'
require_relative 'create_duty_for_user'
require_relative 'duty_create'
Expand All @@ -25,13 +23,12 @@
require_relative 'channel_labels_statistic'
require_relative 'channel_labels_list'
require_relative 'channel_labels_merge'
require_relative 'channel_reminder'
require_relative 'channel_tag_reporter_in_thread'
require_relative 'channel_auto_answer'
require_relative 'thread_labels_clean'
require_relative 'thread_labels'
require_relative 'git_commits'
require_relative 'channel_tag_reporter_in_thread_enable'
require_relative 'channel_tag_reporter_in_thread_disable'
require_relative 'channel_auto_answer_enable'
require_relative 'channel_auto_answer_disable'

module WhoIsOnDutyTodaySlackBotModule
module Commands
Expand Down
24 changes: 6 additions & 18 deletions bot/whoisondutytodayslackbot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,28 +44,16 @@ class WhoIsOnDutyTodaySlackBot < SlackRubyBot::Bot
WhoIsOnDutyTodaySlackBotModule::Commands::CreateDutyForUser.call(client: client, data: data, match: match)
end

command 'channel reminder enabled' do |client, data|
WhoIsOnDutyTodaySlackBotModule::Commands::ChannelReminderEnabled.call(client: client, data: data)
command '^channel reminder_enabled=.*$' do |client, data, match|
WhoIsOnDutyTodaySlackBotModule::Commands::ChannelReminder.call(client: client, data: data, match: match)
end

command 'channel reminder disabled' do |client, data|
WhoIsOnDutyTodaySlackBotModule::Commands::ChannelReminderDisabled.call(client: client, data: data)
command '/^channel auto_answer=.*$/' do |client, data, match|
WhoIsOnDutyTodaySlackBotModule::Commands::ChannelAutoAnswer.call(client: client, data: data, match: match)
end

command 'channel auto answer enable' do |client, data|
WhoIsOnDutyTodaySlackBotModule::Commands::ChannelAutoAnswerEnable.call(client: client, data: data)
end

command 'channel auto answer disable' do |client, data|
WhoIsOnDutyTodaySlackBotModule::Commands::ChannelAutoAnswerDisable.call(client: client, data: data)
end

command 'channel tag reporter in thread enable' do |client, data|
WhoIsOnDutyTodaySlackBotModule::Commands::ChannelTagReporterInThreadEnable.call(client: client, data: data)
end

command 'channel tag reporter in thread disable' do |client, data|
WhoIsOnDutyTodaySlackBotModule::Commands::ChannelTagReporterInThreadDisable.call(client: client, data: data)
command '^channel tag_reporter_enabled=.*$/' do |client, data, match|
WhoIsOnDutyTodaySlackBotModule::Commands::ChannelTagReporterInThread.call(client: client, data: data, match: match)
end

command 'duty update' do |client, data, match|
Expand Down

0 comments on commit f10eeb4

Please sign in to comment.