Skip to content

Discordチャットに今日と明日分の開催イベント一覧を投稿する + 祝日非開催である定期イベントはDiscordに投稿しない#6565

Merged
komagata merged 33 commits intomainfrom
feature/change_event_notification_to_discord
Jun 20, 2023
Merged

Discordチャットに今日と明日分の開催イベント一覧を投稿する + 祝日非開催である定期イベントはDiscordに投稿しない#6565
komagata merged 33 commits intomainfrom
feature/change_event_notification_to_discord

Conversation

@toke04
Copy link
Copy Markdown
Contributor

@toke04 toke04 commented May 27, 2023

Issue

チャットに投稿される明日開催のイベント一覧の表示を変えたい。 #6457
祝日非開催である定期イベント開催のお知らせがDiscordに通知されている #6486

概要

Discordチャットに投稿される、開催イベント一覧の表示方法を変更 + 仕様変更を行いました。
変更により、以下の仕様になります。

  • ❌明日分のみ投稿 => 🟢今日 + 明日に変更
  • ❌祝日非開催イベントが、開催されると誤解されるように投稿されていた=> 🟢祝日に開催されない設定をしたイベントなら、注意書き(⚠️)をして、開催されないのが分かるようにした

スクリーンショット 2023-06-01 13 50 36

変更確認方法

  1. ブランチfeature/change_event_notification_to_discordをローカルに取り込む
  2. bin/rails sでローカル環境を立ち上げる
  3. こちらの公式資料を参考にしながら、「自分専用のDiscordサーバーの作成」を行い、自分宛に通知テストを行う。
    ※過去にDiscord通知サーバーの作成方法を書いた資料があったので、リンクを載せます

「サーバーを追加」を押す
スクリーンショット_2023-05-27_21_13_48

「オリジナルの作成」を押す
スクリーンショット_2023-05-27_21_15_14

名前を付けて新規作成を押したら「自分専用のDiscordサーバーの作成」が完了
testtt

こちらの写真のように、「チャネルの編集ボタン」を押す(歯車マーク)
スクリーンショット_2023-05-27_21_19_06

「連携サービス」から「ウェブックの作成」を押す
フック

「URLをコピー」を押せば、「Webhook URL」の取得は完了です
コピー

[完成形]
スクリーンショット 2023-05-27 20 58 58

  1. サーバーの作成を完了したら、
    webhook_url: webhook_url
    の58行目の、webhook_url のバリューを、自分で取得した「Webhook URL」にする
url
  1. http://localhost:3000/scheduler/daily/notify_coming_soon_regular_events ←のURLにアクセスすると、先ほど作成した「自分専用のDiscordサーバー」に通知が届くことを確認する。
    貼り付け

    「自分専用のDiscordサーバー」に通知が届く
表示

Screenshot

変更前

[明日の分のみ、このように投稿されていた]
貼り付けた画像_2023_04_19_13_58

[祝日非開催のイベントも投稿されていた]
スクリーンショット 2023-05-27 21 37 27

変更後

このように、「今日 + 明日」開催のイベントが投稿されるようになった(祝日非開催のイベントは注意書き(⚠️)をして、開催されないのが分かるようにした)
スクリーンショット 2023-06-01 13 50 36

@toke04 toke04 requested review from komagata and removed request for komagata May 27, 2023 13:36
@toke04 toke04 force-pushed the feature/change_event_notification_to_discord branch from ef8d860 to dd0d0b9 Compare May 28, 2023 03:14
@toke04 toke04 marked this pull request as ready for review May 28, 2023 03:17
@toke04 toke04 changed the title チャットに投稿される今日 + 明日分の開催のイベント一覧を表示する チャットに投稿される今日と明日分の開催のイベント一覧を表示する + 祝日非開催である定期イベント開催をDiscordに投稿しない May 28, 2023
@toke04
Copy link
Copy Markdown
Contributor Author

toke04 commented May 28, 2023

@OdenTakashi
お疲れ様です。
本issueのレビューをお願いしてもよろしいでしょうか?

