Skip to content

Commit

Permalink
Remove autoselect
Browse files Browse the repository at this point in the history
  • Loading branch information
boozec committed Nov 23, 2023
1 parent fc4e483 commit 3a5d53b
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 47 deletions.
2 changes: 1 addition & 1 deletion bot/callbacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func lecturesCallback(bot *tgbotapi.BotAPI, update *tgbotapi.Update, callback_te
timetableKey := callback_text[len("lectures_"):strings.Index(callback_text, "_y_")]

timetable := model.Timetables[timetableKey]
response, err := commands.GetTimeTable(timetable.Type, timetable.Name, timetable.Curriculum, timetable.Url, year, timeForLectures)
response, err := commands.GetTimeTable(timetable.Type, timetable.Name, timetable.Curriculum, year, timeForLectures)
if err != nil {
log.Printf("Error [GetTimeTable]: %s\n", err)
}
Expand Down
4 changes: 1 addition & 3 deletions commands/uni.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,9 @@ func (t *LezioniTime) UnmarshalJSON(data []byte) error {

// GetTimeTable returns an HTML string containing the timetable for the given
// course on the given date. Returns an empty string if there are no lessons.
func GetTimeTable(courseType, courseName string, curriculum string, url string, year int, day time.Time) (string, error) {
func GetTimeTable(courseType, courseName string, curriculum string, year int, day time.Time) (string, error) {

interval := &timetable.Interval{Start: day, End: day}
// FIXME: after the edit on unibo-go the line below will be valid
// events, err := timetable.FetchTimetable(courseType, courseName, curriculum, url, year, interval)
events, err := timetable.FetchTimetable(courseType, courseName, curriculum, year, interval)
if err != nil {
log.Printf("Error getting timetable: %s\n", err)
Expand Down
5 changes: 2 additions & 3 deletions commands/uni_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ func TestGetTimeTable(t *testing.T) {
year int
day time.Time
curriculum string
url string
}
tests := []struct {
name string
Expand Down Expand Up @@ -147,7 +146,7 @@ func TestGetTimeTable(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := GetTimeTable(tt.args.courseType, tt.args.courseName, tt.args.curriculum, tt.args.url, tt.args.year, tt.args.day)
got, err := GetTimeTable(tt.args.courseType, tt.args.courseName, tt.args.curriculum, tt.args.year, tt.args.day)
if err != nil && !tt.error {
t.Errorf("GetTimeTable() error = %v", err)
return
Expand All @@ -165,7 +164,7 @@ func TestGetTimeTable(t *testing.T) {
func TestWeekend(t *testing.T) {

date := time.Date(2023, 3, 11, 0, 0, 0, 0, time.UTC)
result, err := GetTimeTable("laurea", "informatica", "", "orario-lezioni", 1, date)
result, err := GetTimeTable("laurea", "informatica", "", 1, date)
if err != nil {
t.Fatalf("Error while getting timetable: %s", err)
}
Expand Down
37 changes: 3 additions & 34 deletions model/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,40 +121,9 @@ func (data NotLookingForData) HandleBotCommand(_ *tgbotapi.BotAPI, message *tgbo
}

func (data Lectures) HandleBotCommand(_ *tgbotapi.BotAPI, message *tgbotapi.Message) CommandResponse {
// Check if `chatId` is a valid group for a year. Used to auto-select some info
// for the `/lezioni` command.
var groupYear *Year = nil
for _, degree := range Degrees {
for _, year := range degree.Years {
if year.GroupId == message.Chat.ID {
groupYear = &year
break
}
}
}

if groupYear != nil {
if len(groupYear.Timetables) == 1 {
callback_text := fmt.Sprintf("lectures_%s_y_%d_", groupYear.Timetables[0], groupYear.Year)
rows := ChooseTimetableDay(callback_text)

keyboard := tgbotapi.NewInlineKeyboardMarkup(rows...)
return makeResponseWithInlineKeyboard(keyboard)
} else {
timetables := make(map[string]Timetable, len(groupYear.Timetables))
for _, t := range groupYear.Timetables {
timetables[t] = Timetables[t]

}
rows := GetTimetableCoursesRows(&timetables)
keyboard := tgbotapi.NewInlineKeyboardMarkup(rows...)
return makeResponseWithInlineKeyboard(keyboard)
}
} else {
rows := GetTimetableCoursesRows(&Timetables)
keyboard := tgbotapi.NewInlineKeyboardMarkup(rows...)
return makeResponseWithInlineKeyboard(keyboard)
}
rows := GetTimetableCoursesRows(&Timetables)
keyboard := tgbotapi.NewInlineKeyboardMarkup(rows...)
return makeResponseWithInlineKeyboard(keyboard)
}

func (data ListData) HandleBotCommand(*tgbotapi.BotAPI, *tgbotapi.Message) CommandResponse {
Expand Down
9 changes: 3 additions & 6 deletions model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,9 @@ type YearStudyDiagram struct {
}

type Year struct {
Year int64 `json:"year"`
Chat string `json:"chat"`
Teachings YearStudyDiagram `json:"teachings"`
GroupId int64 `json:"group"`
Timetables []string `json:"timetables"`
Year int64 `json:"year"`
Chat string `json:"chat"`
Teachings YearStudyDiagram `json:"teachings"`
}

type Degree struct {
Expand All @@ -111,7 +109,6 @@ type Timetable struct {
Name string `json:"name"` // Course name
Type string `json:"type"` // Type (laurea|magistrale|2cycle)
Curriculum string `json:"curricula"` // Curriculum
Url string `json:"url"`
}

// SECTION ACTION STRUCTS DATA
Expand Down

0 comments on commit 3a5d53b

Please sign in to comment.