Refine the discord api a little

This commit is contained in:
2025-04-13 16:30:28 +02:00
parent 00ed4e9fc1
commit 586c49558e
2 changed files with 12 additions and 21 deletions

View File

@@ -44,21 +44,13 @@ type DLHandler struct{}
func (*DLHandler) HandleMessage(message *nsq.Message) error {
log.Printf("Received message '%s' with %d attempts", message.Body, message.Attempts)
err := NotifyDiscord(fmt.Sprintf("Received message '%s' with %d attempts", message.Body, message.Attempts))
if err != nil {
Error.Printf("Error notifying discord: %v", err)
return err
}
NotifyDiscordErrorless(fmt.Sprintf("Received message '%s' with %d attempts", message.Body, message.Attempts))
data := DownloadRequest{}
err = json.Unmarshal(message.Body, &data)
err := json.Unmarshal(message.Body, &data)
if err != nil {
Error.Printf("Error unmarshalling message: %v", err)
err = NotifyDiscord(fmt.Sprintf("Error unmarshalling message: %v", err))
if err != nil {
Error.Printf("Error notifying discord: %v", err)
return err
}
NotifyDiscordErrorless(fmt.Sprintf("Error unmarshalling message: %v", err))
return err
}
@@ -82,19 +74,11 @@ func (*DLHandler) HandleMessage(message *nsq.Message) error {
err = downloader.Download(data.Link)
if err != nil {
Error.Printf("Error downloading %s: %v", data.Link, err)
err = NotifyDiscord(fmt.Sprintf("Error downloading %s: %v", data.Link, err))
if err != nil {
Error.Printf("Error notifying discord: %v", err)
return err
}
NotifyDiscordErrorless(fmt.Sprintf("Error downloading %s: %v", data.Link, err))
return err
}
message.Finish()
err = NotifyDiscord(fmt.Sprintf("Downloaded %s", data.Link))
if err != nil {
Error.Printf("Error notifying discord: %v", err)
return err
}
NotifyDiscordErrorless(fmt.Sprintf("Downloaded %s", data.Link))
return nil
}