二つ分のissueが混ざっており、動作確認も少し手間がかかってしまいますので、
時間を多く取って頂いて大丈夫です🙇‍♂️

@toke04 toke04 changed the title チャットに投稿される今日と明日分の開催のイベント一覧を表示する + 祝日非開催である定期イベント開催をDiscordに投稿しない チャットに投稿される今日と明日分の開催イベント一覧を表示する + 祝日非開催である定期イベント開催をDiscordに投稿しない May 28, 2023
@toke04 toke04 changed the title チャットに投稿される今日と明日分の開催イベント一覧を表示する + 祝日非開催である定期イベント開催をDiscordに投稿しない Discordチャットに今日と明日分の開催イベント一覧を表示する + 祝日非開催である定期イベントはDiscordに投稿しない May 28, 2023
@toke04 toke04 changed the title Discordチャットに今日と明日分の開催イベント一覧を表示する + 祝日非開催である定期イベントはDiscordに投稿しない Discordチャットに今日と明日分の開催イベント一覧を投稿する + 祝日非開催である定期イベントはDiscordに投稿しない May 28, 2023
@toke04 toke04 requested a review from OdenTakashi May 28, 2023 10:04
@OdenTakashi
Copy link
Copy Markdown
Member

@syo-tokeshi
お疲れ様です。
ご連絡遅れてしまい申し訳ありません。💦

レビュー依頼いただいて申し訳ないのですが、体調を崩してしまっているため他の方にレビュー依頼をお願いしていただいてもよろしいでしょうか?🙇‍♂️

@toke04
Copy link
Copy Markdown
Contributor Author

toke04 commented May 30, 2023

@OdenTakashi
かしこまりました🙇‍♂️
OdenTakashi さんの体調が良くなる事をお祈りいたします🙏
親切に返事、ありがとうございます😊

@ymmtd0x0b
お疲れ様です。
本issueのレビューをお願いしてもよろしいでしょうか?

二つ分のissueが混ざっており、動作確認も少し手間がかかってしまいますので、
時間を多く取って頂いて大丈夫です🙇‍♂️

@toke04 toke04 requested review from ymmtd0x0b and removed request for OdenTakashi May 30, 2023 01:47
@ymmtd0x0b
Copy link
Copy Markdown
Contributor

@syo-tokeshi
了解しました!確認させて頂きます💪

@toke04
Copy link
Copy Markdown
Contributor Author

toke04 commented May 30, 2023

@syo-tokeshi 了解しました!確認させて頂きます💪

ありがとうございます🙇‍♂️
全然無理をなさらずに、ゆっくりで良いのでよろしくお願い致します🙇‍♂️

@toke04
Copy link
Copy Markdown
Contributor Author

toke04 commented May 31, 2023

@ymmtd0x0b
お疲れ様です。
今日MTGの話で出たように、仕様変更になりましたので、
変更後、テストをパスしましたら@を付けてお知らせいたします🙇‍♂️

それまでしばらくレビューをお待ち頂けたら嬉しいです🙇‍♂️

@toke04
Copy link
Copy Markdown
Contributor Author

toke04 commented Jun 1, 2023

@ymmtd0x0b
お待たせ致しました!
変更完了しました🙇‍♂️

ゆっくりで良いので、レビューよろしくお願い致します🙇‍♂️

@toke04 toke04 force-pushed the feature/change_event_notification_to_discord branch from fb549e1 to 78bf85b Compare June 2, 2023 06:44
Copy link
Copy Markdown
Contributor

@ymmtd0x0b ymmtd0x0b left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

お待たせしました🙏
動作確認OKでした!動的に変化する定形文章の構築は凄い難しそうですね...!

いくつかコメントさせて頂いているので、確認をお願いします🙇‍♂️

