From d8abfbac3534100d46e9eb929df2a58ea3879b2d Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Sat, 7 Aug 2021 16:28:22 +0200 Subject: [PATCH] Add auto_publish functionality for liveposting module Signed-off-by: Knut Ahlers --- mod_livePosting.go | 18 +++++++++++++++--- wiki/Home.md | 1 + 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/mod_livePosting.go b/mod_livePosting.go index 9c41c18..02a5236 100644 --- a/mod_livePosting.go +++ b/mod_livePosting.go @@ -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 } diff --git a/wiki/Home.md b/wiki/Home.md index b5ad300..be62ac5 100644 --- a/wiki/Home.md +++ b/wiki/Home.md @@ -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) |