-
Notifications
You must be signed in to change notification settings - Fork 0
/
dsclient.go
81 lines (73 loc) · 1.98 KB
/
dsclient.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
75
76
77
78
79
80
81
// Copyrights mikeuwu 2020-21
package discordservices
import (
"bytes"
"encoding/json"
"fmt"
"log"
"net/http"
"strconv"
)
// const notoken := errors.New()
type DSClient struct {
token string
botid int
}
func (c DSClient) postShardCOunt(count int) {
// Post stats to discordservices api
// Required arguments: count int -> shard count
stred := strconv.Itoa(c.botid)
var url = "https://api.discordservices.net/bot/" + stred + "/stats"
if count == 0 {
fmt.Println("[ERROR] - No count provided")
} else {
var jsonBody, parserr = json.Marshal(map[string]int{"shards": count})
if parserr != nil {
log.Fatalln(parserr)
}
var resp, err = http.NewRequest("POST", url, bytes.NewBuffer(jsonBody))
if err != nil {
log.Fatalln(err)
}
resp.Header.Set("Content-Type", "application/json")
resp.Header.Set("Authorization", c.token)
var client = &http.Client{}
var req, httperr = client.Do(resp)
if httperr != nil {
log.Fatalln(httperr)
}
defer req.Body.Close()
var body = req.Body
log.Println("Responce status: %v\n", req.Status)
log.Println("Responce body: %v\n", body)
}
}
func (c DSClient) postGuildCount(count int) {
// Post stats to discordservices api
// Required arguments: count int -> Guild count
stred := strconv.Itoa(c.botid)
var url = "https://api.discordservices.net/bot/" + stred + "/stats"
if count == 0 {
fmt.Println("[ERROR] - No count provided")
} else {
var jsonBody, parserr = json.Marshal(map[string]int{"servers": count})
if parserr != nil {
log.Fatalln(parserr)
}
var resp, err = http.NewRequest("POST", url, bytes.NewBuffer(jsonBody))
if err != nil {
log.Fatalln(err)
}
resp.Header.Set("Content-Type", "application/json")
resp.Header.Set("Authorization", c.token)
var client = &http.Client{}
var req, httperr = client.Do(resp)
if httperr != nil {
log.Fatalln(httperr)
}
defer req.Body.Close()
//var body = req.Body
fmt.Println("Responce status: ", req.Status)
//log.Println("Responce body: %v\n", body)
}
}