Comment on lines +49 to +53
event_info = "⚡️⚡️⚡️イベントのお知らせ⚡️⚡️⚡️\n\n"
event_info = add_event_info(today_events, '今日', today, event_info)
event_info += "------------------------------\n\n" if today_events.present?
event_info = add_event_info(tomorrow_events, '明日', tomorrow, event_info)
event_info += '⚡️⚡️⚡️⚡️⚡️⚡️⚡️⚡️⚡️⚡️⚡️⚡️⚡️⚡️'
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ココと add_event_infoメソッド にて evnet_info へ定形文を追加している部分は、文字列リテラルを利用した方が保守しやすそうかなと思いましたが、いかがでしょうか?🙋‍♂️

add_event_infoメソッド で返された文字列を埋め込むカタチにすると event_info を渡す必要も無くなりそうです🙌 ( その場合、後置if でメソッドの実行判定を行うかメソッドの最初でイベントが無い場合は return する処理が必要になると思います )

event_info = <<~TEXT.gsub(/^\n+/, "\n").chomp
  ⚡️⚡️⚡️イベントのお知らせ⚡️⚡️⚡️

  #{add_event_info(today_events, '今日', today)}

  #{"------------------------------" if today_events.present?}

  #{add_event_info(tomorrow_events, '明日', tomorrow)}

  ⚡️⚡️⚡️⚡️⚡️⚡️⚡️⚡️⚡️⚡️⚡️⚡️⚡️⚡️
TEXT

Copy link
Copy Markdown
Contributor Author

@toke04 toke04 Jun 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

実際に試した結果、正しくその通りだと思いました🙇‍♂️(劇的に読みやすくなったし引数も減ってgood過ぎました!)
採用させて頂きます🙇‍♂️
そして勉強になりました!!😊

[追記]
<<~TEXT.gsub(/^\n+/, "\n").chompこちら、何を参考に学んだ感じでしょうか?
上手いですね😊

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[追記]
<<~TEXT.gsub(/^\n+/, "\n").chompこちら、何を参考に学んだ感じでしょうか?
上手いですね😊

ありがとうございます🙌
変更前のコードで <<~TEXT.chomp と記述されていたので、通常の文字列と同様に処理できそうだなと思って試してみたら上手く言った感じです!

event_info = <<~TEXT.chomp

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

なるほどです!
そう思って解決されたのですね😊
参考になりました!🙇‍♂️

def add_event_info(events, date_message, date, event_info)
day_of_the_week = %w[日 月 火 水 木 金 土]
event_info += "< #{date_message} (#{date.strftime('%m/%d')} #{day_of_the_week[date.wday]} 開催 >\n\n" if events.present?
held_events, not_held_events = separate_events(events, date)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

開催イベントとお休みイベントの抽出処理は partitionメソッド を利用するとスッキリ記述できそうかなと思いました!

held_events, not_held_events =
  events.partition { |event| event.hold_national_holiday || !HolidayJp.holiday?(date)  }

Copy link
Copy Markdown
Contributor Author

@toke04 toke04 Jun 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

スッキリして最高でした!😊
便利なメソッドを知らず、無駄な処理書いて複雑にしていましたね、、😭

1件ですが、「祝日には開催しないイベント」の判定ですが、
山本さんのコードの方が素直で読みやすいと思うのですが、
&&演算子を使ったほうが、

  • 開催されるイベント
  • 開催されないイベント

の条件が明確で良い気がします🙇‍♂️

not_held_events, held_events = events.partition { |event| !event.hold_national_holiday && HolidayJp.holiday?(date)  }

特定の条件が揃った時のみイベントは開催されないので、こっちの方が良いと思いました🙇‍♂️

ただ、私の方がベターでない可能性もあるので、駒形さんに判断を委ねたいと思いました、、(山本さんの方がコードが素直で読みやすいからです)

&&の方が条件が限定的になるので、予期せぬ不具合が起きにくくなって良いと思うんだけど、どうなんだろう?


@komagata

1

held_events, not_held_events = events.partition { |event| event.hold_national_holiday || !HolidayJp.holiday?(date)  }

2

not_held_events, held_events = events.partition { |event| !event.hold_national_holiday && HolidayJp.holiday?(date)  }

