Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix typo #172

Merged
merged 5 commits into from
May 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions json/actions.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
"issue": {
"type": "issue",
"data": {
"description": "C'è un problema tecnico/tattico, portalo all'attenzione di un mantainer",
"response": "Mantainers, c'è bisogno del vostro aiuto \n",
"fallback": "Nessun mantainer è presente in questo gruppo. Riportate il problema direttamente sul gruppo di @csunibo nel topic Bot"
"description": "C'è un problema tecnico/tattico, portalo all'attenzione di un maintainer",
"response": "Maintainers, c'è bisogno del vostro aiuto \n",
"fallback": "Nessun maintainer è presente in questo gruppo. Riportate il problema direttamente sul gruppo di @csunibo nel topic Bot"
}
},
"unknown": {
Expand Down
2 changes: 1 addition & 1 deletion json/config
8 changes: 4 additions & 4 deletions model/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,23 @@ func (data HelpData) HandleBotCommand(*tgbotapi.BotAPI, *tgbotapi.Message) Comma
}

func (data IssueData) HandleBotCommand(bot *tgbotapi.BotAPI, message *tgbotapi.Message) CommandResponse {
noMantainerFound := true
noMaintainerFound := true
var answer strings.Builder
var Ids []int64

answer.WriteString(data.Response)

for _, m := range Mantainers {
for _, m := range Maintainers {
Ids = append(Ids, int64(m.Id))
}

for i, participant := range utils.GetChatMembers(bot, message.Chat.ID, Ids) {
if Ids[i] == participant.User.ID && participant.User.UserName != "???" {
answer.WriteString("@" + participant.User.UserName + " ")
noMantainerFound = false
noMaintainerFound = false
}
}
if noMantainerFound {
if noMaintainerFound {
return makeResponseWithText(data.Fallback)
}
return makeResponseWithText(answer.String())
Expand Down
6 changes: 3 additions & 3 deletions model/globals.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var (
Teachings map[string]Teaching
Groups GroupsStruct
Timetables map[string]Timetable
Mantainers []Mantainer
Maintainers []Maintainer
Representatives map[string]Representative
)

Expand Down Expand Up @@ -66,9 +66,9 @@ func InitGlobals() {
log.Fatalf(err.Error())
}

Mantainers, err = ParseMantainers()
Maintainers, err = ParseMaintainers()
if err != nil {
log.Fatalf("Error parsing mantainers.json file: %s", err.Error())
log.Fatalf("Error parsing maintainers.json file: %s", err.Error())
}

Representatives, err = ParseRepresentatives()
Expand Down
2 changes: 1 addition & 1 deletion model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ type Action struct {
Data DataInterface `json:"data"`
}

type Mantainer struct {
type Maintainer struct {
Id int64 `json:"id"`
Username string `json:"username"`
}
Expand Down
20 changes: 10 additions & 10 deletions model/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const (
degreesFile = "degrees.json"
teachingsFile = "teachings.json"
timetablesFile = "timetables.json"
mantainersFile = "mantainers.json"
maintainersFile = "maintainers.json"
representativesFile = "representatives.json"
)

Expand Down Expand Up @@ -232,32 +232,32 @@ func ParseTimetables() (timetables map[string]Timetable, err error) {
return
}

func ParseMantainers() (mantainer []Mantainer, err error) {
filepath := filepath.Join(jsonPath, configSubpath, mantainersFile)
func ParseMaintainers() (maintainer []Maintainer, err error) {
filepath := filepath.Join(jsonPath, configSubpath, maintainersFile)
file, err := os.ReadFile(filepath)
if errors.Is(err, os.ErrNotExist) {
return mantainer, fmt.Errorf("%s does not exist", mantainersFile)
return maintainer, fmt.Errorf("%s does not exist", maintainersFile)
} else if err != nil {
return nil, fmt.Errorf("error reading %s file: %w", mantainersFile, err)
return nil, fmt.Errorf("error reading %s file: %w", maintainersFile, err)
}

var projects []struct {
Name string `json:"project"`
Mantainers []Mantainer `json:"mantainers"`
Name string `json:"project"`
Maintainers []Maintainer `json:"maintainers"`
}

err = json.Unmarshal(file, &projects)
if err != nil {
return nil, fmt.Errorf("error parsing %s file: %w", mantainersFile, err)
return nil, fmt.Errorf("error parsing %s file: %w", maintainersFile, err)
}

for _, p := range projects {
if p.Name == "informabot" {
return p.Mantainers, nil
return p.Maintainers, nil
}
}

return nil, fmt.Errorf("couldn't found informabot projects after parsing %s", mantainersFile)
return nil, fmt.Errorf("couldn't found informabot projects after parsing %s", maintainersFile)
}

func ParseRepresentatives() (map[string]Representative, error) {
Expand Down
Loading