2022-03-05 18:02:55 +00:00
|
|
|
|
package messages
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"math/rand"
|
2022-09-04 15:32:58 +00:00
|
|
|
|
"strconv"
|
2022-03-05 18:02:55 +00:00
|
|
|
|
"strings"
|
2023-02-10 07:47:09 +00:00
|
|
|
|
"student_bot/date"
|
2022-03-05 18:02:55 +00:00
|
|
|
|
"student_bot/new_year_service"
|
|
|
|
|
"student_bot/parser"
|
|
|
|
|
"time"
|
2022-09-04 12:46:04 +00:00
|
|
|
|
|
|
|
|
|
weather "github.com/3crabs/go-yandex-weather-api"
|
2022-03-05 18:02:55 +00:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func StartMessage() string {
|
|
|
|
|
return "Привет, я Верочка!"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var thanksMessages = []string{
|
|
|
|
|
"Обращайся",
|
|
|
|
|
"Пожалуйста",
|
|
|
|
|
"Всегда рада помочь",
|
|
|
|
|
"Да незачто",
|
|
|
|
|
"Всегда к вашим услугим",
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func ThanksMessage() string {
|
|
|
|
|
return thanksMessages[rand.Intn(len(thanksMessages)-1)]
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-04 15:32:58 +00:00
|
|
|
|
func HelpMessage(chatID int64) string {
|
2023-03-08 08:55:54 +00:00
|
|
|
|
return "Вот чем я могу вам помочь (v1.4.6), отправь:\n\n" +
|
2022-03-05 18:02:55 +00:00
|
|
|
|
"- /ping отобью pong\n" +
|
|
|
|
|
"- /today_lessons покажу расписание на сегодня\n" +
|
|
|
|
|
"- /tomorrow_lessons покажу расписание на завтра\n" +
|
2023-02-10 06:27:39 +00:00
|
|
|
|
"- /all_lessons - пары на несколько дней\n" +
|
2022-03-05 18:02:55 +00:00
|
|
|
|
"- /weather покажу погоду у универа\n" +
|
|
|
|
|
"- /new_year - посчитаю количество дней до нового года\n" +
|
2022-09-04 15:32:58 +00:00
|
|
|
|
"\nНу а больше я пока ничего не умею" +
|
|
|
|
|
"\nВаш chatID: " + strconv.FormatInt(chatID, 10)
|
2022-03-05 18:02:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func PongMessage() string {
|
|
|
|
|
return "pong"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func LessonsMessage(schedule []parser.Lesson, prefix, emptyText string) string {
|
|
|
|
|
if len(schedule) == 0 {
|
|
|
|
|
return emptyText
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s := ""
|
|
|
|
|
if prefix != "" {
|
|
|
|
|
s += prefix + "\n\n"
|
|
|
|
|
}
|
2023-01-10 19:00:07 +00:00
|
|
|
|
endDate := ""
|
2022-03-05 18:02:55 +00:00
|
|
|
|
for _, l := range schedule {
|
2023-02-10 06:27:39 +00:00
|
|
|
|
if endDate != l.TimeStart.Format("02.01") {
|
2023-01-10 19:00:07 +00:00
|
|
|
|
if endDate != "" {
|
|
|
|
|
s += "\n"
|
|
|
|
|
}
|
2023-01-10 19:35:03 +00:00
|
|
|
|
endDate = l.TimeStart.Format("02.01")
|
2023-02-10 08:13:59 +00:00
|
|
|
|
s += date.GetTranslatedWeekday(l.TimeStart) + " " + endDate + "\n"
|
2023-01-10 19:00:07 +00:00
|
|
|
|
}
|
2022-03-05 18:02:55 +00:00
|
|
|
|
if strings.Contains(l.User, "Ярных В.В.") {
|
|
|
|
|
s += "⭐️ "
|
|
|
|
|
}
|
2023-01-10 19:00:07 +00:00
|
|
|
|
l.Name = strings.ReplaceAll(l.Name, l.Place, "")
|
|
|
|
|
l.Name = strings.ReplaceAll(l.Name, "()", "")
|
2023-02-10 06:27:39 +00:00
|
|
|
|
l.Name = strings.ReplaceAll(l.Name, l.TimeStart.Format("15:04"), "")
|
2023-01-10 19:00:07 +00:00
|
|
|
|
l.Name = strings.TrimSpace(l.Name)
|
2023-02-10 08:43:13 +00:00
|
|
|
|
s += fmt.Sprintf("%s %s (%s)\n%s\n", l.TimeMsg, l.Name, l.Place, l.User)
|
2022-03-05 18:02:55 +00:00
|
|
|
|
}
|
|
|
|
|
if prefix != "" {
|
|
|
|
|
s += "\n" +
|
2023-02-10 06:27:39 +00:00
|
|
|
|
"Д — Димитрова 66\n" + // (Филологический, социологический)
|
|
|
|
|
"Л — Ленина 61\n" + // (Математический, биологический)
|
|
|
|
|
"М — Ленина 61а\n" + // (Исторический и географический)
|
|
|
|
|
"С — Социалистический 68" // (Экономический и юридический)
|
2022-03-05 18:02:55 +00:00
|
|
|
|
}
|
|
|
|
|
return s
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func WeatherMessage(w weather.Weather) string {
|
|
|
|
|
return fmt.Sprintf("Сейчас у универа:\n"+
|
|
|
|
|
"%s\n"+
|
|
|
|
|
"Температура: %d°C\n"+
|
|
|
|
|
"Ощущается как: %d°C\n"+
|
|
|
|
|
"Скорость ветра: %dм/с\n"+
|
|
|
|
|
"\nПогода на %s:\n"+
|
|
|
|
|
"%s\n"+
|
|
|
|
|
"Температура: %d°C\n"+
|
|
|
|
|
"Ощущается как: %d°C\n"+
|
|
|
|
|
"Скорость ветра: %dм/с\n",
|
|
|
|
|
w.Fact.GetCondition(),
|
|
|
|
|
w.Fact.Temp,
|
|
|
|
|
w.Fact.FeelsLike,
|
|
|
|
|
w.Fact.WindSpeed,
|
|
|
|
|
w.Forecast.Parts[0].GetPartName(),
|
|
|
|
|
w.Forecast.Parts[0].GetCondition(),
|
|
|
|
|
w.Forecast.Parts[0].TempAvg,
|
|
|
|
|
w.Forecast.Parts[0].FeelsLike,
|
|
|
|
|
w.Forecast.Parts[0].WindSpeed)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func NewYearMessage(message new_year_service.NewYearMessage) string {
|
|
|
|
|
loc := time.FixedZone("UTC+7", +7*60*60)
|
2023-02-10 06:27:39 +00:00
|
|
|
|
ny := time.Date(time.Now().Year()+1, 1, 1, 0, 0, 0, 0, loc)
|
2022-03-05 18:02:55 +00:00
|
|
|
|
now := time.Now().In(loc)
|
|
|
|
|
days := ny.Sub(now).Hours() / 24
|
2022-11-26 09:59:35 +00:00
|
|
|
|
if message.Header != "" {
|
|
|
|
|
return fmt.Sprintf("❄ %s ❄ \n\n%s\n\n%s", toStrDays(int(days)), message.Header, message.Text)
|
|
|
|
|
}
|
|
|
|
|
return fmt.Sprintf("❄ %s ❄ \n\n%s", toStrDays(int(days)), message.Text)
|
2022-03-05 18:02:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func toStrDays(days int) string {
|
|
|
|
|
if days == 0 {
|
|
|
|
|
return "Сегодня новый год!!!"
|
|
|
|
|
}
|
|
|
|
|
if days == 1 {
|
|
|
|
|
return "Новый год завтра!"
|
|
|
|
|
}
|
|
|
|
|
s := ""
|
|
|
|
|
a := days % 10
|
|
|
|
|
if days < 10 {
|
|
|
|
|
switch a {
|
|
|
|
|
case 2:
|
|
|
|
|
s = "дня"
|
|
|
|
|
case 3:
|
|
|
|
|
s = "дня"
|
|
|
|
|
case 4:
|
|
|
|
|
s = "дня"
|
|
|
|
|
default:
|
|
|
|
|
s = "дней"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if days >= 10 && days < 20 {
|
|
|
|
|
s = "дней"
|
|
|
|
|
}
|
|
|
|
|
if days >= 20 {
|
|
|
|
|
switch a {
|
|
|
|
|
case 1:
|
|
|
|
|
s = "день"
|
|
|
|
|
case 2:
|
|
|
|
|
s = "дня"
|
|
|
|
|
case 3:
|
|
|
|
|
s = "дня"
|
|
|
|
|
case 4:
|
|
|
|
|
s = "дня"
|
|
|
|
|
default:
|
|
|
|
|
s = "дней"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return fmt.Sprintf("До нового года %d %s", days, s)
|
|
|
|
|
}
|