こちら、どちらを採用した方が良さそうでしょうか?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@syo-tokeshi
駒形さんへの確認ありがとうございます!
判定式の内容的には同じはずなので、私としては syo-tokeshiさんの好みの方を採用して頂いて問題ないように思ってます〜

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@syo-tokeshi どちらでもいいかなと思います。
ただ1行が長いので改行するなに何かした方がいいと思います〜

Copy link
Copy Markdown
Contributor Author

@toke04 toke04 Jun 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@komagata
こちらで対応しました🙇‍♂️
コンフリクトの修正 + 一部処理を複数行に分ける

    not_held_events, held_events = events.partition do |event|
      !event.hold_national_holiday && HolidayJp.holiday?(date)
    end

regular_event_repeat_rule35:
frequency: 0
day_of_the_week: 6
regular_event: regular_event30 No newline at end of file
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

最終行の改行が抜けてるみたいです👀

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

失礼しました🙇‍♂️
ご指摘ありがとうございます🙇‍♂️

Comment on lines +116 to +119
travel_to Time.zone.local(2023, 5, 5, 6, 0, 0) do
assert_notifications_enqueued 2, **expected do
DiscordNotifier.with(params).coming_soon_regular_events.notify_later
DiscordNotifier.coming_soon_regular_events(params).notify_later
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

実際に利用されているのが notify_now だけでしたら、この部分は不要そうとも思ったのですがいかがでしょうか🤔?

def self.coming_soon_regular_events(today_events, tomorrow_events)
DiscordNotifier.with(today_events: today_events, tomorrow_events: tomorrow_events).coming_soon_regular_events.notify_now
end

Copy link
Copy Markdown
Contributor Author

@toke04 toke04 Jun 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

確認いたしました🙇‍♂️
確かに、かなりごもっともですね、、

1点気になることがございまして、
test/notifiers/discord_notifier_test.rb
こちらの他のテストコードもnotify_now しか使ってないけど、

  • 同期
  • 非同期

両方テストを行なっているので、無意味な気がしますがそのまま前例に倣っても良い気がしました、、 (が、消すべきかな?やっぱり)

例えばこちらの、invalid_userというメソッドも、notify_nowしか使っていない

駒形さんに聞いてみます🙇‍♂️


@komagata
こちら、使ってない非同期のテスト(notify_laterを使ったテスト)は削除した方がよろしいでしょうか?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@syo-tokeshi
すみません!変更前のコードは notify_now だけだったので、てっきり利用する方だけをテストすれば良いのかなと思っていました🙏
確かに他の箇所では使用の有無に関わらず両方テストされていますね...!ですので、両方記載した方が良さそうですね!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@syo-tokeshi AbstructNotrifierは同期・非同期に対応しているものと作るライブラリなので使う人は両方が対応されていることを想定しています。ですので両方のテストが欲しいです。

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@komagata

使う人は両方が対応されていることを想定しています

かしこまりました。
だから両方必要なんですね🙇‍♂️

Comment on lines +69 to +70
travel_to Time.zone.local(2023, 5, 5, 6, 0, 0) do
visit_with_auth '/scheduler/daily/notify_coming_soon_regular_events', 'komagata'
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

スケジューラへのリクエストは非ログインでもOKに変更されたようなので、予想外のテストエラーを予防する意味で仕様と合わせた方が良さそうに思いました!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

情報ありがとうございます!!🙇‍♂️

確認し、修正致しました😄

Comment on lines +45 to +46
today_events = params[:today_events] || RegularEvent.today_events
tomorrow_events = params[:tomorrow_events] || RegularEvent.tomorrow_events
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

変更前のコードもパラメータからの代入のみとなっているので、OR演算子以降の部分は削除しても支障はなさそうですが、いかがでしょうか? ( もし、開催するイベントが無い場合はコントローラー側と同じ処理を実行する事になりそう...? )

def tomorrow_regular_event(params = {})
params.merge!(@params)
event = params[:event]

