From 8d0264c133710e693d6acb01b852e20cc4d18e16 Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Tue, 16 Nov 2021 00:06:15 +0100 Subject: [PATCH] [liveposting] Add option to remove older messages for the same channel Signed-off-by: Knut Ahlers --- mod_livePosting.go | 20 +++++++++++++++++++- wiki/Home.md | 1 + 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/mod_livePosting.go b/mod_livePosting.go index 1bd675c..4de4b90 100644 --- a/mod_livePosting.go +++ b/mod_livePosting.go @@ -252,10 +252,28 @@ func (m *modLivePosting) sendLivePost(username, displayName, title, game, previe if err != nil { return errors.Wrap(err, "parsing message timestamp") } - if msg.Content == postText && time.Since(mt) < ignoreTime { + + if msg.Content != postText { + // Post is for another channel / is another message + continue + } + + if time.Since(mt) < ignoreTime { + // Message is still fresh logger.Debug("Not creating live-post, it's already there") return nil } + + // @attr remove_old optional bool "false" If set to `true` older message with same content will be deleted + if !m.attrs.MustBool("remove_old", ptrBoolFalse) { + // We're not allowed to purge the old message + continue + } + + // Purge the old message + if err = m.discord.ChannelMessageDelete(channelID, msg.ID); err != nil { + return errors.Wrap(err, "deleting old message") + } } // Discord caches the images and the URLs do not change every time diff --git a/wiki/Home.md b/wiki/Home.md index a6de8df..065b152 100644 --- a/wiki/Home.md +++ b/wiki/Home.md @@ -85,6 +85,7 @@ Announces stream live status based on Discord streaming status | `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) | | `preserve_proxy` | | string | | URL prefix of a Luzifer/preserve proxy to cache stream preview for longer | +| `remove_old` | | bool | `false` | If set to `true` older message with same content will be deleted | | `stream_freshness` | | duration | `5m` | How long after stream start to post shoutout | | `whitelisted_role` | | string | | Only post for members of this role ID |