Skip to content

Commit 7f8d479

Browse files
committed
feat: update serverless
1 parent f09b49e commit 7f8d479

File tree

25 files changed

+182
-272
lines changed

25 files changed

+182
-272
lines changed

_scripts/migrate/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ go run main.go
3535
3. Transforms the data:
3636
- Most fields remain the same (chat_id, bot_id, language_code, state, subscribed, subscribed_at, created_at)
3737
- Creates new `reminder` JSON object with:
38-
- `today`: LastAt set to current time (Moscow timezone)
38+
- `tomorrow`: LastAt set to current time (Moscow timezone)
3939
- `soon`: Offset from old `reminder_offset`, MessageID from old `reminder_message_id`
4040
- `arrive`: MessageID from old `jamaat_message_id`
4141
- `jamaat`: Enabled if both `subscribed` and `jamaat` were true, with default delay configs
@@ -50,9 +50,10 @@ The script uses UPSERT statements, making it safe to run multiple times. Subsequ
5050
### Reminder Field
5151

5252
The reminder JSON structure:
53+
5354
```json
5455
{
55-
"today": {
56+
"tomorrow": {
5657
"offset": 0,
5758
"message_id": 0,
5859
"last_at": "2025-10-26T12:00:00+03:00"

_scripts/migrate/main.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ type ReminderConfig struct {
4343
}
4444

4545
type Reminder struct {
46-
Today *ReminderConfig `json:"today"`
47-
Soon *ReminderConfig `json:"soon"`
48-
Arrive *ReminderConfig `json:"arrive"`
49-
Jamaat *JamaatConfig `json:"jamaat"`
46+
Tomorrow *ReminderConfig `json:"tomorrow"`
47+
Soon *ReminderConfig `json:"soon"`
48+
Arrive *ReminderConfig `json:"arrive"`
49+
Jamaat *JamaatConfig `json:"jamaat"`
5050
}
5151

5252
// Old table row structure
@@ -216,7 +216,7 @@ func transformChat(oldChat OldChat, moscowLocation *time.Location) (NewChat, err
216216
}
217217

218218
reminder := Reminder{
219-
Today: &ReminderConfig{
219+
Tomorrow: &ReminderConfig{
220220
Offset: int64(3 * time.Hour),
221221
LastAt: now.Format(time.RFC3339),
222222
},

serverless/dispatcher/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/escalopa/prayer-bot/dispatcher
33
go 1.21
44

55
require (
6-
github.com/escalopa/prayer-bot v0.0.0-20251026200218-6f6adf300279
6+
github.com/escalopa/prayer-bot v0.0.0-20251026202753-f09b49eedd92
77
github.com/go-telegram/bot v1.15.0
88
github.com/ydb-platform/ydb-go-genproto v0.0.0-20241112172322-ea1f63298f77
99
github.com/ydb-platform/ydb-go-sdk/v3 v3.108.0

serverless/dispatcher/go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,10 @@ github.com/escalopa/prayer-bot v0.0.0-20251026194015-725e9cfbd15d h1:+Dv3qCKHoRc
579579
github.com/escalopa/prayer-bot v0.0.0-20251026194015-725e9cfbd15d/go.mod h1:HOpIxziLKMTC/a+Q6z40Rn5tJDEZsFyzhniLA4iB2i0=
580580
github.com/escalopa/prayer-bot v0.0.0-20251026200218-6f6adf300279 h1:qc+7zybygYoH1yz948TjHe/uQ6QliqSwEVEd8O9rxug=
581581
github.com/escalopa/prayer-bot v0.0.0-20251026200218-6f6adf300279/go.mod h1:HOpIxziLKMTC/a+Q6z40Rn5tJDEZsFyzhniLA4iB2i0=
582+
github.com/escalopa/prayer-bot v0.0.0-20251026201902-b5254b301c89 h1:+jbrcX4CpaKUZs0gG+1QbpVENyN9NVbdZLQJOO+d/q0=
583+
github.com/escalopa/prayer-bot v0.0.0-20251026201902-b5254b301c89/go.mod h1:HOpIxziLKMTC/a+Q6z40Rn5tJDEZsFyzhniLA4iB2i0=
584+
github.com/escalopa/prayer-bot v0.0.0-20251026202753-f09b49eedd92 h1:CZ80HIK0Duq/Rjo1Q+zzFFRNM3mER2fbxBryYu4SFaE=
585+
github.com/escalopa/prayer-bot v0.0.0-20251026202753-f09b49eedd92/go.mod h1:HOpIxziLKMTC/a+Q6z40Rn5tJDEZsFyzhniLA4iB2i0=
582586
github.com/fogleman/gg v1.2.1-0.20190220221249-0403632d5b90/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k=
583587
github.com/fogleman/gg v1.3.0/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k=
584588
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=

serverless/dispatcher/internal/handler/handler.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,10 @@ func (h *Handler) opts() []bot.Option {
8484
bot.WithCallbackQueryDataHandler(remindToggleQuery.String(), bot.MatchTypePrefix, h.errorH(h.chatH(h.remindToggleQuery))),
8585
bot.WithCallbackQueryDataHandler(remindEditQuery.String(), bot.MatchTypePrefix, h.errorH(h.chatH(h.remindEditQuery))),
8686
bot.WithCallbackQueryDataHandler(remindAdjustQuery.String(), bot.MatchTypePrefix, h.errorH(h.chatH(h.remindAdjustQuery))),
87-
bot.WithCallbackQueryDataHandler(remindSaveQuery.String(), bot.MatchTypePrefix, h.errorH(h.chatH(h.remindSaveQuery))),
8887
bot.WithCallbackQueryDataHandler(remindJamaatMenuQuery.String(), bot.MatchTypePrefix, h.errorH(h.chatH(h.remindJamaatMenuQuery))),
8988
bot.WithCallbackQueryDataHandler(remindJamaatToggleQuery.String(), bot.MatchTypePrefix, h.errorH(h.chatH(h.remindJamaatToggleQuery))),
9089
bot.WithCallbackQueryDataHandler(remindJamaatEditQuery.String(), bot.MatchTypePrefix, h.errorH(h.chatH(h.remindJamaatEditQuery))),
9190
bot.WithCallbackQueryDataHandler(remindJamaatAdjustQuery.String(), bot.MatchTypePrefix, h.errorH(h.chatH(h.remindJamaatAdjustQuery))),
92-
bot.WithCallbackQueryDataHandler(remindJamaatSaveQuery.String(), bot.MatchTypePrefix, h.errorH(h.chatH(h.remindJamaatSaveQuery))),
9391
bot.WithCallbackQueryDataHandler(remindBackQuery.String(), bot.MatchTypePrefix, h.errorH(h.chatH(h.remindBackQuery))),
9492
bot.WithCallbackQueryDataHandler(remindCloseQuery.String(), bot.MatchTypePrefix, h.errorH(h.chatH(h.remindCloseQuery))),
9593
}
@@ -242,7 +240,7 @@ func (h *Handler) getChat(ctx context.Context, update *models.Update) (*domain.C
242240

243241
now := h.now(botID)
244242
reminder := &domain.Reminder{
245-
Today: &domain.ReminderConfig{
243+
Tomorrow: &domain.ReminderConfig{
246244
LastAt: now,
247245
Offset: 3 * time.Hour,
248246
},

serverless/dispatcher/internal/handler/helper.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,8 @@ func parseAdjustment(adj string) time.Duration {
8787
}
8888
return 0
8989
}
90+
91+
// isChatGroup checks if the chat is a group or supergroup.
92+
func isChatGroup(chatID int64) bool {
93+
return chatID < 0
94+
}

serverless/dispatcher/internal/handler/keyboard.go

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ const (
1414
monthsPerRow = 3
1515
remindPerRow = 4
1616
daysPerRow = 5
17+
18+
buttonBack = "🔙"
1719
)
1820

1921
func (h *Handler) languagesKeyboard() *models.InlineKeyboardMarkup {
@@ -93,39 +95,50 @@ func (h *Handler) daysKeyboard(now time.Time, month int) *models.InlineKeyboardM
9395
func (h *Handler) remindMenuKeyboard(chat *domain.Chat) *models.InlineKeyboardMarkup {
9496
text := h.lp.GetText(chat.LanguageCode)
9597

96-
kb := &models.InlineKeyboardMarkup{InlineKeyboard: make([][]models.InlineKeyboardButton, 4)}
98+
// Calculate number of rows based on whether it's a group
99+
numRows := 3
100+
if isChatGroup(chat.ChatID) {
101+
numRows = 4
102+
}
103+
kb := &models.InlineKeyboardMarkup{InlineKeyboard: make([][]models.InlineKeyboardButton, numRows)}
104+
105+
rowIndex := 0
97106

98107
if chat.Subscribed {
99-
kb.InlineKeyboard[0] = []models.InlineKeyboardButton{
108+
kb.InlineKeyboard[rowIndex] = []models.InlineKeyboardButton{
100109
{Text: text.RemindMenu.Disable, CallbackData: "remind:toggle|"},
101110
}
102111
} else {
103-
kb.InlineKeyboard[0] = []models.InlineKeyboardButton{
112+
kb.InlineKeyboard[rowIndex] = []models.InlineKeyboardButton{
104113
{Text: text.RemindMenu.Enable, CallbackData: "remind:toggle|"},
105114
}
106115
}
116+
rowIndex++
107117

108-
todayOffset := domain.FormatDuration(chat.Reminder.Today.Offset)
118+
tomorrowOffset := domain.FormatDuration(chat.Reminder.Tomorrow.Offset)
109119
soonOffset := domain.FormatDuration(chat.Reminder.Soon.Offset)
110-
kb.InlineKeyboard[1] = []models.InlineKeyboardButton{
111-
{Text: fmt.Sprintf("%s (%s)", text.RemindMenu.Today, todayOffset), CallbackData: "remind:edit:today|"},
120+
kb.InlineKeyboard[rowIndex] = []models.InlineKeyboardButton{
121+
{Text: fmt.Sprintf("%s (%s)", text.RemindMenu.Tomorrow, tomorrowOffset), CallbackData: "remind:edit:tomorrow|"},
112122
{Text: fmt.Sprintf("%s (%s)", text.RemindMenu.Soon, soonOffset), CallbackData: "remind:edit:soon|"},
113123
}
124+
rowIndex++
114125

115-
kb.InlineKeyboard[2] = []models.InlineKeyboardButton{
116-
{Text: text.RemindMenu.JamaatSettings, CallbackData: "remind:jamaat:menu|"},
126+
// Only show Jamaat Settings for group chats
127+
if isChatGroup(chat.ChatID) {
128+
kb.InlineKeyboard[rowIndex] = []models.InlineKeyboardButton{
129+
{Text: text.RemindMenu.JamaatSettings, CallbackData: "remind:jamaat:menu|"},
130+
}
131+
rowIndex++
117132
}
118133

119-
kb.InlineKeyboard[3] = []models.InlineKeyboardButton{
134+
kb.InlineKeyboard[rowIndex] = []models.InlineKeyboardButton{
120135
{Text: text.RemindMenu.Close, CallbackData: "remind:close|"},
121136
}
122137

123138
return kb
124139
}
125140

126141
func (h *Handler) remindEditKeyboard(reminderType domain.ReminderType, languageCode string) *models.InlineKeyboardMarkup {
127-
text := h.lp.GetText(languageCode)
128-
129142
kb := &models.InlineKeyboardMarkup{InlineKeyboard: make([][]models.InlineKeyboardButton, 3)}
130143

131144
kb.InlineKeyboard[0] = []models.InlineKeyboardButton{
@@ -141,8 +154,7 @@ func (h *Handler) remindEditKeyboard(reminderType domain.ReminderType, languageC
141154
}
142155

143156
kb.InlineKeyboard[2] = []models.InlineKeyboardButton{
144-
{Text: text.Buttons.Save, CallbackData: fmt.Sprintf("remind:save:%s|", reminderType)},
145-
{Text: text.Buttons.Back, CallbackData: "remind:back:menu|"},
157+
{Text: buttonBack, CallbackData: "remind:back:menu|"},
146158
}
147159

148160
return kb
@@ -185,15 +197,13 @@ func (h *Handler) jammatMenuKeyboard(chat *domain.Chat) *models.InlineKeyboardMa
185197
}
186198

187199
kb.InlineKeyboard[4] = []models.InlineKeyboardButton{
188-
{Text: text.Buttons.Back, CallbackData: "remind:back:menu|"},
200+
{Text: buttonBack, CallbackData: "remind:back:menu|"},
189201
}
190202

191203
return kb
192204
}
193205

194206
func (h *Handler) jammatEditKeyboard(prayerID domain.PrayerID, languageCode string) *models.InlineKeyboardMarkup {
195-
text := h.lp.GetText(languageCode)
196-
197207
kb := &models.InlineKeyboardMarkup{InlineKeyboard: make([][]models.InlineKeyboardButton, 3)}
198208

199209
prayerName := prayerID.String()
@@ -211,8 +221,7 @@ func (h *Handler) jammatEditKeyboard(prayerID domain.PrayerID, languageCode stri
211221
}
212222

213223
kb.InlineKeyboard[2] = []models.InlineKeyboardButton{
214-
{Text: text.Buttons.Save, CallbackData: fmt.Sprintf("remind:jamaat:save:%s|", prayerName)},
215-
{Text: text.Buttons.Back, CallbackData: "remind:back:jamaat|"},
224+
{Text: buttonBack, CallbackData: "remind:back:jamaat|"},
216225
}
217226

218227
return kb

serverless/dispatcher/internal/handler/languages.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ type (
3030
TitleDisabled string `yaml:"title_disabled"`
3131
Enable string `yaml:"enable"`
3232
Disable string `yaml:"disable"`
33-
Today string `yaml:"today"`
33+
Tomorrow string `yaml:"tomorrow"`
3434
Soon string `yaml:"soon"`
3535
JamaatSettings string `yaml:"jamaat_settings"`
3636
Close string `yaml:"close"`
3737
}
3838

3939
RemindEditText struct {
40-
TitleToday string `yaml:"title_today"`
41-
TitleSoon string `yaml:"title_soon"`
40+
TitleTomorrow string `yaml:"title_tomorrow"`
41+
TitleSoon string `yaml:"title_soon"`
4242
}
4343

4444
JamaatMenuText struct {

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

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,31 +43,27 @@ language:
4343
success: "✅ تم تغيير اللغة إلى *%s*"
4444

4545
remind_menu:
46-
title_enabled: "⚙️ إعدادات التذكير - مفعّل"
47-
title_disabled: "⚙️ إعدادات التذكير - معطّل"
46+
title_enabled: "⚙️ التذكيرات - مفعّل"
47+
title_disabled: "⚙️ التذكيرات - معطّل 🔕"
4848
enable: "🔔 تفعيل"
4949
disable: "🔕 تعطيل"
50-
today: "⏰ اليوم"
51-
soon: "🔜 قريباً"
52-
jamaat_settings: "🕌 إعدادات الجماعة"
50+
tomorrow: "🌅 معاينة الغد"
51+
soon: "⏰ تنبيه الصلاة"
52+
jamaat_settings: "🕌 مواعيد الجماعة"
5353
close: "❌ إغلاق"
5454

5555
remind_edit:
56-
title_today: "⏰ اليوم"
57-
title_soon: "🔜 قريباً"
56+
title_tomorrow: "🌅 معاينة الغد\n⏰ إرسال مواقيت صلاة الغد قبل منتصف الليل"
57+
title_soon: "⏰ تنبيه الصلاة\n⏱ التذكير قبل كل وقت صلاة"
5858

5959
jamaat_menu:
60-
title_enabled: "🕌 إعدادات الجماعة - مفعّل"
61-
title_disabled: "🕌 إعدادات الجماعة - معطّل"
60+
title_enabled: "🕌 مواعيد الجماعة - مفعّل\n(للمجموعات فقط)"
61+
title_disabled: "🕌 مواعيد الجماعة - معطّل 🔕\n(للمجموعات فقط)"
6262
enable: "🔔 تفعيل"
6363
disable: "🔕 تعطيل"
6464

6565
jamaat_edit:
66-
title: "تأخير جماعة %s"
67-
68-
buttons:
69-
save: "💾"
70-
back: "🔙"
66+
title: "🕌 موعد جماعة %s\n⏱ الوقت بعد الأذان"
7167

7268
help: |
7369
هل تحتاج مساعدة؟ 😊 إليك ما يمكنني فعله: 👇

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

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,31 +43,27 @@ language:
4343
success: "✅ Language changed to *%s*"
4444

4545
remind_menu:
46-
title_enabled: "⚙️ Configure Reminders - Enabled"
47-
title_disabled: "⚙️ Configure Reminders - Disabled"
46+
title_enabled: "⚙️ Reminders - Enabled"
47+
title_disabled: "⚙️ Reminders - Disabled 🔕"
4848
enable: "🔔 Enable"
4949
disable: "🔕 Disable"
50-
today: "⏰ Today"
51-
soon: "🔜 Soon"
52-
jamaat_settings: "🕌 Jamaat Settings"
50+
tomorrow: "🌅 Tomorrow Preview"
51+
soon: "⏰ Prayer Alert"
52+
jamaat_settings: "🕌 Jamaat Times"
5353
close: "❌ Close"
5454

5555
remind_edit:
56-
title_today: "⏰ Today"
57-
title_soon: "🔜 Soon"
56+
title_tomorrow: "🌅 Tomorrow Preview\n⏰ Send tomorrow's prayer times before midnight"
57+
title_soon: "⏰ Prayer Alert\n⏱ Remind before each prayer time"
5858

5959
jamaat_menu:
60-
title_enabled: "🕌 Jamaat Settings - Enabled"
61-
title_disabled: "🕌 Jamaat Settings - Disabled"
60+
title_enabled: "🕌 Jamaat Times - Enabled\n(Group Only)"
61+
title_disabled: "🕌 Jamaat Times - Disabled 🔕\n(Group Only)"
6262
enable: "🔔 Enable"
6363
disable: "🔕 Disable"
6464

6565
jamaat_edit:
66-
title: "%s Jamaat Delay"
67-
68-
buttons:
69-
save: "💾"
70-
back: "🔙"
66+
title: "🕌 %s Jamaat Time\n⏱ Time after Adhan"
7167

7268
help: |
7369
Need help? 😊 Here's what I can do: 👇

0 commit comments

Comments
 (0)