From b243e2f7f127f396bc9ae5b2076615e6c3cf3340 Mon Sep 17 00:00:00 2001 From: ayn2op Date: Wed, 30 Jul 2025 15:03:18 -0400 Subject: [PATCH] perf(notifications): exit early if notifications are disabled --- internal/notifications/notifications.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/internal/notifications/notifications.go b/internal/notifications/notifications.go index 90b6529..b7d4516 100644 --- a/internal/notifications/notifications.go +++ b/internal/notifications/notifications.go @@ -16,9 +16,12 @@ import ( ) func Notify(state *ningen.State, msg *gateway.MessageCreateEvent, cfg *config.Config) error { + if !cfg.Notifications.Enabled || cfg.Status == discord.DoNotDisturbStatus { + return nil + } + mentions := state.MessageMentions(&msg.Message) - // Only display notification if enabled and unmuted - if !cfg.Notifications.Enabled || mentions == 0 || cfg.Status == discord.DoNotDisturbStatus { + if mentions == 0 { return nil } @@ -87,11 +90,11 @@ func getCachedProfileImage(avatarHash discord.Hash, url string) (string, error) return path, nil } - image, err := os.Create(path) + file, err := os.Create(path) if err != nil { return "", err } - defer image.Close() + defer file.Close() resp, err := http.Get(url) if err != nil { @@ -99,7 +102,7 @@ func getCachedProfileImage(avatarHash discord.Hash, url string) (string, error) } defer resp.Body.Close() - if _, err := io.Copy(image, resp.Body); err != nil { + if _, err := io.Copy(file, resp.Body); err != nil { return "", err }