Add auto_publish functionality for liveposting module

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2021-08-07 16:28:22 +02:00
parent 5bd54dd15c
commit d8abfbac35
Signed by: luzifer
GPG key ID: 0066F03ED215AD7D
2 changed files with 16 additions and 3 deletions

View file

@ -226,7 +226,9 @@ func (m modLivePosting) sendLivePost(username, displayName, title, game, preview
)
// @attr discord_channel_id required string "" ID of the Discord channel to post the message to
msgs, err := m.discord.ChannelMessages(m.attrs.MustString("discord_channel_id", nil), livePostingNumberOfMessagesToLoad, "", "", "")
channelID := m.attrs.MustString("discord_channel_id", nil)
msgs, err := m.discord.ChannelMessages(channelID, livePostingNumberOfMessagesToLoad, "", "", "")
if err != nil {
return errors.Wrap(err, "fetching previous messages")
}
@ -282,10 +284,20 @@ func (m modLivePosting) sendLivePost(username, displayName, title, game, preview
URL: strings.Join([]string{"https://www.twitch.tv", username}, "/"),
}
_, err = m.discord.ChannelMessageSendComplex(m.attrs.MustString("discord_channel_id", nil), &discordgo.MessageSend{
msg, err := m.discord.ChannelMessageSendComplex(channelID, &discordgo.MessageSend{
Content: postText,
Embed: msgEmbed,
})
if err != nil {
return errors.Wrap(err, "sending message")
}
return errors.Wrap(err, "sending message")
// @attr auto_publish optional bool "false" Automatically publish (crosspost) the message to followers of the channel
if m.attrs.MustBool("auto_publish", ptrBoolFalse) {
if _, err = m.discord.ChannelMessageCrosspost(channelID, msg.ID); err != nil {
return errors.Wrap(err, "publishing message")
}
}
return nil
}

View file

@ -75,6 +75,7 @@ Announces stream live status based on Discord streaming status
| `post_text` | ✅ | string | | Message to post to channel use `${displayname}` and `${username}` as placeholders |
| `twitch_client_id` | ✅ | string | | Twitch client ID the token was issued for |
| `twitch_client_secret` | ✅ | string | | Secret for the Twitch app identified with twitch_client_id |
| `auto_publish` | | bool | `false` | Automatically publish (crosspost) the message to followers of the channel |
| `cron` | | string | `*/5 * * * *` | Fetch live status of `poll_usernames` (set to empty string to disable): keep this below `stream_freshness` or you might miss streams |
| `disable_presence` | | bool | `false` | Disable posting live-postings for discord presence changes |
| `poll_usernames` | | []string | `[]` | Check these usernames for active streams when executing the `cron` (at most 100 users can be checked) |