Readstate now treats temporarily muted correctly

This solves the problem that a temporarily muted channel or guild will
always be seen as muted and cause no notifications to be sent.
This commit is contained in:
Marcel Schramm 2020-10-18 14:23:32 +02:00
parent 83c0ee7a0b
commit 767d19a5f8
No known key found for this signature in database
GPG Key ID: 05971054C70EEDC7
3 changed files with 23 additions and 6 deletions

2
go.mod
View File

@ -4,7 +4,7 @@ go 1.12
require (
github.com/Bios-Marcel/discordemojimap v1.0.1
github.com/Bios-Marcel/discordgo v0.21.2-0.20201011131701-9eda31330792
github.com/Bios-Marcel/discordgo v0.21.2-0.20201018121341-5060bbaaa5a2
github.com/Bios-Marcel/goclipimg v0.0.0-20191117180634-d0f7b06fbe82
github.com/Bios-Marcel/shortnotforlong v1.1.1
github.com/alecthomas/chroma v0.6.6

4
go.sum
View File

@ -1,7 +1,7 @@
github.com/Bios-Marcel/discordemojimap v1.0.1 h1:b3UYPO7+h1+ciStkwU/KQCerOmpUNPHsBf4a7EjMdys=
github.com/Bios-Marcel/discordemojimap v1.0.1/go.mod h1:AoHIpUwf3EVCAAUmk+keXjb9khyZcFnW84/rhJd4IkU=
github.com/Bios-Marcel/discordgo v0.21.2-0.20201011131701-9eda31330792 h1:fYTwK7mGmVLDPqVYqQfwJS/BErhGHVcTCKvf3mRSIJM=
github.com/Bios-Marcel/discordgo v0.21.2-0.20201011131701-9eda31330792/go.mod h1:bLnfQU0j/SejmPozgW5GepmKvd8CrbMIml2I0IZENVE=
github.com/Bios-Marcel/discordgo v0.21.2-0.20201018121341-5060bbaaa5a2 h1:8sASIIHFlB6kbrnRYKAzaE2hxl/+IYcBhSlr36I+LVc=
github.com/Bios-Marcel/discordgo v0.21.2-0.20201018121341-5060bbaaa5a2/go.mod h1:bLnfQU0j/SejmPozgW5GepmKvd8CrbMIml2I0IZENVE=
github.com/Bios-Marcel/goclipimg v0.0.0-20191117180634-d0f7b06fbe82 h1:gspJ6CW9bhboosSISmuX2iq03pUsYHzlJN0s+z4fz4E=
github.com/Bios-Marcel/goclipimg v0.0.0-20191117180634-d0f7b06fbe82/go.mod h1:hiFR6fH5+uc/f2yK2syh/UfzaPfGo6F2HJSoiI4ufWU=
github.com/Bios-Marcel/shortnotforlong v1.1.1 h1:cCJIp6MODd4rwH5Y+fAMAaIuFxS1FPKfwDbRzsCU9nM=

View File

@ -129,7 +129,7 @@ func UpdateReadBuffered(session *discordgo.Session, channel *discordgo.Channel,
func IsGuildMuted(guildID string) bool {
for _, settings := range state.UserGuildSettings {
if settings.GuildID == guildID {
if settings.Muted {
if settings.Muted && isStillMuted(settings.MuteConfig) {
return true
}
@ -198,6 +198,23 @@ func HasGuildBeenMentioned(guildID string) bool {
return false
}
func isStillMuted(config *discordgo.MuteConfig) bool {
if config == nil || config.EndTime == "" {
//This means permanently muted; I think!
//We make the assumption that this function is only
//called if "Muted" is set to "true". Therefore no timeframe means
//we must be permanently muted.
return true
}
muteEndTime, parseError := config.EndTime.Parse()
if parseError != nil {
panic(parseError)
}
return time.Now().UTC().Before(muteEndTime)
}
func isChannelMuted(channel *discordgo.Channel) bool {
//optimization for the case of guild channels, as the handling for
//private channels will be unnecessarily slower.
@ -227,7 +244,7 @@ func isGuildChannelMuted(guildID, channelID string) bool {
if settings.GetGuildID() == guildID {
for _, override := range settings.ChannelOverrides {
if override.ChannelID == channelID {
if override.Muted {
if override.Muted && isStillMuted(override.MuteConfig) {
return true
}
@ -251,7 +268,7 @@ func IsPrivateChannelMuted(channel *discordgo.Channel) bool {
if settings.GetGuildID() == "" {
for _, override := range settings.ChannelOverrides {
if override.ChannelID == channel.ID {
if override.Muted {
if override.Muted && isStillMuted(override.MuteConfig) {
return true
}