Add support for message content for reaction role posts

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2021-08-08 13:57:28 +02:00
parent 473808dfa0
commit 0345d3c90f
Signed by: luzifer
GPG key ID: 0066F03ED215AD7D
2 changed files with 16 additions and 3 deletions

View file

@ -55,6 +55,9 @@ func (m modReactionRole) Setup() error {
// @attr discord_channel_id required string "" ID of the Discord channel to post the message to
channelID := m.attrs.MustString("discord_channel_id", nil)
// @attr content optional string "" Message content to post above the embed
contentString := m.attrs.MustString("content", ptrStringEmpty)
msgEmbed := &discordgo.MessageEmbed{
// @attr embed_color optional int64 "0x2ECC71" Integer / HEX representation of the color for the embed
Color: int(m.attrs.MustInt64("embed_color", ptrInt64(streamScheduleDefaultColor))),
@ -100,9 +103,18 @@ func (m modReactionRole) Setup() error {
}
if managedMsg == nil {
managedMsg, err = m.discord.ChannelMessageSendEmbed(channelID, msgEmbed)
} else if !isDiscordMessageEmbedEqual(managedMsg.Embeds[0], msgEmbed) {
_, err = m.discord.ChannelMessageEditEmbed(channelID, managedMsg.ID, msgEmbed)
managedMsg, err = m.discord.ChannelMessageSendComplex(channelID, &discordgo.MessageSend{
Content: contentString,
Embed: msgEmbed,
})
} else if !isDiscordMessageEmbedEqual(managedMsg.Embeds[0], msgEmbed) || managedMsg.Content != contentString {
_, err = m.discord.ChannelMessageEditComplex(&discordgo.MessageEdit{
Content: &contentString,
Embed: msgEmbed,
ID: managedMsg.ID,
Channel: channelID,
})
}
if err != nil {
return errors.Wrap(err, "updating / creating message")

View file

@ -117,6 +117,7 @@ Creates a post with pre-set reactions and assigns roles on reaction
| `discord_channel_id` | ✅ | string | | ID of the Discord channel to post the message to |
| `embed_title` | ✅ | string | | Title of the embed |
| `reaction_roles` | ✅ | []string | | List of strings in format `emote=role-id[:set]`. `emote` equals an unicode emote (✅) or a custom emote in form `:<emote-name>:<emote-id>`. `role-id` is the integer ID of the guilds role to add with this emote. If `:set` is added at the end, the role will only be added but not removed when the reaction is removed. |
| `content` | | string | | Message content to post above the embed |
| `embed_color` | | int64 | `0x2ECC71` | Integer / HEX representation of the color for the embed |
| `embed_description` | | string | | Description for the embed block |
| `embed_thumbnail_height` | | int64 | | Height of the thumbnail |