Skip to content

Commit

Permalink
mail on response
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelemusiani committed Dec 5, 2023
1 parent fd469a5 commit c9f5bce
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 23 deletions.
28 changes: 7 additions & 21 deletions model/callback.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
tgbotapi "github.com/musianisamuele/telegram-bot-api"

"github.com/csunibo/informabot/commands"
"github.com/csunibo/informabot/utils"
)

func (_ MessageData) HandleBotCallback(_bot *tgbotapi.BotAPI, _update *tgbotapi.Update, _callback_text string) {
Expand Down Expand Up @@ -118,32 +117,19 @@ func (data RepresentativesData) HandleBotCallback(bot *tgbotapi.BotAPI, update *
degreeName := strings.TrimPrefix(callback_text, "representatives_")

repData, _ := Representatives[degreeName]
ids := repData.Representatives
mails := repData.Representatives
courseName := repData.Course

var response string
if len(ids) == 0 {
if len(mails) == 0 {
response = fmt.Sprintf(data.FallbackText, courseName)
} else {
// Get chat mebers based on ids
var tmp strings.Builder
noRepresentativeFound := true
for i, participant := range utils.GetChatMembers(bot, chatId, ids) {
if ids[i] == participant.User.ID &&
participant.User.UserName != "???" {
tmp.WriteString("@" + participant.User.UserName + "\n")
noRepresentativeFound = false
}
}
if noRepresentativeFound {
response = fmt.Sprintf(data.Title, courseName) + "\n\n" + "Nessun rappresentante del corso è presente nel gruppo."
// Fallback sulle mail?
// Hardcodiamo gli username?
// Qui srvirebbero sempre tutti i rappresentanti indipendentemente dal
// gruppo o no
} else {
response = fmt.Sprintf(data.Title, courseName) + "\n\n" + tmp.String()
tmp := strings.Builder{}
for _, m := range mails {
tmp.WriteString(m)
tmp.WriteString("\n")
}
response = fmt.Sprintf(data.Title, courseName) + "\n\n" + tmp.String()
}

editConfig := tgbotapi.NewEditMessageText(chatId, messageId, response)
Expand Down
4 changes: 2 additions & 2 deletions model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ type RepresentativesData struct {
}

type Representative struct {
Course string `json:"course"`
Representatives []int64 `json:"representatives"`
Course string `json:"course"`
Representatives []string `json:"representatives"`
}

type InvalidData struct{}

0 comments on commit c9f5bce

Please sign in to comment.