Skip to content

Commit

Permalink
Merge pull request #472 from traPtitech/feat/daily_notify_update
Browse files Browse the repository at this point in the history
daily notify の更新
  • Loading branch information
Takeno-hito authored Oct 5, 2023
2 parents a05d57b + 0562d6c commit f15d295
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
20 changes: 12 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},
}
roomAvailable := makeRoomAvailableByTimeTable(rooms, timeTables, t)

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

}
return roomMessage + eventMessage

return fmt.Sprintf("## %s の進捗部屋\n%s## %s 開催予定のイベント\n%s", date, roomMessage, date, eventMessage)
}
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},
}

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

0 comments on commit f15d295

Please sign in to comment.