Исправлено: перепутанное время в расписании
Исправлено: диалоги
This commit is contained in:
parent
cf518e4aa7
commit
718ff7642d
|
@ -34,7 +34,7 @@ func (bot *Bot) InitUser(id int64, name string) (*database.TgUser, error) {
|
||||||
L9Id: l9id,
|
L9Id: l9id,
|
||||||
Name: name,
|
Name: name,
|
||||||
TgId: id,
|
TgId: id,
|
||||||
PosTag: "ready",
|
PosTag: "not_started",
|
||||||
}
|
}
|
||||||
_, err = db.Insert(user, tg_user)
|
_, err = db.Insert(user, tg_user)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -48,14 +48,14 @@ func (bot *Bot) InitUser(id int64, name string) (*database.TgUser, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bot *Bot) Start() error {
|
func (bot *Bot) Start() error {
|
||||||
/*bot.TG_user.PosTag = "add"
|
bot.TG_user.PosTag = "ready"
|
||||||
_, err := bot.DB.Update(bot.TG_user)
|
_, err := bot.DB.Update(bot.TG_user)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}*/
|
}
|
||||||
msg := tgbotapi.NewMessage(bot.TG_user.TgId, "Привет! Введи свой <b>номер группы</b> или <b>фамилию преподавателя</b>")
|
msg := tgbotapi.NewMessage(bot.TG_user.TgId, "Привет! У меня можно посмотреть расписание занятий\nПросто введи <b>номер группы</b> или <b>фамилию преподавателя</b>")
|
||||||
msg.ParseMode = tgbotapi.ModeHTML
|
msg.ParseMode = tgbotapi.ModeHTML
|
||||||
_, err := bot.TG.Send(msg)
|
_, err = bot.TG.Send(msg)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,9 +41,9 @@ func (bot *Bot) GetSummary(shedules []database.ShedulesInUser, isPersonal bool,
|
||||||
firstPair = pairs[0]
|
firstPair = pairs[0]
|
||||||
log.Println(firstPair, secondPair)
|
log.Println(firstPair, secondPair)
|
||||||
|
|
||||||
var str string
|
str := "📝Краткая сводка:\n\n"
|
||||||
if pairs[0][0].Begin.Day() != time.Now().Day() {
|
if pairs[0][0].Begin.Day() != time.Now().Day() {
|
||||||
str = "❗️Сегодня пар нет\nБлижайшие занятия "
|
str += "❗️Сегодня пар нет\nБлижайшие занятия "
|
||||||
if time.Until(firstPair[0].Begin).Hours() < 48 {
|
if time.Until(firstPair[0].Begin).Hours() < 48 {
|
||||||
str += "завтра\n"
|
str += "завтра\n"
|
||||||
} else {
|
} else {
|
||||||
|
@ -56,9 +56,9 @@ func (bot *Bot) GetSummary(shedules []database.ShedulesInUser, isPersonal bool,
|
||||||
str += day
|
str += day
|
||||||
} else {
|
} else {
|
||||||
if firstPair[0].Begin.Before(now) {
|
if firstPair[0].Begin.Before(now) {
|
||||||
str = "Сейчас:\n\n"
|
str += "Сейчас:\n\n"
|
||||||
} else {
|
} else {
|
||||||
str = "Ближайшая пара сегодня:\n\n"
|
str += "Ближайшая пара сегодня:\n\n"
|
||||||
}
|
}
|
||||||
firstStr, err := PairToStr(firstPair, bot.DB)
|
firstStr, err := PairToStr(firstPair, bot.DB)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -120,6 +120,15 @@ func (bot *Bot) GetPersonalDaySummary(dt int, msg ...tgbotapi.Message) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var ruWeekdays = []string{
|
||||||
|
"понедельник",
|
||||||
|
"вторник",
|
||||||
|
"среду",
|
||||||
|
"четверг",
|
||||||
|
"пятницу",
|
||||||
|
"субботу",
|
||||||
|
}
|
||||||
|
|
||||||
func (bot *Bot) GetDaySummary(shedules []database.ShedulesInUser, dt int, isPersonal bool, editMsg ...tgbotapi.Message) error {
|
func (bot *Bot) GetDaySummary(shedules []database.ShedulesInUser, dt int, isPersonal bool, editMsg ...tgbotapi.Message) error {
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
day := time.Date(now.Year(), now.Month(), now.Day()+dt, 0, 0, 0, 0, now.Location())
|
day := time.Date(now.Year(), now.Month(), now.Day()+dt, 0, 0, 0, 0, now.Location())
|
||||||
|
@ -131,7 +140,11 @@ func (bot *Bot) GetDaySummary(shedules []database.ShedulesInUser, dt int, isPers
|
||||||
pairs := GroupPairs(lessons)
|
pairs := GroupPairs(lessons)
|
||||||
var str string
|
var str string
|
||||||
|
|
||||||
str = fmt.Sprintf("Расписание на %s\n\n", pairs[0][0].Begin.Format("02.01"))
|
str = fmt.Sprintf(
|
||||||
|
"Расписание на %s, %s\n\n",
|
||||||
|
ruWeekdays[int(pairs[0][0].Begin.Weekday())-1],
|
||||||
|
pairs[0][0].Begin.Format("02.01"),
|
||||||
|
)
|
||||||
day, err := bot.GetDayShedule(pairs)
|
day, err := bot.GetDayShedule(pairs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -53,7 +53,7 @@ func GenerateKeyboard(array []tgbotapi.InlineKeyboardButton, query string) tgbot
|
||||||
}
|
}
|
||||||
|
|
||||||
func SummaryKeyboard(clickedButton string, sheduleId int64, isTeacher bool, dt int) tgbotapi.InlineKeyboardMarkup {
|
func SummaryKeyboard(clickedButton string, sheduleId int64, isTeacher bool, dt int) tgbotapi.InlineKeyboardMarkup {
|
||||||
tail := GenerateButtonTail(sheduleId, dt, isTeacher)
|
tail := GenerateButtonTail(sheduleId, 0, isTeacher)
|
||||||
|
|
||||||
near := []tgbotapi.InlineKeyboardButton{
|
near := []tgbotapi.InlineKeyboardButton{
|
||||||
tgbotapi.NewInlineKeyboardButtonData("Краткая сводка", "near"+tail),
|
tgbotapi.NewInlineKeyboardButtonData("Краткая сводка", "near"+tail),
|
||||||
|
@ -72,6 +72,7 @@ func SummaryKeyboard(clickedButton string, sheduleId int64, isTeacher bool, dt i
|
||||||
next_arrow := GenerateButtonTail(sheduleId, dt+1, isTeacher)
|
next_arrow := GenerateButtonTail(sheduleId, dt+1, isTeacher)
|
||||||
arrows = []tgbotapi.InlineKeyboardButton{
|
arrows = []tgbotapi.InlineKeyboardButton{
|
||||||
tgbotapi.NewInlineKeyboardButtonData("⏮", clickedButton+prev_arrow),
|
tgbotapi.NewInlineKeyboardButtonData("⏮", clickedButton+prev_arrow),
|
||||||
|
tgbotapi.NewInlineKeyboardButtonData("🔄", clickedButton+update),
|
||||||
tgbotapi.NewInlineKeyboardButtonData("⏭", clickedButton+next_arrow),
|
tgbotapi.NewInlineKeyboardButtonData("⏭", clickedButton+next_arrow),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"math"
|
"math"
|
||||||
"os"
|
"os"
|
||||||
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -82,16 +83,26 @@ func (bot *Bot) GetWeekSummary(shedules []database.ShedulesInUser, dw int, isPer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var times []ssau_parser.Lesson
|
var times []ssau_parser.Lesson
|
||||||
|
var beginsSlice []time.Time
|
||||||
|
var endsSlice []time.Time
|
||||||
for b := range begins {
|
for b := range begins {
|
||||||
l := ssau_parser.Lesson{
|
beginsSlice = append(beginsSlice, b)
|
||||||
Begin: b,
|
|
||||||
}
|
|
||||||
times = append(times, l)
|
|
||||||
}
|
}
|
||||||
i := 0
|
|
||||||
for e := range ends {
|
for e := range ends {
|
||||||
times[i].End = e
|
endsSlice = append(endsSlice, e)
|
||||||
i++
|
}
|
||||||
|
sort.Slice(beginsSlice, func(i, j int) bool {
|
||||||
|
return beginsSlice[i].Before(beginsSlice[j])
|
||||||
|
})
|
||||||
|
sort.Slice(endsSlice, func(i, j int) bool {
|
||||||
|
return endsSlice[i].Before(endsSlice[j])
|
||||||
|
})
|
||||||
|
for i, b := range beginsSlice {
|
||||||
|
sh := ssau_parser.Lesson{
|
||||||
|
Begin: b,
|
||||||
|
End: endsSlice[i],
|
||||||
|
}
|
||||||
|
times = append(times, sh)
|
||||||
}
|
}
|
||||||
|
|
||||||
weekBegin := timex.WeekStart(lessons[0].Begin.Year(), week)
|
weekBegin := timex.WeekStart(lessons[0].Begin.Year(), week)
|
||||||
|
@ -108,7 +119,15 @@ func (bot *Bot) GetWeekSummary(shedules []database.ShedulesInUser, dw int, isPer
|
||||||
}
|
}
|
||||||
|
|
||||||
html := bot.CreateHTMLShedule(week, shedule, dates, times)
|
html := bot.CreateHTMLShedule(week, shedule, dates, times)
|
||||||
fname := fmt.Sprintf("./%d_%d.html", bot.TG_user.L9Id, week-bot.Week)
|
|
||||||
|
if _, err := os.Stat("shedules"); os.IsNotExist(err) {
|
||||||
|
err = os.Mkdir("shedules", os.ModePerm)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fname := fmt.Sprintf("./shedules/%d_%d.html", bot.TG_user.L9Id, week-bot.Week)
|
||||||
f, _ := os.Create(fname)
|
f, _ := os.Create(fname)
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
f.WriteString(html)
|
f.WriteString(html)
|
||||||
|
@ -132,7 +151,7 @@ func (bot *Bot) GetWeekSummary(shedules []database.ShedulesInUser, dw int, isPer
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
fname = fmt.Sprintf("./%d_%d.pdf", bot.TG_user.L9Id, week-bot.Week)
|
fname = fmt.Sprintf("./shedules/%d_%d.pdf", bot.TG_user.L9Id, week-bot.Week)
|
||||||
err = pdfg.WriteFile(fname)
|
err = pdfg.WriteFile(fname)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -165,7 +184,15 @@ func (bot *Bot) GetWeekSummary(shedules []database.ShedulesInUser, dw int, isPer
|
||||||
shedules[0].IsTeacher,
|
shedules[0].IsTeacher,
|
||||||
dw,
|
dw,
|
||||||
)
|
)
|
||||||
str := fmt.Sprintf("Расписание на %d неделю сообщением ниже 👇", week-bot.Week)
|
_, nowWeek := time.Now().ISOWeek()
|
||||||
|
var str string
|
||||||
|
if week == nowWeek {
|
||||||
|
str = fmt.Sprintf("Расписание на текущую (%d) неделю сообщением ниже 👇", week-bot.Week)
|
||||||
|
} else if week-nowWeek == 1 {
|
||||||
|
str = fmt.Sprintf("Расписание на следующую (%d) неделю сообщением ниже 👇", week-bot.Week)
|
||||||
|
} else {
|
||||||
|
str = fmt.Sprintf("Расписание на %d неделю сообщением ниже 👇", week-bot.Week)
|
||||||
|
}
|
||||||
bot.EditOrSend(str, markup, editMsg...)
|
bot.EditOrSend(str, markup, editMsg...)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -179,7 +206,7 @@ const head = `<html lang="ru">
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
.note div,.rasp div{background-color:#f0f8ff;padding:10px;text-align:center;border-radius:10px}.note,th.head,th.time{font-family:monospace}.subj div #text,.subj p{display:none}html{font-size:1.3rem}body{background:#dc14bd}table{table-layout:fixed;width:100%;border-spacing:5px 5px}.note div{margin:10px 0}.head p,.subj p,hr{margin:0}.rasp div{transition:.3s}th.head{background-color:#0ff;border-radius:10px;padding:5px;font-size:1.05rem}th.subj,th.time{background-color:#f0f8ff;padding:10px;border-radius:10px}th.time{font-size:1.1rem}.subj h2,.subj p{font-size:.85rem}th.subj:not(.lab,.lect,.pract,.other){background-color:#a9a9a9}.subj div{border-radius:10px;padding:5px}.subj p{font-family:monospace;color:#f0f8ff}.subj h2,.subj h3,.subj h5{font-family:monospace;text-align:left;margin:5px}.subj h3{font-size:.65rem}.subj h5{font-size:.7rem;font-weight:400}.lect div{background-color:#7fff00}.pract div{background-color:#dc143c}.lab div{background-color:#8a2be2}.other div{background-color:#ff8c00}
|
.note div,.rasp div{background-color:#f0f8ff;padding:10px;text-align:center;border-radius:10px}.note,th.head,th.time{font-family:monospace}.subj div #text,.subj p{display:none}html{font-size:1.5rem}body{background:#dc14bd}table{table-layout:fixed;width:100%;border-spacing:5px 5px}.note div{margin:10px 0}.head p,.subj p,hr{margin:0}.rasp div{transition:.3s}th.head{background-color:#0ff;border-radius:10px;padding:5px;font-size:1.05rem}th.subj,th.time{background-color:#f0f8ff;padding:10px;border-radius:10px}th.time{font-size:1.1rem}.subj h2,.subj p{font-size:.85rem}th.subj:not(.lab,.lect,.pract,.other){background-color:#a9a9a9}.subj div{border-radius:10px;padding:5px}.subj p{font-family:monospace;color:#f0f8ff}.subj h2,.subj h3,.subj h5{font-family:monospace;text-align:left;margin:5px}.subj h3{font-size:.65rem}.subj h5{font-size:.7rem;font-weight:400}.lect div{background-color:#7fff00}.pract div{background-color:#dc143c}.lab div{background-color:#8a2be2}.other div{background-color:#ff8c00}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
|
Reference in New Issue