Refine the discord api a little
This commit is contained in:
@@ -10,6 +10,13 @@ import (
|
||||
"os"
|
||||
)
|
||||
|
||||
func NotifyDiscordErrorless(message string) {
|
||||
err := NotifyDiscord(message)
|
||||
if err != nil {
|
||||
log.Printf("Error notifying discord: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func NotifyDiscord(message string) error {
|
||||
webhookURL := os.Getenv("YTDL_DISCORD_WEBHOOK_URL")
|
||||
if webhookURL == "" {
|
||||
|
@@ -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
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user