This adds checking if we already sent a status update for that given stream based on the channelid
--- a/database/bitcask.go Tue Apr 09 13:14:34 2019 -0700
+++ b/database/bitcask.go Mon Apr 15 13:49:20 2019 -0700
@@ -1,6 +1,9 @@
"github.com/prologic/bitcask"
log "github.com/sirupsen/logrus"
@@ -44,6 +47,26 @@
+func (db db_bitcask) AlreadyPostedStatus(channelid, streamid string) bool { + data, err := db.database.Get(channelid) + if err != nil || len(data) == 0 { + log.Errorf("Bitcash AlreadySend error: %s", err) + return strings.EqualFold(streamid, string(data)) +func (db db_bitcask) AddStatusUpdate(channelid, streamid string) error { + if db.AlreadyPostedStatus(channelid, streamid) { + return fmt.Errorf("Bitcash AddStatusUpdate failed for %s -> %s", channelid, streamid) + return db.database.Put(channelid, []byte(streamid)) func (db db_bitcask) Close() {
--- a/database/database.go Tue Apr 09 13:14:34 2019 -0700
+++ b/database/database.go Mon Apr 15 13:49:20 2019 -0700
@@ -10,6 +10,8 @@
GetGuild(guildid string) *Guild
UpdateGuild(guild *Guild)
+ AlreadyPostedStatus(channelid, streamid string) bool + AddStatusUpdate(channelid, streamid string) error --- a/discord/presence.go Tue Apr 09 13:14:34 2019 -0700
+++ b/discord/presence.go Mon Apr 15 13:49:20 2019 -0700
@@ -26,6 +26,15 @@
presence, _ := presence.GetPresence(p.Game.URL)
+ if c.db.AlreadyPostedStatus(presence.UserID, presence.StreamID) { + log.Debugf("already sent presence to guild %s: %v", p.GuildID, presence) + if err := c.db.AddStatusUpdate(presence.UserID, presence.StreamID); err != nil { + log.Warnf("failed to add user (%s) stream (%s) to database, %v", presence.UserID, presence.StreamID, err) if err := c.sendPresence(p.GuildID, presence); err != nil {
log.Warnf("failed to send presence to guild %s: %v, %v", p.GuildID, err, presence)
--- a/go.mod Tue Apr 09 13:14:34 2019 -0700
+++ b/go.mod Mon Apr 15 13:49:20 2019 -0700
@@ -9,7 +9,7 @@
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf // indirect
github.com/bwmarrin/discordgo v0.19.0
github.com/dustin/go-humanize v1.0.0
- github.com/go-redis/redis v6.15.2+incompatible
+ github.com/go-redis/redis v6.15.2+incompatible // indirect github.com/iancoleman/orderedmap v0.0.0-20190318233801-ac98e3ecb4b0
github.com/nicklaw5/helix v0.5.1
github.com/nicksnyder/go-i18n v1.10.0 // indirect
--- a/presence/presence.go Tue Apr 09 13:14:34 2019 -0700
+++ b/presence/presence.go Mon Apr 15 13:49:20 2019 -0700
@@ -1,7 +1,9 @@
--- a/twitch/twitch.go Tue Apr 09 13:14:34 2019 -0700
+++ b/twitch/twitch.go Mon Apr 15 13:49:20 2019 -0700
@@ -54,7 +54,9 @@
profile_url = strings.Replace(profile_url, "{height}", "255", -1)
Username: user.DisplayName,
Viewers: int64(stream.ViewerCount),
Language: stream.Language,