Skip to content

Commit

Permalink
refactor: discord webhook.
Browse files Browse the repository at this point in the history
  • Loading branch information
dvgamerr committed May 29, 2023
1 parent 06fa2b5 commit 8ec16a1
Showing 1 changed file with 26 additions and 10 deletions.
36 changes: 26 additions & 10 deletions act/notify.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,36 @@ import (
)

func (hoyo *Hoyolab) NotifyMessage(message string) error {
if hoyo.Notify.LINENotify == "" || message == "" {
if message == "" {
return nil
}

raw, err := resty.New().R().
SetHeaders(map[string]string{"Authorization": fmt.Sprintf("Bearer %s", hoyo.Notify.LINENotify)}).
SetFormData(map[string]string{"message": message}).
Post("https://notify-api.line.me/api/notify")
if err != nil {
return fmt.Errorf("notify::%+v", err)
if hoyo.Notify.LINENotify != "" {
raw, err := resty.New().R().
SetHeaders(map[string]string{"Authorization": fmt.Sprintf("Bearer %s", hoyo.Notify.LINENotify)}).
SetFormData(map[string]string{"message": message}).
Post("https://notify-api.line.me/api/notify")
if err != nil {
return fmt.Errorf("line::%+v", err)
}
if raw.StatusCode() != 200 {
return fmt.Errorf("line::%s", raw.Status())
}
log.Println("LINENotify Message Sending...")
}
if raw.StatusCode() != 200 {
return fmt.Errorf("notify::%s", raw.Status())

if hoyo.Notify.Discord != "" {
raw, err := resty.New().R().
SetFormData(map[string]string{"content": message}).
Post(hoyo.Notify.Discord)
if err != nil {
return fmt.Errorf("Discord::%+v", err)
}
if raw.StatusCode() != 200 {
return fmt.Errorf("Discord::%s", raw.Status())
}
log.Println("Discord Message Sending...")
}
log.Println("NotifyMessage Sending...")

return nil
}

0 comments on commit 8ec16a1

Please sign in to comment.