@@ -3,6 +3,7 @@ package handler
33import (
44 "context"
55 "fmt"
6+ "strings"
67 "time"
78
89 "github.com/escalopa/prayer-bot/domain"
@@ -11,7 +12,7 @@ import (
1112)
1213
1314type ReminderType interface {
14- ShouldTrigger (ctx context.Context , chat * domain.Chat , prayerDay * domain.PrayerDay , now time.Time ) (shouldSend bool , prayerID domain.PrayerID , nextLastAt time. Time )
15+ ShouldTrigger (ctx context.Context , chat * domain.Chat , prayerDay * domain.PrayerDay , now time.Time ) (shouldSend bool , prayerID domain.PrayerID )
1516 Send (ctx context.Context , b * bot.Bot , chat * domain.Chat , prayerID domain.PrayerID , prayerDay * domain.PrayerDay ) (messageID int , err error )
1617 Name () domain.ReminderType
1718}
@@ -22,18 +23,13 @@ type TomorrowReminder struct {
2223 formatPrayerDay func (botID int64 , prayerDay * domain.PrayerDay , languageCode string ) string
2324}
2425
25- func (r * TomorrowReminder ) ShouldTrigger (ctx context.Context , chat * domain.Chat , prayerDay * domain.PrayerDay , now time.Time ) (bool , domain.PrayerID , time. Time ) {
26+ func (r * TomorrowReminder ) ShouldTrigger (ctx context.Context , chat * domain.Chat , _ * domain.PrayerDay , now time.Time ) (bool , domain.PrayerID ) {
2627 config := chat .Reminder .Tomorrow
2728
2829 // Trigger logic: last_at + 24h - offset < now
29- lastDate := config .LastAt .Truncate (24 * time .Hour )
30- triggerTime := lastDate .Add (24 * time .Hour ).Add (- config .Offset )
31- shouldSend := triggerTime .Before (now ) || triggerTime .Equal (now )
32-
33- // Next LastAt should be tomorrow's date (midnight) to prevent re-triggering on the same day
34- nextLastAt := now .Truncate (24 * time .Hour ).Add (24 * time .Hour )
35-
36- return shouldSend , domain .PrayerIDUnknown , nextLastAt
30+ triggerTime := config .LastAt .Truncate (24 * time .Hour ).Add (24 * time .Hour ).Add (- config .Offset )
31+ shouldSend := config .LastAt .Before (triggerTime ) && (triggerTime .Before (now ) || triggerTime .Equal (now ))
32+ return shouldSend , domain .PrayerIDUnknown
3733}
3834
3935func (r * TomorrowReminder ) Send (ctx context.Context , b * bot.Bot , chat * domain.Chat , _ domain.PrayerID , prayerDay * domain.PrayerDay ) (int , error ) {
@@ -55,7 +51,7 @@ type SoonReminder struct {
5551 lp * languagesProvider
5652}
5753
58- func (r * SoonReminder ) ShouldTrigger (ctx context.Context , chat * domain.Chat , prayerDay * domain.PrayerDay , now time.Time ) (bool , domain.PrayerID , time. Time ) {
54+ func (r * SoonReminder ) ShouldTrigger (ctx context.Context , chat * domain.Chat , prayerDay * domain.PrayerDay , now time.Time ) (bool , domain.PrayerID ) {
5955 prayers := []struct {
6056 id domain.PrayerID
6157 time time.Time
@@ -77,10 +73,10 @@ func (r *SoonReminder) ShouldTrigger(ctx context.Context, chat *domain.Chat, pra
7773 if config .LastAt .Before (trigger ) && (trigger .Before (now ) || trigger .Equal (now )) {
7874 // // Next LastAt should be incremented by 1 minute to avoid re-triggering
7975 // nextLastAt := now.Add(1 * time.Minute)
80- return true , p .id , now
76+ return true , p .id
8177 }
8278 }
83- return false , 0 , time. Time {}
79+ return false , 0
8480}
8581
8682func (r * SoonReminder ) Send (ctx context.Context , b * bot.Bot , chat * domain.Chat , prayerID domain.PrayerID , prayerDay * domain.PrayerDay ) (int , error ) {
@@ -92,8 +88,8 @@ func (r *SoonReminder) Send(ctx context.Context, b *bot.Bot, chat *domain.Chat,
9288 if chat .Reminder .Jamaat .Enabled && prayerID != domain .PrayerIDShuruq {
9389 delay := chat .Reminder .Jamaat .Delay .GetDelayByPrayerID (prayerID )
9490 message := fmt .Sprintf ("%s\n %s" ,
95- fmt .Sprintf (text .PrayerSoon , prayer , domain .FormatDuration (chat .Reminder .Soon .Offset )),
96- fmt .Sprintf (text .PrayerJamaat , domain .FormatDuration (delay )),
91+ fmt .Sprintf (strings . ReplaceAll ( text .PrayerSoon , "*" , "" ) , prayer , domain .FormatDuration (chat .Reminder .Soon .Offset )),
92+ fmt .Sprintf (strings . ReplaceAll ( text .PrayerJamaat , "*" , "" ), domain .FormatDuration (delay + chat . Reminder . Soon . Offset )),
9793 )
9894 isAnonymous := false
9995
@@ -134,7 +130,7 @@ type ArriveReminder struct {
134130 lp * languagesProvider
135131}
136132
137- func (r * ArriveReminder ) ShouldTrigger (ctx context.Context , chat * domain.Chat , prayerDay * domain.PrayerDay , now time.Time ) (bool , domain.PrayerID , time. Time ) {
133+ func (r * ArriveReminder ) ShouldTrigger (ctx context.Context , chat * domain.Chat , prayerDay * domain.PrayerDay , now time.Time ) (bool , domain.PrayerID ) {
138134 config := chat .Reminder .Arrive
139135
140136 prayers := []struct {
@@ -151,14 +147,11 @@ func (r *ArriveReminder) ShouldTrigger(ctx context.Context, chat *domain.Chat, p
151147
152148 for _ , p := range prayers {
153149 // logic: last_at < prayer_time AND prayer_time <= now
154- if config .LastAt .Before (p .time ) &&
155- (p .time .Before (now ) || p .time .Equal (now )) {
156- // // Next LastAt should be incremented by 1 minute to avoid re-triggering
157- // nextLastAt := now.Add(1 * time.Minute)
158- return true , p .id , now
150+ if config .LastAt .Before (p .time ) && (p .time .Before (now ) || p .time .Equal (now )) {
151+ return true , p .id
159152 }
160153 }
161- return false , 0 , time. Time {}
154+ return false , 0
162155}
163156
164157func (r * ArriveReminder ) Send (ctx context.Context , b * bot.Bot , chat * domain.Chat , prayerID domain.PrayerID , prayerDay * domain.PrayerDay ) (int , error ) {
0 commit comments