Copy link
Copy Markdown
Contributor Author

@toke04 toke04 Jun 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

その通りでした、、
コントローラーから処理がスタートして、
eventのパラメーターを渡しているので、OR演算子以降はいらないですね、、🙇‍♂️

def notify_coming_soon_regular_events
today_events = RegularEvent.today_events
tomorrow_events = RegularEvent.tomorrow_events
return if today_events.blank? && tomorrow_events.blank?
NotificationFacade.coming_soon_regular_events(today_events, tomorrow_events)

ご指摘ありがとうございます🙇‍♂️

@toke04
Copy link
Copy Markdown
Contributor Author

toke04 commented Jun 4, 2023

@ymmtd0x0b
代替案まで出してくれて本当にありがとうございます🙇‍♂️
もの凄く勉強になりました🙇‍♂️
有意義な時間ありがとうございます😊

@toke04 toke04 requested a review from komagata June 4, 2023 15:07
@toke04
Copy link
Copy Markdown
Contributor Author

toke04 commented Jun 7, 2023

@machida
お疲れ様です。
今日MTGで話しましたDiscordへの通知の文言の修正完了しました🙇‍♂️

こちらでよろしいでしょうか?
通知の文言の微調整を行う

変更点

  • 曜日の後ろに)を付与
  • ⚠️ の後ろのスペースを「半角」に変更

[旧]
旧

[新]
新

[新しい通知の全体スクショ]
スクリーンショット 2023-06-07 19 11 41

@machida
Copy link
Copy Markdown
Member

machida commented Jun 7, 2023

@syo-tokeshi 確認しましたー👍
これでレビューに進めてくださいー
対応ありがとうございます🙏

@toke04 toke04 force-pushed the feature/change_event_notification_to_discord branch from 7f8c540 to 63e08a0 Compare June 11, 2023 03:21
@toke04
Copy link
Copy Markdown
Contributor Author

toke04 commented Jun 11, 2023

@komagata
お疲れ様です。
一件だけ対応しました🙇‍♂️
ご確認よろしくお願い致します
#6565 (comment)

Copy link
Copy Markdown
Member

@komagata komagata left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

確認させて頂きました。OKです〜🙆‍♂️

travel_to Time.zone.local(2022, 7, 30, 0, 0, 0) do
visit_with_auth '/scheduler/daily/notify_tomorrow_regular_event', 'komagata'
travel_to Time.zone.local(2023, 5, 5, 6, 0, 0) do
visit '/scheduler/daily/notify_coming_soon_regular_events'
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@komagata komagata merged commit b39c3d6 into main Jun 20, 2023
@komagata komagata deleted the feature/change_event_notification_to_discord branch June 20, 2023 15:00
@github-actions github-actions bot mentioned this pull request Jun 20, 2023
13 tasks
@machida
Copy link
Copy Markdown
Member

machida commented Jul 17, 2023

@komagata こちらの通知が本番で飛んでないそうです。確認をお願いします。

@syo-tokeshi 足りない情報がありましたらこちらに追記お願いします。

@komagata
Copy link
Copy Markdown
Member

@machida かしこまりました。

@syo-tokeshi 僕のミスで本番で該当URLが毎日アクセスされる設定がされておりませんでした。先ほど設定して実行したので再度確認いただければありがたいです。

@toke04
Copy link
Copy Markdown
Contributor Author

toke04 commented Jul 18, 2023

@machida かしこまりました。

@syo-tokeshi 僕のミスで本番で該当URLが毎日アクセスされる設定がされておりませんでした。先ほど設定して実行したので再度確認いただければありがたいです。

@komagata
ご確認ありがとうございます🙇‍♂️

かしこまりました!
明日、チャットを確認しましたら、結果報告します🙇‍♂️

@toke04
Copy link
Copy Markdown
Contributor Author

toke04 commented Jul 19, 2023

@komagata
Discordに通知が来ていることが確認できたのでcloseさせて頂きます🙇‍♂️

ご対応ありがとうございました🙇‍♂️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants