Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

daily notify の更新 #472

Merged
merged 4 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions utils/cron.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ func InitPostEventToTraQ(repo *db.GormRepository, secret, channelID, webhookID,
rooms, _ := repo.GetAllRooms(now, tomorrow, uuid.Nil)
events, _ := repo.GetAllEvents(filter.FilterTime(now, tomorrow))
message := createMessage(now, rooms, events, origin)
_ = RequestWebhook(message, secret, channelID, webhookID, 1)
err := RequestWebhook(message, secret, channelID, webhookID, 1)
if err != nil {
fmt.Println(err)
}
}

return job
Expand Down Expand Up @@ -106,7 +109,7 @@ func createMessage(t time.Time, rooms []*domain.Room, events []*db.Event, origin
var verifiedRoomNames []string

if len(rooms) == 0 {
roomMessage = fmt.Sprintf("%sの進捗部屋は、予約を取っていないようです。\n", date)
roomMessage = "本日は予約を取っていないようです。\n"
} else {
for _, room := range rooms {
if room.Verified && !slices.Contains(verifiedRoomNames, room.Place) {
Expand All @@ -115,17 +118,17 @@ func createMessage(t time.Time, rooms []*domain.Room, events []*db.Event, origin
}

if len(verifiedRoomNames) == 0 {
roomMessage = fmt.Sprintf("%sの進捗部屋は、予約を取っていないようです。\n", date)
roomMessage = "本日は予約を取っていないようです。\n"
} else {
timeTables := []timeTable{
{":sunny:", setTimeFromString(t, "00:00:00"), false},
{"1-2", setTimeFromString(t, "08:50:00"), true},
{"3-4", setTimeFromString(t, "10:45:00"), true},
{"昼", setTimeFromString(t, "12:25:00"), true},
{"5-6", setTimeFromString(t, "13:45:00"), true},
{"7-8", setTimeFromString(t, "15:40:00"), true},
{"9-10", setTimeFromString(t, "17:30:00"), true},
{":crescent_moon:", setTimeFromString(t, "19:10:00"), false},
{"5-6", setTimeFromString(t, "13:30:00"), true},
{"7-8", setTimeFromString(t, "15:25:00"), true},
{"9-10", setTimeFromString(t, "17:15:00"), true},
{":crescent_moon:", setTimeFromString(t, "18:55:00"), false},
Comment on lines -125 to +131
Copy link
Member

Choose a reason for hiding this comment

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

IMO: 頻繁に変わるなら設定ファイルで持てるとうれしい (PR外)

Copy link
Member Author

Choose a reason for hiding this comment

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

今回でコロナ前の時間割に戻ったので多分これ以上変わらないんじゃないかなーと勝手に予想してます

}
roomAvailable := makeRoomAvailableByTimeTable(rooms, timeTables, t)

Expand Down Expand Up @@ -166,5 +169,7 @@ func createMessage(t time.Time, rooms []*domain.Room, events []*db.Event, origin
}

}
return roomMessage + eventMessage

message := fmt.Sprintf("## %s の進捗部屋\n%s## %s 開催予定のイベント\n%s", date, roomMessage, date, eventMessage)
return message
Takeno-hito marked this conversation as resolved.
Show resolved Hide resolved
}
20 changes: 10 additions & 10 deletions utils/cron_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ func Test_makeRoomAvailableByTimeTable(t *testing.T) {
{"1-2", setTimeFromString(today, "08:50:00"), true},
{"3-4", setTimeFromString(today, "10:45:00"), true},
{"昼", setTimeFromString(today, "12:25:00"), true},
{"5-6", setTimeFromString(today, "13:45:00"), true},
{"7-8", setTimeFromString(today, "15:40:00"), true},
{"9-10", setTimeFromString(today, "17:30:00"), true},
{":crescent_moon:", setTimeFromString(today, "19:10:00"), false},
{"5-6", setTimeFromString(today, "13:30:00"), true},
{"7-8", setTimeFromString(today, "15:25:00"), true},
{"9-10", setTimeFromString(today, "17:15:00"), true},
{":crescent_moon:", setTimeFromString(today, "18:55:00"), false},
Takeno-hito marked this conversation as resolved.
Show resolved Hide resolved
}

stampAvailable := ":white_check_mark:"
Expand All @@ -33,7 +33,7 @@ func Test_makeRoomAvailableByTimeTable(t *testing.T) {
Place: "traP-001",
Verified: true,
TimeStart: setTimeFromString(today, "08:50:00"),
TimeEnd: setTimeFromString(today, "19:10:00"),
TimeEnd: setTimeFromString(today, "18:55:00"),
},
},
want: []map[string]string{
Expand All @@ -53,13 +53,13 @@ func Test_makeRoomAvailableByTimeTable(t *testing.T) {
Place: "traP-001",
Verified: true,
TimeStart: setTimeFromString(today, "08:50:00"),
TimeEnd: setTimeFromString(today, "19:10:00"),
TimeEnd: setTimeFromString(today, "18:55:00"),
},
{
Place: "unverified",
Verified: false,
TimeStart: setTimeFromString(today, "08:50:00"),
TimeEnd: setTimeFromString(today, "19:10:00"),
TimeEnd: setTimeFromString(today, "18:55:00"),
},
},
want: []map[string]string{
Expand Down Expand Up @@ -99,7 +99,7 @@ func Test_makeRoomAvailableByTimeTable(t *testing.T) {
Place: "traP-001",
Verified: true,
TimeStart: setTimeFromString(today, "12:25:00"),
TimeEnd: setTimeFromString(today, "19:10:00"),
TimeEnd: setTimeFromString(today, "18:55:00"),
},
{
Place: "traP-002",
Expand All @@ -110,8 +110,8 @@ func Test_makeRoomAvailableByTimeTable(t *testing.T) {
{
Place: "traP-002",
Verified: true,
TimeStart: setTimeFromString(today, "13:45:00"),
TimeEnd: setTimeFromString(today, "19:10:00"),
TimeStart: setTimeFromString(today, "13:30:00"),
TimeEnd: setTimeFromString(today, "18:55:00"),
},
},
want: []map[string]string{
Expand Down