Add logging for successful role change

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2021-08-26 00:36:59 +02:00
parent 49ce944d30
commit bd46a37bea
Signed by: luzifer
GPG key ID: 0066F03ED215AD7D

View file

@ -100,6 +100,7 @@ func (m modLiveRole) handlePresenceUpdate(d *discordgo.Session, p *discordgo.Pre
if err := exitFunc(p.GuildID, p.User.ID, member.Roles); err != nil { if err := exitFunc(p.GuildID, p.User.ID, member.Roles); err != nil {
logger.WithError(err).Error("Unable to update live-streamer-role") logger.WithError(err).Error("Unable to update live-streamer-role")
} }
logger.Info("Updated live-streamer-role")
} }
}() }()
@ -115,6 +116,7 @@ func (m modLiveRole) handlePresenceUpdate(d *discordgo.Session, p *discordgo.Pre
if activity == nil { if activity == nil {
// No streaming activity: Remove role // No streaming activity: Remove role
exitFunc = m.removeLiveStreamerRole exitFunc = m.removeLiveStreamerRole
logger = logger.WithField("action", "remove")
return return
} }
@ -122,12 +124,14 @@ func (m modLiveRole) handlePresenceUpdate(d *discordgo.Session, p *discordgo.Pre
if err != nil { if err != nil {
logger.WithError(err).WithField("url", activity.URL).Warning("Unable to parse activity URL") logger.WithError(err).WithField("url", activity.URL).Warning("Unable to parse activity URL")
exitFunc = m.removeLiveStreamerRole exitFunc = m.removeLiveStreamerRole
logger = logger.WithField("action", "remove")
return return
} }
if u.Host != "www.twitch.tv" { if u.Host != "www.twitch.tv" {
logger.WithError(err).WithField("url", activity.URL).Warning("Activity is not on Twitch") logger.WithError(err).WithField("url", activity.URL).Warning("Activity is not on Twitch")
exitFunc = m.removeLiveStreamerRole exitFunc = m.removeLiveStreamerRole
logger = logger.WithField("action", "remove")
return return
} }
@ -143,11 +147,13 @@ func (m modLiveRole) handlePresenceUpdate(d *discordgo.Session, p *discordgo.Pre
if err != nil { if err != nil {
logger.WithError(err).WithField("user", strings.TrimLeft(u.Path, "/")).Warning("Unable to fetch streams for user") logger.WithError(err).WithField("user", strings.TrimLeft(u.Path, "/")).Warning("Unable to fetch streams for user")
exitFunc = m.removeLiveStreamerRole exitFunc = m.removeLiveStreamerRole
logger = logger.WithField("action", "remove")
return return
} }
if len(streams.Data) > 0 { if len(streams.Data) > 0 {
exitFunc = m.addLiveStreamerRole exitFunc = m.addLiveStreamerRole
logger = logger.WithField("action", "add")
} }
} }