-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiscord_webhook_test.go
74 lines (70 loc) · 1.78 KB
/
discord_webhook_test.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package discord
import (
"net"
"net/http"
"net/url"
"testing"
"time"
)
var (
proxy = ""
webhookUrl = "https://discord.com/api/webhooks/xxxxx/xxxxxxx"
)
func TestDiscord(t *testing.T) {
client := http.DefaultClient
if proxy != "" {
client = &http.Client{
Transport: &http.Transport{
Proxy: func(req *http.Request) (*url.URL, error) {
return url.Parse(proxy)
},
Dial: (&net.Dialer{
Timeout: 10 * time.Second,
}).Dial,
},
Timeout: 10 * time.Second,
}
}
newWebhook := &Webhook{
Content: "Hello",
//Username: "I'm the King",
AvatarUrl: "https://golang.org/lib/godoc/images/footer-gopher.jpg",
Embeds: []Embed{
{
Title: "Win Win Win",
Description: "This is the embed's description",
Url: "https://github.com/etaaa/go-webhooks",
Timestamp: GetTimestamp(), // RETURNS NEW TIMESTAMP ACCORDING TO DISCORD'S FORMAT
Color: GetColor("#00ff00"), // RETURNS COLOR ACCORDING TO DISCORD'S FORMAT
//Footer: EmbedFooter{
// Text: "Sent via github.com/etaaa/go-webhooks",
//},
Footer: EmbedFooter{
Text: "powered by binance",
IconUrl: "https://raw.githubusercontent.com/coinrust/crex/master/images/binance.jpg",
ProxyIconUrl: "https://raw.githubusercontent.com/coinrust/crex/master/images/binance.jpg",
},
Thumbnail: EmbedThumbnail{
Url: "https://raw.githubusercontent.com/coinrust/crex/master/images/binance.jpg",
},
Fields: []EmbedFields{
{
Name: "I'm richer",
Value: "Win $100,000,000",
Inline: true,
},
{
Name: "I'm richer",
Value: "Win $100,000,000 again",
Inline: true,
},
},
},
},
}
err := SendWebhook(webhookUrl,
client, newWebhook, false)
if err != nil {
t.Fatal(err)
}
}