Skip to content

Commit

Permalink
common/templates: add silent key to complexMessage (botlabs-gg#1456)
Browse files Browse the repository at this point in the history
* lib/discordgo: add SUPPRESS_NOTIFICATIONS flag

Add the recently introduced `SUPPRESS_NOTIFICATIONS` message flag to
the set of `discordgo.MessageFlags`.

Also add a `Flags` field to both `MessageEdit` and `MessageSend` struct,
so that we can introduce a new key for `complexMessage` to suppress
notifications.

Signed-off-by: Luca Zeuch <l-zeuch@email.de>

* common/templates: add silent key to complexMessage

Follow-up to ea8711a ("lib/discordgo: add SUPPRESS_NOTIFICATIONS flag")

Add a "silent" key to complexMessage to suppress notifications.

Just recently a user on the support server asked whether it is possible
(with yagpdb) to use the new `@silent` feature -- standing now, that is
not the case.

So, I've gone ahead and implemented exactly that sort of feature. I'm
not expecting to have this released until the next scheduled release;
we've went quite some time without it, chances are that users can still
wait until the next release.

A minimal working example, silently pinging the triggering user:
```go
{{ sendMessage nil (complexMessage "content" .User.Mention "silent" true) }}
```

Signed-off-by: Luca Zeuch <l-zeuch@email.de>

---------

Signed-off-by: Luca Zeuch <l-zeuch@email.de>
  • Loading branch information
l-zeuch authored Mar 7, 2023
1 parent cecc18a commit 608b704
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
10 changes: 10 additions & 0 deletions common/templates/general.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,11 @@ func CreateMessageSend(values ...interface{}) (*discordgo.MessageSend, error) {
msg.Reference = &discordgo.MessageReference{
MessageID: msgID,
}
case "silent":
if val == nil || val == false {
continue
}
msg.Flags |= discordgo.MessageFlagsSuppressNotifications
default:
return nil, errors.New(`invalid key "` + key + `" passed to send message builder`)
}
Expand Down Expand Up @@ -319,6 +324,11 @@ func CreateMessageEdit(values ...interface{}) (*discordgo.MessageEdit, error) {
}
msg.Embeds = []*discordgo.MessageEmbed{embed}
}
case "silent":
if val == nil || val == false {
continue
}
msg.Flags |= discordgo.MessageFlagsSuppressNotifications
default:
return nil, errors.New(`invalid key "` + key + `" passed to message edit builder`)
}
Expand Down
3 changes: 3 additions & 0 deletions lib/discordgo/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ const (
MessageFlagsLoading MessageFlags = 1 << 7
// MessageFlagsFailedToMentionSomeRolesInThread this message failed to mention some roles and add their members to the thread.
MessageFlagsFailedToMentionSomeRolesInThread MessageFlags = 1 << 8
// MessageFlagsSuppressNotifications this message will not trigger push and desktop notifications
MessageFlagsSuppressNotifications MessageFlags = 1 << 12
)

// File stores info about files you e.g. send in messages.
Expand All @@ -211,6 +213,7 @@ type MessageSend struct {
Files []*File `json:"-"`
AllowedMentions AllowedMentions `json:"allowed_mentions,omitempty"`
Reference *MessageReference `json:"message_reference,omitempty"`
Flags MessageFlags `json:"flags,omitempty"`

// TODO: Remove this when compatibility is not required.
File *File `json:"-"`
Expand Down

0 comments on commit 608b704

Please sign in to comment.