summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabe Kangas <gabek@real-ity.com>2022-02-03 21:45:01 -0800
committerGabe Kangas <gabek@real-ity.com>2022-03-07 16:51:58 -0800
commitd4274ab162cd2e144220f789693eb07a0de4cfaa (patch)
tree49affada8cd78e8a6d54d8626415800c32727b54
parentd7bbf295274c8890c157441d5914b9be494e35ec (diff)
Add stream title to discord and twitter notifications
-rw-r--r--notifications/notifications.go21
-rw-r--r--utils/utils.go10
2 files changed, 27 insertions, 4 deletions
diff --git a/notifications/notifications.go b/notifications/notifications.go
index 29d259c7d..f3a0e5f6b 100644
--- a/notifications/notifications.go
+++ b/notifications/notifications.go
@@ -11,6 +11,7 @@ import (
"github.com/owncast/owncast/notifications/discord"
"github.com/owncast/owncast/notifications/email"
"github.com/owncast/owncast/notifications/twitter"
+ "github.com/owncast/owncast/utils"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
)
@@ -133,7 +134,14 @@ func (n *Notifier) setupDiscord() error {
}
func (n *Notifier) notifyDiscord() {
- if err := n.discord.Send(data.GetDiscordConfig().GoLiveMessage); err != nil {
+ goLiveMessage := data.GetDiscordConfig().GoLiveMessage
+ streamTitle := data.GetStreamTitle()
+ if streamTitle != "" {
+ goLiveMessage += "\n" + streamTitle
+ }
+ message := fmt.Sprintf("%s\n\n%s", goLiveMessage, data.GetServerURL())
+
+ if err := n.discord.Send(message); err != nil {
log.Errorln("error sending discord message", err)
}
}
@@ -151,13 +159,18 @@ func (n *Notifier) setupTwitter() error {
func (n *Notifier) notifyTwitter() {
goLiveMessage := data.GetTwitterConfiguration().GoLiveMessage
+ streamTitle := data.GetStreamTitle()
+ if streamTitle != "" {
+ goLiveMessage += "\n" + streamTitle
+ }
tagString := ""
- for _, tag := range data.GetServerMetadataTags() {
- tagString += fmt.Sprintf("%s #%s", tagString, tag)
+ for _, tag := range utils.ShuffleStringSlice(data.GetServerMetadataTags()) {
+ tagString = fmt.Sprintf("%s #%s", tagString, tag)
}
tagString = strings.TrimSpace(tagString)
- message := fmt.Sprintf("%s\n\n%s\n\n%s", goLiveMessage, data.GetServerURL(), tagString)
+ message := fmt.Sprintf("%s\n%s\n\n%s", goLiveMessage, data.GetServerURL(), tagString)
+
if err := n.twitter.Notify(message); err != nil {
log.Errorln("error sending twitter message", err)
}
diff --git a/utils/utils.go b/utils/utils.go
index ab40cf5c7..b68e74b28 100644
--- a/utils/utils.go
+++ b/utils/utils.go
@@ -13,6 +13,7 @@ import (
"path/filepath"
"regexp"
"strings"
+ "time"
"github.com/mssola/user_agent"
log "github.com/sirupsen/logrus"
@@ -366,3 +367,12 @@ func GetHashtagsFromText(text string) []string {
re := regexp.MustCompile(`#[a-zA-Z0-9_]+`)
return re.FindAllString(text, -1)
}
+
+// ShuffleStringSlice will shuffle a slice of strings.
+func ShuffleStringSlice(s []string) []string {
+ rand.Seed(time.Now().UnixNano())
+ rand.Shuffle(len(s), func(i, j int) {
+ s[i], s[j] = s[j], s[i]
+ })
+ return s
+}