-
Notifications
You must be signed in to change notification settings - Fork 22
/
main.go
60 lines (46 loc) · 1.19 KB
/
main.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
package main
import (
"encoding/json"
"fmt"
"net/http"
"os"
"os/signal"
"syscall"
"github.com/bwmarrin/discordgo"
"github.com/summrs-dev-team/summrs-premium/api"
)
func main() {
fmt.Print("Enter your token: ")
fmt.Scan(&token)
req, _ := http.NewRequest("GET", "https://discord.com/api/v8/gateway/bot", nil) // I would use fasthttp but does speed really matter that much here?
req.Header.Add("Authorization", fmt.Sprintf("Bot %s", token))
res, err := http.DefaultClient.Do(req)
if err != nil {
fmt.Printf("[Sharding Error]: %s\n", err.Error())
return
}
defer res.Body.Close()
gresponse := &discordgo.GatewayBotResponse{}
json.NewDecoder(res.Body).Decode(&gresponse)
if err != nil {
fmt.Printf("[Decode Error]: %s\n", err.Error())
return
}
var shardCount = gresponse.Shards
if shardCount < 2 {
shardCount = 1
}
bot.Sessions = make([]*discordgo.Session, shardCount)
for s := 0; s < shardCount; s++ {
bot.Shard(token, shardCount, s)
bot.Run()
}
sc := make(chan os.Signal, 1)
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt, os.Kill)
<-sc
bot.Stop()
}
var (
bot = api.Bot{}
token string
)