Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-exz committed Dec 20, 2024
1 parent 394e31e commit 81e10b6
Showing 1 changed file with 51 additions and 31 deletions.
82 changes: 51 additions & 31 deletions bot/commands/other.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,21 @@ def self.call(client:, data:, match:)
channel = Channel.where(slack_channel_id: data.channel).first
return if channel.nil?

# Answer if it is known problem
if !data.nil? && !match.nil?
Action.where(channel: data.channel).each do |action|
/#{action.problem}/i.match(data.text) do |_|
reply_to_known_problem(client: client, problem: action.problem, data: data, action: action.action,
channel: channel)
end
end
end

duty = Duty.where(channel_id: data.channel, enabled: true).first
return if duty.nil?

# don't reply on duty person messages
#return if data.user == duty.user.slack_user_id

# store messages where reminder enabled
if channel.reminder_enabled == true
Expand All @@ -23,20 +37,6 @@ def self.call(client:, data:, match:)
message_processor.disable_message_from_remind(data: data)
end
end

# don't reply on duty person messages
#return if data.user == duty.user.slack_user_id

# Answer if it is known problem
if !data.nil? && !match.nil?
Action.where(channel: data.channel).each do |action|
/#{action.problem}/i.match(data.text) do |_|
reply_to_known_problem(client: client, problem: action.problem, data: data, action: action.action,
channel: channel)
end
end
end

# check if message written in channel
if data.respond_to?(:thread_ts) == false
message_processor.collectUserInfo(data: data)
Expand All @@ -62,19 +62,45 @@ def self.reply_in_not_working_time(client, reason, data, channel)
answers = Answer.where(channel_id: data.channel)

if answers.empty?
# use standard answer for not working time if no custom
text = I18n.t('reply.non-working-time.text', name: client.self.name)
else
working_hours_answer = answers.find { |answer| answer.answer_type == 'working_time' }
non_working_hours_answer = answers.find { |answer| answer.answer_type == 'non_working_time' }
text = non_working_hours_answer.body
reason = '' if non_working_hours_answer.hide_reason == 1
end

if working_hours_answer && within_working_hours?(channel) && channel.auto_answer_enabled
text = working_hours_answer.body
elsif non_working_hours_answer && !within_working_hours?(channel)
text = non_working_hours_answer.body
reason = '' if non_working_hours_answer.hide_reason == 1
else
text = I18n.t('reply.non-working-time.text', name: client.self.name)
end
client.web_client.chat_postMessage(
text: '%s' % reason,
channel: data.channel,
attachments: [
{
fallback: I18n.t('reply.non-working-time.subject'),
text: text,
color: '#3AA3E3',
attachment_type: 'default'
}
],
thread_ts: data.thread_ts || data.ts,
as_user: true
)
message_processor = MessageProcessor.new
message_processor.save_message(data: data)
send_tagged_message(client,channel,data)
end

def self.reply_in_working_time(client, reason, data, channel)

# search for custom answer
answers = Answer.where(channel_id: data.channel)

if answers.empty?
# use standard answer for not working time if no custom
text = I18n.t('reply.non-working-time.text', name: client.self.name)
else
non_working_hours_answer = answers.find { |answer| answer.answer_type == 'non_working_time' }
text = non_working_hours_answer.body
reason = '' if non_working_hours_answer.hide_reason == 1
end

client.web_client.chat_postMessage(
Expand Down Expand Up @@ -146,18 +172,12 @@ def self.send_tagged_message(client, channel, data)
end
end

def self.within_working_hours?(channel)
# Implement logic to check if the current time is within working hours
# This is a placeholder implementation
def self.within_working_hours?(duty)
current_time = Time.now.utc
duty = Duty.where(channel_id: channel.slack_channel_id, enabled: true).first
return false if duty.nil?

from_time = duty.duty_from.utc.strftime('%H%M%S%N')
to_time = duty.duty_to.utc.strftime('%H%M%S%N')
current_time_str = current_time.strftime('%H%M%S%N')

current_time_str >= from_time && current_time_str <= to_time
current_time_str > from_time && current_time_str < to_time
end
end
end
Expand Down

0 comments on commit 81e10b6

Please sign in to comment.