Skip to content

Commit

Permalink
Manage title and fallbacktext
Browse files Browse the repository at this point in the history
Also, fix the mod for arrays of weekdays and months
  • Loading branch information
boozec committed Nov 27, 2023
1 parent 0bee321 commit 9324821
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 11 deletions.
2 changes: 1 addition & 1 deletion bot/bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ func executeCommand(bot *tgbotapi.BotAPI, update *tgbotapi.Update, commandIndex
msg := tgbotapi.NewMessage(update.Message.Chat.ID, update.Message.Text)
msg.ReplyMarkup = newCommand.Rows
if _, err := bot.Send(msg); err != nil {
msg = tgbotapi.NewMessage(update.Message.Chat.ID, "Error retrieving lectures")
msg = tgbotapi.NewMessage(update.Message.Chat.ID, "Error sending data")
bot.Send(msg)
}
}
Expand Down
10 changes: 7 additions & 3 deletions bot/callbacks.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package bot

import (
"fmt"
"log"
"regexp"
"strconv"
Expand Down Expand Up @@ -57,12 +58,15 @@ func lecturesCallback(bot *tgbotapi.BotAPI, update *tgbotapi.Update, callback_te
log.Printf("Error [GetTimeTable]: %s\n", err)
}

if response == "" {
response = timetable.FallbackText
} else {
response = fmt.Sprintf(timetable.Title, timetable.Course, year, timeForLectures.Format("2006-01-02")) + "\n\n" + response
}

editConfig := tgbotapi.NewEditMessageText(chatId, messageId, response)
editConfig.ParseMode = tgbotapi.ModeHTML

if response == "" {
editConfig = tgbotapi.NewEditMessageText(chatId, messageId, "Non ci sono lezioni in questo giorno. SMETTILA DI PRESSARMI")
}
_, err = bot.Send(editConfig)
if err != nil {
log.Printf("Error [bot.Send() for the NewEditMessageText]: %s\n", err)
Expand Down
13 changes: 8 additions & 5 deletions model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,12 @@ type Curriculum struct {

// Recognized by a callback string
type Timetable struct {
Course string `json:"course"` // Course title
Name string `json:"name"` // Course name
Type string `json:"type"` // Type (laurea|magistrale|2cycle)
Curriculum string `json:"curricula"` // Curriculum
Course string `json:"course"` // Course title
Name string `json:"name"` // Course name
Type string `json:"type"` // Type (laurea|magistrale|2cycle)
Curriculum string `json:"curricula"` // Curriculum
Title string `json:"title"`
FallbackText string `json:"fallbackText"`
}

// SECTION ACTION STRUCTS DATA
Expand Down Expand Up @@ -150,7 +152,8 @@ type NotLookingForData struct {
}

type Lectures struct {
Description string `json:"description"`
Description string `json:"description"`
FallbackText string `json:"fallbackText"`
}

type ListData struct {
Expand Down
2 changes: 1 addition & 1 deletion model/timetables.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func ChooseTimetableDay(callback_text string) InlineKeyboardRows {
dt := time.Now()

for day := 0; day < 7; day++ {
rows[day] = tgbotapi.NewInlineKeyboardRow(tgbotapi.NewInlineKeyboardButtonData(fmt.Sprintf("%s %d %s", weekdays[dt.Weekday()], dt.Day(), months[dt.Month()]), fmt.Sprintf("%s_day_%d", callback_text, dt.Unix())))
rows[day] = tgbotapi.NewInlineKeyboardRow(tgbotapi.NewInlineKeyboardButtonData(fmt.Sprintf("%s %d %s", weekdays[dt.Weekday()%7], dt.Day(), months[dt.Month()%12]), fmt.Sprintf("%s_day_%d", callback_text, dt.Unix())))
dt = dt.AddDate(0, 0, 1)
}

Expand Down
2 changes: 1 addition & 1 deletion model/timetables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func TestChooseTimetableDay(t *testing.T) {
}

for day := 0; day < 7; day++ {
tests[0].want[day] = tgbotapi.NewInlineKeyboardRow(tgbotapi.NewInlineKeyboardButtonData(fmt.Sprintf("%s %d %s", weekdays[dt.Weekday()], dt.Day(), months[dt.Month()]), fmt.Sprintf("%s_day_%d", "lectures_lm_informatica_software_techniques", dt.Unix())))
tests[0].want[day] = tgbotapi.NewInlineKeyboardRow(tgbotapi.NewInlineKeyboardButtonData(fmt.Sprintf("%s %d %s", weekdays[dt.Weekday()%7], dt.Day(), months[dt.Month()%12]), fmt.Sprintf("%s_day_%d", "lectures_lm_informatica_software_techniques", dt.Unix())))
dt = dt.AddDate(0, 0, 1)
}
for _, tt := range tests {
Expand Down

0 comments on commit 9324821

Please sign in to comment.