Skip to content

Commit

Permalink
Merge pull request #179 from csunibo/new_degrees
Browse files Browse the repository at this point in the history
New degrees
  • Loading branch information
samuelemusiani committed Jun 7, 2024
2 parents 3bbd7cb + d6a59ea commit 6ef6bb1
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 34 deletions.
34 changes: 23 additions & 11 deletions bot/bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func degreeToTeaching(degree cparser.Degree) cparser.Teaching {
}

func degreeToString(degree cparser.Degree) string {
if len(degree.Years) == 0 {
if len(degree.Teachings) == 0 {
return teachingToString(degreeToTeaching(degree))
}
var b strings.Builder
Expand All @@ -189,17 +189,29 @@ func degreeToString(degree cparser.Degree) string {
b.WriteString(strings.Join(elements, " "))
b.WriteString("</b>\n")
}
// years
for _, y := range degree.Years {
// header
b.WriteString(fmt.Sprintf("%d", y.Year))
if y.Chat != "" {
b.WriteString(fmt.Sprintf(" (<a href='%s'>👥 Gruppo</a>)", y.Chat))

for y := range 5 {
// For not classified teachings
t1 := cparser.GetYearMandatoryTeachingsFromDegree(degree, int64(y))
t2 := cparser.GetYearElectivesTeachingsFromDegree(degree, int64(y))
if y != 0 && (len(t1) > 0 || len(t2) > 0) {
// header
b.WriteString(fmt.Sprintf("%d", y))

var chat string
for _, tmp := range degree.Years {
if tmp.Year == int64(y) {
chat = tmp.Chat
}
}

if chat != "" {
b.WriteString(fmt.Sprintf(" (<a href='%s'>👥 Gruppo</a>)", chat))
}
b.WriteString("\n")
}
b.WriteString("\n")
teachings := y.Teachings
for _, t := range append(teachings.Mandatory, teachings.Electives...) {
b.WriteString(fmt.Sprintf("/%s\n", t))
for _, t := range append(t1, t2...) {
b.WriteString(fmt.Sprintf("/%s\n", t.Name))
}
}
return b.String()
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ module github.com/csunibo/informabot
go 1.22.3

require (
github.com/csunibo/config-parser-go v0.0.2
github.com/csunibo/unibo-go v0.0.10
github.com/mitchellh/mapstructure v1.5.0
github.com/samuelemusiani/telegram-bot-api v0.0.6
golang.org/x/exp v0.0.0-20231127185646-65229373498e
golang.org/x/text v0.15.0
)

require github.com/csunibo/config-parser-go v0.0.3-0.20240605210600-7adafb400cbf // indirect
16 changes: 14 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
github.com/csunibo/config-parser-go v0.0.2 h1:BNujualQX9mZdCzKsEmWlzvTinLqDC0T3dkgdZ/mCTY=
github.com/csunibo/config-parser-go v0.0.2/go.mod h1:guoYwHikybA1kw6MFmCr+HCMZEFxGaO0cr+ACxD0dvY=
github.com/csunibo/config-parser-go v0.0.3-0.20240605194754-e482b63887f6 h1:nT06uGq/GYf5wDgQC8zujOQByNKtc888L5a5e7/AycI=
github.com/csunibo/config-parser-go v0.0.3-0.20240605194754-e482b63887f6/go.mod h1:dwZfvG8VAisAae8r8kZ1wzY4KkRivXpPuco9WQy+PW4=
github.com/csunibo/config-parser-go v0.0.3-0.20240605205505-dbd209cfa33e h1:CH4v6lF3GwEsaAI/EikdsRuArcVDaCJF3GCh/blpp6A=
github.com/csunibo/config-parser-go v0.0.3-0.20240605205505-dbd209cfa33e/go.mod h1:dwZfvG8VAisAae8r8kZ1wzY4KkRivXpPuco9WQy+PW4=
github.com/csunibo/config-parser-go v0.0.3-0.20240605210600-7adafb400cbf h1:KGJHNxAn9ysnmAaD4TcdGNuS1elygT4pvCgdliMfXG4=
github.com/csunibo/config-parser-go v0.0.3-0.20240605210600-7adafb400cbf/go.mod h1:dwZfvG8VAisAae8r8kZ1wzY4KkRivXpPuco9WQy+PW4=
github.com/csunibo/unibo-go v0.0.10 h1:UwFIvTpXMKZCOVoX564RmqQttXTTs5Xz5hCAjun8NFk=
github.com/csunibo/unibo-go v0.0.10/go.mod h1:h2+xnccHa7x48RNB6d07bpHQ01ozw4oihgDOlvVrJ9U=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/samuelemusiani/telegram-bot-api v0.0.6 h1:OH7/qXD4E/wDzd6UcNOJZgw9GWthUKRB33ob1PSWnGI=
github.com/samuelemusiani/telegram-bot-api v0.0.6/go.mod h1:/Sagg9PoVMvfJeQ4Dh4sasKOCRC1xsZJ2Kx9C/BSjW8=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
golang.org/x/exp v0.0.0-20231127185646-65229373498e h1:Gvh4YaCaXNs6dKTlfgismwWZKyjVZXwOPfIyUaqU3No=
golang.org/x/exp v0.0.0-20231127185646-65229373498e/go.mod h1:iRJReGqOEeBhDZGkGbynYwcHlctCvnjTYIamk7uXpHI=
golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk=
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
2 changes: 1 addition & 1 deletion json/config
Submodule config updated 1 files
+496 −193 degrees.json
25 changes: 6 additions & 19 deletions model/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,9 @@ import (
)

const (
jsonPath = "./json/"
groupsFile = "groups.json"
configSubpath = "config/"
degreesFile = "degrees.json"
teachingsFile = "teachings.json"
timetablesFile = "timetables.json"
maintainersFile = "maintainers.json"
representativesFile = "representatives.json"
jsonPath = "./json/"
groupsFile = "groups.json"
configSubpath = "config/"
)

func ParseAutoReplies() (autoReplies []AutoReply, err error) {
Expand Down Expand Up @@ -60,12 +55,6 @@ func commandNameFromDegree(d cparser.Degree) string {
return commandNameFromString(d.Id)
}

func commandNamesFromStrings(strings []string) {
for i, s := range strings {
strings[i] = commandNameFromString(s)
}
}

func ParseTeachings() (teachings map[string]cparser.Teaching, err error) {

teachingsArray, err := cparser.ParseTeachings(filepath.Join(jsonPath, configSubpath))
Expand All @@ -84,11 +73,9 @@ func ParseDegrees() (degrees map[string]cparser.Degree, err error) {
if err != nil {
return nil, fmt.Errorf("error parsing Degrees: %w", err)
}
for _, d := range degreesArray {
for _, y := range d.Years {
t := y.Teachings
commandNamesFromStrings(t.Mandatory)
commandNamesFromStrings(t.Electives)
for i := range degreesArray {
for j := range degreesArray[i].Teachings {
degreesArray[i].Teachings[j].Name = commandNameFromString(degreesArray[i].Teachings[j].Name)
}
}
degrees = make(map[string]cparser.Degree, len(degreesArray))
Expand Down

0 comments on commit 6ef6bb1

Please sign in to comment.