Skip to content

Commit

Permalink
+ supress
Browse files Browse the repository at this point in the history
  • Loading branch information
keshon committed May 27, 2021
1 parent a60e6f3 commit bc63753
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
7 changes: 4 additions & 3 deletions src/controllers/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ type Config struct {
ChatIDByRoles []string
}
Messaging struct {
PollDuration int
CommentTruncateAt int
SilentUpdate bool
PollDuration int
CommentTruncateAt int
SilentUpdate bool
SuppressUndefinedRoles bool
}
}

Expand Down
24 changes: 13 additions & 11 deletions src/controllers/munro/munro.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,15 +186,8 @@ func ParseTaskStatuses(bot *tgbotapi.BotAPI, conf config.Config, t time.Time, db

// Decision making
result := storage.FindRecord(db, task.ID)
if len(result.TaskID) <= 0 {
// create
storage.CreateRecord(db, task.ID, currentTaskStatus.ShortName, task.LastCommentDate)
// say
if conf.Messaging.SilentUpdate != true {
sendMessage(bot, conf, messageTemplate, currentTaskStatus.ShortName)
}
} else {
// TODO or date mismatch
if len(result.TaskID) > 0 {
// check if status is different or last comment date don't match
if result.TaskStatus != currentTaskStatus.ShortName || result.TaskLastUpdate != task.LastCommentDate {
// update
storage.UpdateRecord(db, task.ID, currentTaskStatus.ShortName, task.LastCommentDate)
Expand All @@ -203,6 +196,14 @@ func ParseTaskStatuses(bot *tgbotapi.BotAPI, conf config.Config, t time.Time, db
sendMessage(bot, conf, messageTemplate, currentTaskStatus.ShortName)
}
}

} else {
// create
storage.CreateRecord(db, task.ID, currentTaskStatus.ShortName, task.LastCommentDate)
// say
if conf.Messaging.SilentUpdate != true {
sendMessage(bot, conf, messageTemplate, currentTaskStatus.ShortName)
}
}
}
}
Expand All @@ -228,8 +229,9 @@ func sendMessage(bot *tgbotapi.BotAPI, conf config.Config, message, taskStatus s
messageSent = true
}
}
// Send message to Admin if no role matching was done successfuly
if messageSent == false {

// Send message to Admin if no role matching was done successfuly and supress is disabled
if messageSent == false && conf.Messaging.SuppressUndefinedRoles != true {
chatID, _ := strconv.ParseInt(conf.Credentials.AdminChatID, 10, 64)
message = i18n.Tr(conf.Bot.Language, "unknown-status") + "\n" + message
msg := tgbotapi.NewMessage(chatID, message)
Expand Down

0 comments on commit bc63753

Please sign in to comment.