generated from PoCInnovation/open-source-project-template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
webhook.go
49 lines (44 loc) · 805 Bytes
/
webhook.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package main
import (
"bytes"
"encoding/json"
"net/http"
)
type Author struct {
Name string `json:"name"`
IconUrl string `json:"icon_url"`
}
type Embed struct {
Title string `json:"title"`
Description string `json:"description"`
Author Author `json:"author"`
Color int `json:"color"`
}
func queueRequest(a []Embed) {
var b []Embed
for i, p := range a {
b = append(b, p)
if (i+1)%10 == 0 {
err := postWebhook(b)
if err != nil {
return
}
b = nil
}
}
if len(b) > 0 {
err := postWebhook(b)
if err != nil {
return
}
}
}
func postWebhook(e []Embed) error {
b := Body{Embeds: e}
jsonData, _ := json.Marshal(b)
_, err := http.Post(WebhookURL, "application/json", bytes.NewBuffer(jsonData))
if err != nil {
return err
}
return nil
}