Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Throttle duplicate iOS sandbox Discord alerts

Neeraj Gupta4413cdf8f587
diff --git a/server/pkg/controller/appstore.go b/server/pkg/controller/appstore.go
index 7ef3347bc7..bdca2511d9 100644
--- a/server/pkg/controller/appstore.go
+++ b/server/pkg/controller/appstore.go
@@ -7,6 +7,7 @@ import (
"fmt"
"strconv"
"strings"
+ "time"
"github.com/ente-io/museum/pkg/controller/commonbilling"
"github.com/ente-io/museum/pkg/controller/discord"
@@ -79,8 +80,8 @@ func (c *AppStoreController) validateSandboxRequest(ctx context.Context, environ
}
maskedEmail := email.GetMaskedEmailWithHint(user.Email)
- c.DiscordController.Notify(fmt.Sprintf("iOS Sandbox %s for user: %s (userID: %d)",
- sandboxContext, maskedEmail, userID))
+ c.DiscordController.NotifyThrottled(fmt.Sprintf("iOS Sandbox %s for user: %s (userID: %d)",
+ sandboxContext, maskedEmail, userID), 10*time.Minute)
if strings.HasSuffix(email.NormalizeEmail(user.Email), "@ente.io") {
return nil
diff --git a/server/pkg/controller/discord/discord.go b/server/pkg/controller/discord/discord.go
index 91a9b7ce7e..198e48ed65 100644
--- a/server/pkg/controller/discord/discord.go
+++ b/server/pkg/controller/discord/discord.go
@@ -72,6 +72,19 @@ func (c *DiscordController) Notify(message string) {
c.sendMessage(c.MonaLisa, viper.GetString("discord.bot.mona-lisa.channel"), message)
}
+func (c *DiscordController) NotifyThrottled(message string, window time.Duration) {
+ c.mu.Lock()
+ defer c.mu.Unlock()
+
+ now := time.Now()
+ if lastTime, exists := c.lastSent[message]; exists && now.Sub(lastTime) < window {
+ log.Infof("Skipping duplicate Discord notification: %s", message)
+ return
+ }
+ c.lastSent[message] = now
+ c.Notify(message)
+}
+
// Send a message related to subscriptions.
func (c *DiscordController) NotifyNewSub(userID int64, paymentProvider string, amount string) {
message := fmt.Sprintf("New subscriber via `%s`, after %s of signing up! πŸ«‚ (%s)",
@@ -110,15 +123,7 @@ func (c *DiscordController) NotifyAccountDelete(userID int64, paymentProvider st
}
func (c *DiscordController) NotifyPotentialAbuse(message string) {
- c.mu.Lock()
- defer c.mu.Unlock()
- now := time.Now()
- if lastTime, exists := c.lastSent[message]; exists && now.Sub(lastTime) < time.Minute {
- log.Infof("Skipping duplicate abuse notification: %s", message)
- return
- }
- c.lastSent[message] = now
- c.Notify(fmt.Sprintf("%s: %s", c.HostName, message))
+ c.NotifyThrottled(fmt.Sprintf("%s: %s", c.HostName, message), time.Minute)
}
func (c *DiscordController) getTimeSinceSignUp(userID int64) string {