Skip to content

Commit 06c8426

Browse files
committed
feat: add tomorrow comand
1 parent d54841f commit 06c8426

File tree

12 files changed

+49
-11
lines changed

12 files changed

+49
-11
lines changed

serverless/dispatcher/internal/handler/command.go

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ const (
4040
startCommand command = "start"
4141
helpCommand command = "help"
4242
todayCommand command = "today"
43+
tomorrowCommand command = "tomorrow"
4344
dateCommand command = "date" // 2 stages
4445
nextCommand command = "next"
4546
remindCommand command = "remind" // 1 stage
@@ -88,7 +89,7 @@ func (h *Handler) help(ctx context.Context, b *bot.Bot, _ *models.Update) error
8889
func (h *Handler) today(ctx context.Context, b *bot.Bot, _ *models.Update) error {
8990
chat := getContextChat(ctx)
9091

91-
prayerDay, err := h.db.GetPrayerDay(ctx, chat.BotID, h.now(chat.BotID))
92+
prayerDay, err := h.db.GetPrayerDay(ctx, chat.BotID, h.nowDateUTC(chat.BotID))
9293
if err != nil {
9394
log.Error("today: get prayer day", log.Err(err), log.BotID(chat.BotID), log.ChatID(chat.ChatID))
9495
return domain.ErrInternal
@@ -107,6 +108,29 @@ func (h *Handler) today(ctx context.Context, b *bot.Bot, _ *models.Update) error
107108
return nil
108109
}
109110

111+
func (h *Handler) tomorrow(ctx context.Context, b *bot.Bot, _ *models.Update) error {
112+
chat := getContextChat(ctx)
113+
114+
tomorrow := h.nowDateUTC(chat.BotID).Add(24 * time.Hour)
115+
prayerDay, err := h.db.GetPrayerDay(ctx, chat.BotID, tomorrow)
116+
if err != nil {
117+
log.Error("tomorrow: get prayer day", log.Err(err), log.BotID(chat.BotID), log.ChatID(chat.ChatID))
118+
return domain.ErrInternal
119+
}
120+
121+
_, err = b.SendMessage(ctx, &bot.SendMessageParams{
122+
ChatID: chat.ChatID,
123+
Text: h.formatPrayerDay(chat.BotID, prayerDay, chat.LanguageCode),
124+
})
125+
if err != nil {
126+
log.Error("tomorrow: send message", log.Err(err), log.BotID(chat.BotID), log.ChatID(chat.ChatID))
127+
return domain.ErrInternal
128+
}
129+
130+
h.resetState(ctx, chat)
131+
return nil
132+
}
133+
110134
func (h *Handler) date(ctx context.Context, b *bot.Bot, _ *models.Update) error {
111135
chat := getContextChat(ctx)
112136

@@ -129,7 +153,7 @@ func (h *Handler) next(ctx context.Context, b *bot.Bot, _ *models.Update) error
129153

130154
var (
131155
now = h.now(chat.BotID)
132-
date = now.Truncate(24 * time.Hour)
156+
date = h.nowDateUTC(chat.BotID)
133157
)
134158

135159
prayerDay, err := h.db.GetPrayerDay(ctx, chat.BotID, date)

serverless/dispatcher/internal/handler/handler.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ func (h *Handler) opts() []bot.Option {
6363
bot.WithMessageTextHandler(startCommand.String(), bot.MatchTypeCommandStartOnly, h.errorH(h.chatH(h.start))),
6464
bot.WithMessageTextHandler(helpCommand.String(), bot.MatchTypeCommand, h.errorH(h.chatH(h.help))),
6565
bot.WithMessageTextHandler(todayCommand.String(), bot.MatchTypeCommand, h.errorH(h.chatH(h.today))),
66+
bot.WithMessageTextHandler(tomorrowCommand.String(), bot.MatchTypeCommand, h.errorH(h.chatH(h.tomorrow))),
6667
bot.WithMessageTextHandler(dateCommand.String(), bot.MatchTypeCommand, h.errorH(h.chatH(h.date))),
6768
bot.WithMessageTextHandler(nextCommand.String(), bot.MatchTypeCommand, h.errorH(h.chatH(h.next))),
6869
bot.WithMessageTextHandler(remindCommand.String(), bot.MatchTypeCommand, h.errorH(h.chatH(h.remind))),

serverless/dispatcher/internal/handler/helper.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ func (h *Handler) now(botID int64) time.Time {
5353
return time.Now().In(h.cfg[botID].Location.V()).Truncate(time.Minute)
5454
}
5555

56+
func (h *Handler) nowDateUTC(botID int64) time.Time {
57+
now := h.now(botID)
58+
return time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.UTC)
59+
}
60+
5661
// daysInMonth returns the number of days in a month.
5762
func daysInMonth(month time.Month, year int) int {
5863
// month is incremented by 1 and day is 0 because we want the last day of the month.

serverless/dispatcher/internal/handler/languages/ar.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ help: |
7171
*الصلاة:*
7272
7373
⏰ /today – مواقيت اليوم
74+
🌅 /tomorrow – مواقيت الغد
7475
📅 /date – مواقيت يوم محدد
7576
⏳ /next – متى الصلاة القادمة؟
7677
📨 /remind – إعدادات التذكير

serverless/dispatcher/internal/handler/languages/en.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ help: |
7171
*Prayers:*
7272
7373
⏰ /today – Today's times
74+
🌅 /tomorrow – Tomorrow's times
7475
📅 /date – Times for a chosen day
7576
⏳ /next – When's the next prayer?
7677
📨 /remind – Configure reminders

serverless/dispatcher/internal/handler/languages/es.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ help: |
7171
*Oraciones:*
7272
7373
⏰ /today – Horarios de hoy
74+
🌅 /tomorrow – Horarios de mañana
7475
📅 /date – Horarios de un día específico
7576
⏳ /next – ¿Cuándo es la próxima oración?
7677
📨 /remind – Configurar recordatorios

serverless/dispatcher/internal/handler/languages/fr.yaml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,14 @@ jamaat_edit:
6666
title: "🕌 Horaire Jamaat %s\n⏱ Temps après l'Adhan"
6767

6868
help: |
69-
Besoin d'aide? 😊 Voici ce que je peux faire : 👇
69+
Besoin d'aide ? 😊 Voici ce que je peux faire : 👇
7070
7171
*Prières:*
7272
7373
⏰ /today – Horaires d'aujourd'hui
74+
🌅 /tomorrow – Horaires de demain
7475
📅 /date – Horaires pour une date choisie
75-
⏳ /next – Quand est la prochaine prière?
76+
⏳ /next – Quand est la prochaine prière ?
7677
📨 /remind – Configurer les rappels
7778
7879
*Paramètres:*
@@ -86,12 +87,12 @@ help: |
8687
💬 /feedback – Envoyer un retour
8788
8889
feedback:
89-
start: "💬 Partagez vos commentaires! (ou tapez /cancel pour arrêter)"
90-
success: "✅ Merci! Votre commentaire a été envoyé"
90+
start: "💬 Partagez vos commentaires ! (ou tapez /cancel pour arrêter)"
91+
success: "✅ Merci ! Votre commentaire a été envoyé"
9192

9293
bug:
9394
start: "🐞 Décrivez le bug rencontré (ou tapez /cancel pour arrêter)"
94-
success: "✅ Merci! Votre rapport a été reçu"
95+
success: "✅ Merci ! Votre rapport a été reçu"
9596

9697
help_admin: |
9798
📊 /info – Voir les infos et paramètres du chat

serverless/dispatcher/internal/handler/languages/ru.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ help: |
7171
*Молитвы:*
7272
7373
⏰ /today – Время молитв на сегодня
74+
🌅 /tomorrow – Время молитв на завтра
7475
📅 /date – Время молитв на выбранный день
7576
⏳ /next – Когда следующая молитва?
7677
📨 /remind – Настроить напоминания

serverless/dispatcher/internal/handler/languages/tr.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ help: |
7171
*Namazlar:*
7272
7373
⏰ /today – Şu günki wagtlar
74+
🌅 /tomorrow – Ertirki wagtlar
7475
📅 /date – Saýlanan gün üçin wagtlar
7576
⏳ /next – Indiki namaz haçan?
7677
📨 /remind – Duýduryşlary sazlamak

serverless/dispatcher/internal/handler/languages/tt.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ help: |
7171
*Намазлар:*
7272
7373
⏰ /today – Бүгенге вакытлар
74+
🌅 /tomorrow – Иртәгәге вакытлар
7475
📅 /date – Күрсәтелгән көн өчен вакытлар
7576
⏳ /next – Киләсе намаз кайчан?
7677
📨 /remind – Хәтерләтүләрне көйләргә

0 commit comments

Comments
 (0)