mirror of
https://github.com/dancojocaru2000/CfrTrainInfoTelegramBot.git
synced 2025-06-19 10:42:32 +03:00
Compare commits
No commits in common. "f7970ff50fecbe2ae7fff34abff74a655cb43ef0" and "c985a6575ad90187b8c7bcfaca42b0ebf0a2851c" have entirely different histories.
f7970ff50f
...
c985a6575a
1 changed files with 8 additions and 29 deletions
|
@ -26,7 +26,7 @@ const (
|
|||
|
||||
subscribeButton = "Subscribe to updates"
|
||||
unsubscribeButton = "Unsubscribe from updates"
|
||||
viewInWebAppButton = "View in WebApp"
|
||||
openInWebAppButton = "Open in WebApp"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -182,7 +182,7 @@ func HandleTrainNumberCommand(ctx context.Context, trainNumber string, date time
|
|||
}
|
||||
messageText.WriteString(fmt.Sprintf("Next stop: %s, arriving in %s at %s\n", nextStop.Name, arrStr, arrTime.In(utils.Location).Format("15:04")))
|
||||
} else {
|
||||
depStr := ""
|
||||
depStr := "less than 1m"
|
||||
depTime := nextStop.Departure.ScheduleTime.Add(func() time.Duration {
|
||||
if nextStop.Departure.Status != nil {
|
||||
return time.Minute * time.Duration(nextStop.Departure.Status.Delay)
|
||||
|
@ -191,25 +191,12 @@ func HandleTrainNumberCommand(ctx context.Context, trainNumber string, date time
|
|||
}
|
||||
}())
|
||||
depDiff := depTime.Sub(time.Now())
|
||||
if depDiff/(time.Hour*24) >= 1 {
|
||||
depStr += fmt.Sprintf("%dd", depDiff/(time.Hour*24))
|
||||
depDiff = depDiff % (time.Hour * 24)
|
||||
}
|
||||
if depDiff/time.Hour >= 1 {
|
||||
depStr += fmt.Sprintf("%dh", depDiff/time.Hour)
|
||||
depDiff = depDiff % time.Hour
|
||||
}
|
||||
if depDiff/time.Minute >= 1 {
|
||||
depStr += fmt.Sprintf("%dm", depDiff/time.Minute)
|
||||
}
|
||||
if len(depStr) == 0 {
|
||||
depStr = "less than 1m"
|
||||
}
|
||||
if nextStopIdx == 0 {
|
||||
messageText.WriteString(fmt.Sprintf("The train will depart from %s in %s at %s\n", nextStop.Name, depStr, depTime.In(utils.Location).Format("15:04")))
|
||||
} else {
|
||||
messageText.WriteString(fmt.Sprintf("Currently stopped at: %s, departing in %s at %s\n", nextStop.Name, depStr, depTime.In(utils.Location).Format("15:04")))
|
||||
depStr = fmt.Sprintf("%dh%dm", depDiff/time.Hour, (depDiff%time.Hour)/time.Minute)
|
||||
} else if depDiff/time.Minute >= 1 {
|
||||
depStr = fmt.Sprintf("%dm", depDiff/time.Minute)
|
||||
}
|
||||
messageText.WriteString(fmt.Sprintf("Currently stopped at: %s, departing in %s at %s\n", nextStop.Name, depStr, depTime.In(utils.Location).Format("15:04")))
|
||||
}
|
||||
}
|
||||
if group.Status != nil {
|
||||
|
@ -303,16 +290,8 @@ func GetTrainNumberCommandResponseButtons(trainNumber string, date time.Time, gr
|
|||
}
|
||||
result = append(result, []models.InlineKeyboardButton{
|
||||
{
|
||||
Text: viewInWebAppButton,
|
||||
WebApp: &models.WebAppInfo{
|
||||
URL: func() string {
|
||||
miniAppUrl := *kaiUrl
|
||||
miniAppUrlQuery := miniAppUrl.Query()
|
||||
miniAppUrlQuery.Add("tg", "1")
|
||||
miniAppUrl.RawQuery = miniAppUrlQuery.Encode()
|
||||
return miniAppUrl.String()
|
||||
}(),
|
||||
},
|
||||
Text: openInWebAppButton,
|
||||
URL: kaiUrl.String(),
|
||||
},
|
||||
})
|
||||
return models.InlineKeyboardMarkup{
|
||||
|
|
Loading…
Add table
Reference in a new issue