From e48df42bb03054c65e123995c524dde4d04e4451 Mon Sep 17 00:00:00 2001 From: far-galaxy Date: Fri, 24 Mar 2023 17:15:02 +0400 Subject: [PATCH] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=BE:=20=D1=83=D0=B1=D1=80=D0=B0=D0=BD=D0=BE=20=D0=BE=D0=B1?= =?UTF-8?q?=D1=8F=D0=B7=D0=B0=D1=82=D0=B5=D0=BB=D1=8C=D0=BD=D0=BE=D0=B5=20?= =?UTF-8?q?=D0=BF=D0=BE=D0=B4=D0=BA=D0=BB=D1=8E=D1=87=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D0=BA=20=D0=B3=D1=80=D1=83=D0=BF=D0=BF=D0=B5=20=D0=98?= =?UTF-8?q?=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD=D0=BE:=20=D0=BF=D1=80?= =?UTF-8?q?=D0=BE=D0=BF=D1=83=D1=81=D0=BA=20=D0=BF=D0=BE=D0=B4=D1=82=D0=B2?= =?UTF-8?q?=D0=B5=D1=80=D0=B6=D0=B4=D0=B5=D0=BD=D0=B8=D1=8F,=20=D0=B5?= =?UTF-8?q?=D1=81=D0=BB=D0=B8=20=D0=BD=D0=B0=D0=B9=D0=B4=D0=B5=D0=BD=D0=B0?= =?UTF-8?q?=20=D0=B2=D1=81=D0=B5=D0=B3=D0=BE=20=D0=BE=D0=B4=D0=BD=D0=B0=20?= =?UTF-8?q?=D0=B3=D1=80=D1=83=D0=BF=D0=BF=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/tg/handlers.go | 67 ++++++++++++++++++++++++------------------ 1 file changed, 38 insertions(+), 29 deletions(-) diff --git a/modules/tg/handlers.go b/modules/tg/handlers.go index 9002702..a74aec6 100644 --- a/modules/tg/handlers.go +++ b/modules/tg/handlers.go @@ -34,7 +34,7 @@ func (bot *Bot) InitUser(id int64, name string) (*database.TgUser, error) { L9Id: l9id, Name: name, TgId: id, - PosTag: "not_started", + PosTag: "ready", } _, err = db.Insert(user, tg_user) if err != nil { @@ -48,14 +48,14 @@ func (bot *Bot) InitUser(id int64, name string) (*database.TgUser, error) { } func (bot *Bot) Start() error { - bot.TG_user.PosTag = "add" + /*bot.TG_user.PosTag = "add" _, err := bot.DB.Update(bot.TG_user) if err != nil { return err - } + }*/ msg := tgbotapi.NewMessage(bot.TG_user.TgId, "Привет! Введи свой номер группы или фамилию преподавателя") msg.ParseMode = tgbotapi.ModeHTML - _, err = bot.TG.Send(msg) + _, err := bot.TG.Send(msg) return err } @@ -104,7 +104,35 @@ func (bot *Bot) Find(query string) error { } } - if len(allGroups) != 0 { + if len(allGroups) == 1 || len(allTeachers) == 1 { + if bot.TG_user.PosTag == "add" { + msg := tgbotapi.NewMessage(bot.TG_user.TgId, "Подключено!") + keyboard := tgbotapi.NewReplyKeyboard([]tgbotapi.KeyboardButton{tgbotapi.NewKeyboardButton("Главное меню")}) + msg.ReplyMarkup = keyboard + bot.TG.Send(msg) + } else { + var sheduleId int64 + var isGroup bool + if len(allGroups) == 1 { + sheduleId = allGroups[0].GroupId + isGroup = true + } else { + sheduleId = allTeachers[0].TeacherId + isGroup = false + } + shedule := database.ShedulesInUser{ + IsTeacher: !isGroup, + SheduleId: sheduleId, + } + err := bot.GetSummary([]database.ShedulesInUser{shedule}, false) + if err != nil { + return err + } + } + bot.TG_user.PosTag = "ready" + err := bot.UpdateUserDB() + return err + } else if len(allGroups) != 0 { if bot.TG_user.PosTag == "add" { bot.TG_user.PosTag = "confirm_add_group" } else { @@ -197,32 +225,13 @@ func (bot *Bot) Confirm(query *tgbotapi.CallbackQuery) error { } func (bot *Bot) Cancel(query *tgbotapi.CallbackQuery) error { - shedules, err := bot.DB.Count(&database.ShedulesInUser{ - L9Id: bot.TG_user.L9Id, - }) + bot.TG_user.PosTag = "ready" + err := bot.UpdateUserDB() if err != nil { - log.Fatal(err) - } - if shedules == 0 { - bot.TG_user.PosTag = "add" - err = bot.UpdateUserDB() - if err != nil { - return err - } - bot.DeleteMsg(query) - msg := tgbotapi.NewMessage( - bot.TG_user.TgId, - "Ой, для работы с ботом нужно подключить хотя бы одно расписание группы или преподавателя!\nВведи свой номер группы или фамилию преподавателя", - ) - bot.TG.Send(msg) - } else { - bot.TG_user.PosTag = "ready" - err = bot.UpdateUserDB() - if err != nil { - return err - } - bot.DeleteMsg(query) + return err } + bot.DeleteMsg(query) + return nil }