-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
612 additions
and
526 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
module WhoIsOnDutyTodaySlackBotModule | ||
module Commands | ||
class ActionCreate | ||
def self.call(client:,data:,match:) | ||
action = Action.new( | ||
problem: match['expression'][/problem:(.*) action:/, 1], | ||
action: match['expression'][/ action:(.*)$/, 1], | ||
channel: data.channel | ||
) | ||
|
||
if action.save | ||
client.web_client.chat_postMessage( | ||
channel: data.channel, | ||
text: I18n.t('commands.action.created.text'), | ||
thread_ts: data.thread_ts || data.ts, | ||
as_user: true | ||
) | ||
else | ||
client.web_client.chat_postMessage( | ||
channel: data.channel, | ||
text: I18n.t('commands.action.failed.text'), | ||
thread_ts: data.thread_ts || data.ts, | ||
as_user: true | ||
) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
module WhoIsOnDutyTodaySlackBotModule | ||
module Commands | ||
class ActionDelete | ||
def self.call(client:,data:,match:) | ||
Action.where( | ||
problem: match['expression'][/problem:(.*)/, 1], | ||
channel: data.channel | ||
).delete_all | ||
|
||
client.web_client.chat_postMessage( | ||
channel: data.channel, | ||
text: I18n.t('commands.action.deleted.text'), | ||
thread_ts: data.thread_ts || data.ts, | ||
as_user: true | ||
) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
module WhoIsOnDutyTodaySlackBotModule | ||
module Commands | ||
class AnswerDeleteCustomText | ||
def self.call(client:,data:) | ||
Answer.where(channel_id: data.channel).delete_all | ||
|
||
client.web_client.chat_postMessage( | ||
channel: data.channel, | ||
text: I18n.t('commands.answer.deleted.text'), | ||
thread_ts: data.thread_ts || data.ts, | ||
as_user: true | ||
) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module WhoIsOnDutyTodaySlackBotModule | ||
module Commands | ||
class AnswerDisableHideReason | ||
def self.call(client:,data:) | ||
Answer.where(channel_id: data.channel).update_all(hide_reason: false) | ||
client.web_client.chat_postMessage( | ||
channel: data.channel, | ||
text: I18n.t('commands.disable.hide_reason.text', name: client.self.name), | ||
thread_ts: data.thread_ts || data.ts, | ||
as_user: true | ||
) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
module WhoIsOnDutyTodaySlackBotModule | ||
module Commands | ||
class AnswerEnableHideReason | ||
def self.call(client:,data:) | ||
if Answer.where(channel_id: data.channel).update_all(hide_reason: true) | ||
client.web_client.chat_postMessage( | ||
channel: data.channel, | ||
text: I18n.t('commands.enable.hide_reason.text', name: client.self.name), | ||
thread_ts: data.thread_ts || data.ts, | ||
as_user: true | ||
) | ||
else | ||
client.web_client.chat_postMessage( | ||
channel: data.channel, | ||
text: I18n.t('commands.enable.hide_reason.failed.text', name: client.self.name), | ||
thread_ts: data.thread_ts || data.ts, | ||
as_user: true | ||
) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
module WhoIsOnDutyTodaySlackBotModule | ||
module Commands | ||
class AnswerSetCustomText | ||
def self.call(client:,data:,match:) | ||
custom_text = match['expression'] | ||
Answer.where(channel_id: data.channel).delete_all | ||
answer = Answer.new | ||
answer.body = custom_text | ||
answer.channel_id = data.channel | ||
|
||
if answer.save | ||
|
||
client.web_client.chat_postMessage( | ||
channel: data.channel, | ||
text: I18n.t('commands.answer.created.text'), | ||
thread_ts: data.thread_ts || data.ts, | ||
as_user: true | ||
) | ||
|
||
client.web_client.chat_postMessage( | ||
channel: data.channel, | ||
text: custom_text, | ||
thread_ts: data.thread_ts || data.ts, | ||
as_user: true | ||
) | ||
else | ||
client.web_client.chat_postMessage( | ||
channel: data.channel, | ||
text: I18n.t('commands.answer.failed.text'), | ||
thread_ts: data.thread_ts || data.ts, | ||
as_user: true | ||
) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
module WhoIsOnDutyTodaySlackBotModule | ||
module Commands | ||
class ChannelReminderDisabled | ||
def self.call(client:,data:) | ||
channel = Channel.where(slack_channel_id: data.channel).first | ||
channel.reminder_enabled = false | ||
channel.save | ||
client.say( | ||
channel: data.channel, | ||
text: I18n.t('commands.channel.reminder.disabled.text'), | ||
thread_ts: data.thread_ts || data.ts | ||
) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
module WhoIsOnDutyTodaySlackBotModule | ||
module Commands | ||
class ChannelReminderEnabled | ||
def self.call(client:,data:) | ||
channel = Channel.where(slack_channel_id: data.channel).first | ||
channel.reminder_enabled = true | ||
channel.save | ||
client.say( | ||
channel: data.channel, | ||
text: I18n.t('commands.channel.reminder.enabled.text'), | ||
thread_ts: data.thread_ts || data.ts | ||
) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
module WhoIsOnDutyTodaySlackBotModule | ||
module Commands | ||
class Checked | ||
def self.call(client:,data:) | ||
message_processor = MessageProcessor.new | ||
message_processor.disable_message_from_remind(data: data) | ||
client.web_client.chat_postMessage( | ||
channel: data.channel, | ||
text: I18n.t('commands.thread.checked'), | ||
thread_ts: data.thread_ts || data.ts, | ||
as_user: true | ||
) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
module WhoIsOnDutyTodaySlackBotModule | ||
module Commands | ||
class CreateDutyForUser | ||
def self.call(client:,data:,match:) | ||
message_processor = MessageProcessor.new | ||
slack_web_client = Slack::Web::Client.new | ||
|
||
begin | ||
channel_info = slack_web_client.channels_info(channel: data.channel) | ||
rescue | ||
channel_info = Hash.new | ||
channel_info['channel'] = Hash.new | ||
channel_info['channel']['id'] = data.channel | ||
channel_info['channel']['name'] = nil | ||
channel_info['channel']['value'] = nil | ||
end | ||
|
||
channel = Channel.where(slack_channel_id: data.channel).first | ||
if channel.blank? | ||
channel = Channel.new | ||
channel.slack_channel_id = channel_info['channel']['id'] | ||
channel.name = channel_info['channel']['name'] | ||
channel.description = channel_info['channel']['value'] | ||
channel.save | ||
end | ||
|
||
user_name = match['expression'][/<@(.+)>/, 1] | ||
message_processor.collectUserInfoBySlackUserId(user_name) | ||
user = User.where(slack_user_id: user_name).first | ||
|
||
duty = Duty.where(user_id: user_name, channel_id: data.channel).first | ||
if duty.blank? | ||
duty = Duty.new | ||
duty.duty_from = ActiveSupport::TimeZone.new(user.tz).local_to_utc(match['expression'][/from (\d+:\d+) /, 1].to_time) | ||
duty.duty_to = ActiveSupport::TimeZone.new(user.tz).local_to_utc(match['expression'][/.* to (\d+:\d+)$/, 1].to_time) | ||
duty.channel_id = data.channel | ||
duty.user_id = user.id | ||
duty.enabled = true | ||
duty.save | ||
client.say( | ||
channel: data.channel, | ||
text: I18n.t('commands.duty.created.text', fH: duty.duty_from.hour, fM: duty.duty_from.min, tH: duty.duty_to.hour, tM: duty.duty_to.min, status: duty.enabled), | ||
thread_ts: data.thread_ts || data.ts | ||
) | ||
set_user_on_duty(data: data, client: client, slack_user_id: user_name) | ||
else | ||
client.say( | ||
channel: data.channel, | ||
text: I18n.t('commands.duty.exist.text', fH: duty.duty_from.hour, fM: duty.duty_from.min, tH: duty.duty_to.hour, tM: duty.duty_to.min, status: duty.enabled), | ||
thread_ts: data.thread_ts || data.ts | ||
) | ||
end | ||
end | ||
|
||
def self.set_user_on_duty(data:, client:, slack_user_id:) | ||
Duty.where(channel_id: data.channel).where(user_id: slack_user_id).update_all(enabled: true) | ||
Duty.where(channel_id: data.channel).where.not(user_id: slack_user_id).update_all(enabled: false) | ||
client.say( | ||
channel: data.channel, | ||
text: I18n.t('commands.duty.enabled-for-user.text', name: slack_user_id), | ||
thread_ts: data.thread_ts || data.ts | ||
) | ||
end | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
module WhoIsOnDutyTodaySlackBotModule | ||
module Commands | ||
class DutyCreate | ||
def self.call(client:,data:,match:) | ||
message_processor = MessageProcessor.new | ||
slack_web_client = Slack::Web::Client.new | ||
begin | ||
channel_info = slack_web_client.channels_info(channel: data.channel) | ||
rescue | ||
channel_info = Hash.new | ||
channel_info['channel'] = Hash.new | ||
channel_info['channel']['id'] = data.channel | ||
channel_info['channel']['name'] = nil | ||
channel_info['channel']['value'] = nil | ||
end | ||
|
||
channel = Channel.where(slack_channel_id: data.channel).first | ||
if channel.blank? | ||
channel = Channel.new | ||
channel.slack_channel_id = channel_info['channel']['id'] | ||
channel.name = channel_info['channel']['name'] | ||
channel.description = channel_info['channel']['value'] | ||
channel.save | ||
end | ||
|
||
message_processor.collectUserInfo(data: data) | ||
user = User.where(slack_user_id: data.user).first | ||
|
||
duty = Duty.where(user_id: data.user, channel_id: data.channel).first | ||
if duty.blank? | ||
duty = Duty.new | ||
duty.duty_from = ActiveSupport::TimeZone.new(user.tz).local_to_utc(match['expression'][/from (\d+:\d+) /, 1].to_time) | ||
duty.duty_to = ActiveSupport::TimeZone.new(user.tz).local_to_utc(match['expression'][/.* to (\d+:\d+)$/, 1].to_time) | ||
duty.channel_id = data.channel | ||
duty.user_id = user.id | ||
duty.enabled = true | ||
duty.save | ||
client.say( | ||
channel: data.channel, | ||
text: I18n.t('commands.duty.created.text', fH: duty.duty_from.hour, fM: duty.duty_from.min, tH: duty.duty_to.hour, tM: duty.duty_to.min, status: duty.enabled), | ||
thread_ts: data.thread_ts || data.ts | ||
) | ||
i_am_on_duty(data: data, client: client) | ||
else | ||
client.say( | ||
channel: data.channel, | ||
text: I18n.t('commands.duty.exist.text', fH: duty.duty_from.hour, fM: duty.duty_from.min, tH: duty.duty_to.hour, tM: duty.duty_to.min, status: duty.enabled), | ||
thread_ts: data.thread_ts || data.ts | ||
) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
module WhoIsOnDutyTodaySlackBotModule | ||
module Commands | ||
class DutyDelete | ||
def self.call(client:,data:) | ||
duty = Duty.where(user_id: data.user, channel_id: data.channel).first | ||
|
||
if duty.blank? | ||
client.say( | ||
channel: data.channel, | ||
text: I18n.t('commands.duty.exist.error'), | ||
thread_ts: data.thread_ts || data.ts | ||
) | ||
else | ||
duty.delete | ||
client.say( | ||
channel: data.channel, | ||
text: I18n.t('commands.duty.deleted.text'), | ||
thread_ts: data.thread_ts || data.ts | ||
) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module WhoIsOnDutyTodaySlackBotModule | ||
module Commands | ||
class DutySetOpsgenieEscalation | ||
def self.call(client:,data:,match:) | ||
opsgenie_escalation_name = match['expression'] | ||
Duty.where(channel_id: data.channel).update_all(opsgenie_escalation_name: opsgenie_escalation_name) | ||
|
||
client.web_client.chat_postMessage( | ||
channel: data.channel, | ||
text: I18n.t('commands.opsgenie-escalation-name.text'), | ||
thread_ts: data.thread_ts || data.ts, | ||
as_user: true | ||
) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module WhoIsOnDutyTodaySlackBotModule | ||
module Commands | ||
class DutySyncWithOpsgenieSchedule | ||
def self.call(client:,data:,match:) | ||
opsgenie_schedule_name = match['expression'] | ||
Duty.where(channel_id: data.channel).update_all(opsgenie_schedule_name: opsgenie_schedule_name) | ||
|
||
client.web_client.chat_postMessage( | ||
channel: data.channel, | ||
text: I18n.t('commands.opsgenie-schedule-name.text'), | ||
thread_ts: data.thread_ts || data.ts, | ||
as_user: true | ||
) | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.