Refine the discord api a little
This commit is contained in:
@@ -10,6 +10,13 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func NotifyDiscordErrorless(message string) {
|
||||||
|
err := NotifyDiscord(message)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Error notifying discord: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func NotifyDiscord(message string) error {
|
func NotifyDiscord(message string) error {
|
||||||
webhookURL := os.Getenv("YTDL_DISCORD_WEBHOOK_URL")
|
webhookURL := os.Getenv("YTDL_DISCORD_WEBHOOK_URL")
|
||||||
if webhookURL == "" {
|
if webhookURL == "" {
|
||||||
|
@@ -44,21 +44,13 @@ type DLHandler struct{}
|
|||||||
|
|
||||||
func (*DLHandler) HandleMessage(message *nsq.Message) error {
|
func (*DLHandler) HandleMessage(message *nsq.Message) error {
|
||||||
log.Printf("Received message '%s' with %d attempts", message.Body, message.Attempts)
|
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))
|
NotifyDiscordErrorless(fmt.Sprintf("Received message '%s' with %d attempts", message.Body, message.Attempts))
|
||||||
if err != nil {
|
|
||||||
Error.Printf("Error notifying discord: %v", err)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
data := DownloadRequest{}
|
data := DownloadRequest{}
|
||||||
err = json.Unmarshal(message.Body, &data)
|
err := json.Unmarshal(message.Body, &data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Error.Printf("Error unmarshalling message: %v", err)
|
Error.Printf("Error unmarshalling message: %v", err)
|
||||||
err = NotifyDiscord(fmt.Sprintf("Error unmarshalling message: %v", err))
|
NotifyDiscordErrorless(fmt.Sprintf("Error unmarshalling message: %v", err))
|
||||||
if err != nil {
|
|
||||||
Error.Printf("Error notifying discord: %v", err)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,19 +74,11 @@ func (*DLHandler) HandleMessage(message *nsq.Message) error {
|
|||||||
err = downloader.Download(data.Link)
|
err = downloader.Download(data.Link)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Error.Printf("Error downloading %s: %v", data.Link, err)
|
Error.Printf("Error downloading %s: %v", data.Link, err)
|
||||||
err = NotifyDiscord(fmt.Sprintf("Error downloading %s: %v", data.Link, err))
|
NotifyDiscordErrorless(fmt.Sprintf("Error downloading %s: %v", data.Link, err))
|
||||||
if err != nil {
|
|
||||||
Error.Printf("Error notifying discord: %v", err)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
message.Finish()
|
message.Finish()
|
||||||
err = NotifyDiscord(fmt.Sprintf("Downloaded %s", data.Link))
|
NotifyDiscordErrorless(fmt.Sprintf("Downloaded %s", data.Link))
|
||||||
if err != nil {
|
|
||||||
Error.Printf("Error notifying discord: %v", err)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user