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

Tag mantainer #132

Merged
merged 22 commits into from
Nov 25, 2023
Merged
Show file tree
Hide file tree
Changes from 19 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
10 changes: 10 additions & 0 deletions json/actions.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@
"slashes": false
}
},
"issue": {
"type": "issue",
"data": {
"description": "C'è un problema tecnico/tattico, portalo all'attenzione di un mantainer",
"responses":[
"Mantainer c'è bisogno del vostro aiuto \n",
"Scrivete sul gruppo di @csunibo nel topic Bot"
]
Jabbar03 marked this conversation as resolved.
Show resolved Hide resolved
}
},
"unknown": {
"type": "message",
"data": {
Expand Down
2 changes: 1 addition & 1 deletion json/config
23 changes: 23 additions & 0 deletions model/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,29 @@ func (data HelpData) HandleBotCommand(*tgbotapi.BotAPI, *tgbotapi.Message) Comma
return makeResponseWithText(answer.String())
}

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

answer.WriteString(data.Responses[0])

for _, m := range Mantainers {
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
}
}
if noMantainerFound {
return makeResponseWithText(data.Responses[1])
}
return makeResponseWithText(answer.String())
}

func (data LookingForData) HandleBotCommand(bot *tgbotapi.BotAPI, message *tgbotapi.Message) CommandResponse {
chatTitle := strings.ToLower(message.Chat.Title)

Expand Down
4 changes: 4 additions & 0 deletions model/description.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ func (d HelpData) GetDescription() string {
return d.Description
}

func (d IssueData) GetDescription() string {
return d.Description
}

func (d LookingForData) GetDescription() string {
return d.Description
}
Expand Down
7 changes: 7 additions & 0 deletions model/globals.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ var (
Settings SettingsStruct
Teachings map[string]Teaching
Groups GroupsStruct
Mantainers []Mantainer
)

func InitGlobals() {
Expand Down Expand Up @@ -57,4 +58,10 @@ func InitGlobals() {
if err != nil {
log.Fatalf("Error reading or creating groups.json file: %s", err.Error())
}

Mantainers, err = ParseMantainers()
if err != nil {
log.Fatalf("Error reading mantainers.json file: %s", err.Error())
Jabbar03 marked this conversation as resolved.
Show resolved Hide resolved
}

}
12 changes: 12 additions & 0 deletions model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ func GetActionFromType(name string, commandType string) Action {
data = MessageData{}
case "help":
data = HelpData{}
case "issue":
data = IssueData{}
case "lookingFor":
data = LookingForData{}
case "notLookingFor":
Expand Down Expand Up @@ -69,6 +71,11 @@ type Action struct {
Data DataInterface `json:"data"`
}

type Mantainer struct {
Id int `json:"id"`
Username string `json:"username"`
}

// config/teachings.json

type Teaching struct {
Expand Down Expand Up @@ -111,6 +118,11 @@ type HelpData struct {
Slashes bool `json:"slashes"`
}

type IssueData struct {
Description string `json:"description"`
Responses []string `json:"responses"`
}

type LookingForData struct {
Description string `json:"description"`
SingularText string `json:"singularText"`
Expand Down
27 changes: 27 additions & 0 deletions model/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,30 @@ func ParseOrCreateGroups() (GroupsStruct, error) {
}

func SaveGroups(groups GroupsStruct) error { return utils.WriteJSONFile(groupsFile, groups) }

func ParseMantainers() (mantainer []Mantainer, err error) {
file, err := os.ReadFile("./json/config/mantainers.json")
if errors.Is(err, os.ErrNotExist) {
return mantainer, fmt.Errorf("mantainers.json does not exist")
} else if err != nil {
return nil, fmt.Errorf("error reading mantainers.json file: %w", err)
}

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

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

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

return nil, fmt.Errorf("couldn't found informabot projects after parsing mantainers.json")
}
Loading