Skip to content

Commit

Permalink
feat(commands): hide passes in /marks
Browse files Browse the repository at this point in the history
  • Loading branch information
oddyamill committed Nov 30, 2024
1 parent be0493f commit 62681be
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 18 deletions.
4 changes: 4 additions & 0 deletions internal/client/structures.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ type Mark struct {
UpdatedAt time.Time `json:"updated_at"`
}

func (m Mark) IsPass() bool {
return m.Mark == "Б" || m.Mark == "Н" || m.Mark == "У"
}

type RawSchedule struct {
Schedule []Event `json:"schedule"`
Homeworks []Homework `json:"homeworks"`
Expand Down
47 changes: 29 additions & 18 deletions internal/commands/marks.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"time"
)

func marksCommand(context Context, responder Responder, formatter helpers.Formatter, periodID int) error {
func marksCommand(context Context, responder Responder, formatter helpers.Formatter, periodID int, hidePasses bool) error {
periods, err := context.GetClient().GetStudyPeriods()

if err != nil {
Expand All @@ -29,6 +29,11 @@ func marksCommand(context Context, responder Responder, formatter helpers.Format
}
}

row = append(row, KeyboardButton{
Text: helpers.If(hidePasses, "Показать", "Скрыть") + " пропуски",
Callback: "marks:" + strconv.Itoa(periodID) + ":" + helpers.If(hidePasses, "show", "hide"),
})

keyboard := Keyboard{row}

if period == nil {
Expand All @@ -44,29 +49,29 @@ func marksCommand(context Context, responder Responder, formatter helpers.Format
responder.Write(formatter.Title("Оценки за " + period.Text))

for _, lesson := range *marks {
line := lesson.String()
line := ""

if len(lesson.Marks) > 0 {
marksLine := ""
for i, mark := range lesson.Marks {
if hidePasses && mark.IsPass() {
continue
}

for i, mark := range lesson.Marks {
if i > 0 {
marksLine += ", "
}
if i > 0 && line != "" {
line += ", "
}

marksLine += mark.Mark
line += mark.Mark

if mark.UpdatedAt.After(context.User.LastMarksUpdate) {
marksLine += "⁺"
}
if mark.UpdatedAt.After(context.User.LastMarksUpdate) {
line += "⁺"
}
}

line += ": " + formatter.Code(marksLine)
} else {
line += ": " + formatter.Code("-")
if line == "" {
line = "-"
}

responder.Write(formatter.Item(line))
responder.Write(formatter.Item(lesson.String() + ": " + formatter.Code(line)))
}

context.User.UpdateLastMarksUpdate()
Expand All @@ -75,10 +80,16 @@ func marksCommand(context Context, responder Responder, formatter helpers.Format
}

var MarksCommand = Command(func(context Context, responder Responder, formatter helpers.Formatter) error {
return marksCommand(context, responder, formatter, 0)
return marksCommand(context, responder, formatter, 0, true)
})

var MarksCallback = Callback(func(context Context, responder Responder, formatter helpers.Formatter, data []string) error {
id, _ := strconv.Atoi(data[1])
return marksCommand(context, responder, formatter, id)

if len(data) < 3 {
// todo better compatibility with the old versions
return marksCommand(context, responder, formatter, id, true)
}

return marksCommand(context, responder, formatter, id, data[2] == "hide")
})

0 comments on commit 62681be

Please sign in to comment.