FreyaMode won't affect other message processing steps

This commit is contained in:
Asaf Gartner 2024-05-14 17:55:23 +03:00
parent 23b1b30d22
commit 1aab3b47b3
1 changed files with 11 additions and 13 deletions

View File

@ -33,12 +33,6 @@ var autostoreChannels = []string{
} }
func HandleIncomingMessage(ctx context.Context, dbConn db.ConnOrTx, msg *Message, createSnippets bool) error { func HandleIncomingMessage(ctx context.Context, dbConn db.ConnOrTx, msg *Message, createSnippets bool) error {
if handled, err := FreyaMode(ctx, dbConn, msg); handled {
return nil
} else if err != nil {
return err
}
deleted := false deleted := false
var err error var err error
@ -64,6 +58,10 @@ func HandleIncomingMessage(ctx context.Context, dbConn db.ConnOrTx, msg *Message
err = HandleInternedMessage(ctx, dbConn, msg, deleted, createSnippets) err = HandleInternedMessage(ctx, dbConn, msg, deleted, createSnippets)
} }
if !deleted && err == nil {
err = FreyaMode(ctx, dbConn, msg)
}
return err return err
} }
@ -147,12 +145,12 @@ func CleanUpLibrary(ctx context.Context, dbConn db.ConnOrTx, msg *Message) (bool
return deleted, nil return deleted, nil
} }
func FreyaMode(ctx context.Context, dbConn db.ConnOrTx, msg *Message) (bool, error) { func FreyaMode(ctx context.Context, dbConn db.ConnOrTx, msg *Message) error {
if msg.Author.IsBot { if msg.Author.IsBot {
return false, nil return nil
} }
if msg.ChannelID == config.Config.Discord.ShowcaseChannelID { if msg.ChannelID == config.Config.Discord.ShowcaseChannelID || msg.ChannelID == config.Config.Discord.LibraryChannelID {
return false, nil return nil
} }
twitteryUrls := []string{ twitteryUrls := []string{
@ -168,7 +166,7 @@ func FreyaMode(ctx context.Context, dbConn db.ConnOrTx, msg *Message) (bool, err
} }
} }
if !isTwittery { if !isTwittery {
return false, nil return nil
} }
// FREYA MODE ENGAGED // FREYA MODE ENGAGED
@ -205,10 +203,10 @@ func FreyaMode(ctx context.Context, dbConn db.ConnOrTx, msg *Message) (bool, err
}, },
}) })
if err != nil { if err != nil {
return false, oops.New(err, "failed to send Freya tweet") return oops.New(err, "failed to send Freya tweet")
} }
return true, nil return nil
} }
func ShareToMatrix(ctx context.Context, msg *Message) error { func ShareToMatrix(ctx context.Context, msg *Message) error {