-
Notifications
You must be signed in to change notification settings - Fork 0
/
bgl.go
112 lines (96 loc) · 3 KB
/
bgl.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// This file was generated from JSON Schema using quicktype, do not modify it directly.
// To parse and unparse this JSON data, add this code to your project and do:
//
// matchResult, err := UnmarshalMatchResult(bytes)
// bytes, err = matchResult.Marshal()
package main
import (
"encoding/json"
"io/ioutil"
"log"
"net/http"
"time"
)
type TeamsResult struct {
Count int `json:"count"`
Next interface{} `json:"next"`
Previous interface{} `json:"previous"`
Teams []struct {
ID int `json:"id"`
Name string `json:"name"`
Circuit int `json:"circuit"`
Group interface{} `json:"group"`
IsActive bool `json:"is_active"`
CanAddMembers bool `json:"can_add_members"`
Dynasty interface{} `json:"dynasty"`
Captain struct {
ID int `json:"id"`
Name string `json:"name"`
NamePhonetic interface{} `json:"name_phonetic"`
Pronouns string `json:"pronouns"`
DiscordUsername interface{} `json:"discord_username"`
TwitchUsername string `json:"twitch_username"`
Bio string `json:"bio"`
Emoji interface{} `json:"emoji"`
AvatarURL string `json:"avatar_url"`
Modified time.Time `json:"modified"`
Created time.Time `json:"created"`
} `json:"captain"`
Members []struct {
ID int `json:"id"`
Name string `json:"name"`
NamePhonetic string `json:"name_phonetic"`
Pronouns string `json:"pronouns"`
DiscordUsername string `json:"discord_username"`
TwitchUsername string `json:"twitch_username"`
Bio string `json:"bio"`
Emoji interface{} `json:"emoji"`
AvatarURL string `json:"avatar_url"`
Modified time.Time `json:"modified"`
Created time.Time `json:"created"`
} `json:"members"`
Modified time.Time `json:"modified"`
Created time.Time `json:"created"`
Wins int `json:"wins"`
Losses int `json:"losses"`
} `json:"results"`
}
func GetBGLTeams() TeamsResult {
url := "https://api.beegame.gg/teams/?is_active=true"
method := "GET"
client := &http.Client{}
req, err := http.NewRequest(method, url, nil)
if err != nil {
log.Println(err)
}
res, err := client.Do(req)
if err != nil {
log.Println(err)
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
if err != nil {
log.Println(err)
}
var teamsResult TeamsResult
err = json.Unmarshal(body, &teamsResult)
if err != nil {
log.Println(err)
}
return teamsResult
}
func GetTeamInfo(c chan []Team) {
log.Println("Fetching Team Information from BGL...")
bglTeams := GetBGLTeams()
teams := []Team{}
for _, v := range bglTeams.Teams {
team := Team{}
team.Name = v.Name
team.Tier = v.Circuit
team.Img = KQBAvatarImage
team.Stats.MatchesWon = v.Wins
team.Stats.MatchesLost = v.Losses
teams = append(teams, team)
}
c <- teams
}