This repository has been archived by the owner on Nov 16, 2020. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
contest.go
72 lines (65 loc) · 2.41 KB
/
contest.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
package golem
import (
"strconv"
"github.com/mitchellh/mapstructure"
)
// GetContestType returns a ContestType object
// Acceptable search queries:
// ID, Name
func GetContestType(query string) ContestType {
searchType := idOrString(query)
contestType := ContestType{}
if checkCache("contest-type", query, searchType) {
mapstructure.Decode(getDataCache("contest-type", query, searchType, contestType), &contestType)
} else {
dataInterface = getDataAPI("contest-type", query, contestType)
if dataInterface != nil {
mapstructure.Decode(dataInterface, &contestType)
storeData(false, contestType, "contest-type", contestType.ID, contestType.Name)
}
}
contestType.GetBerryFlavor = getBerryFlavor(contestType.BerryFlavor.Name)
for i, ct := range contestType.Names {
contestType.Names[i].GetLanguage = getLanguage(ct.Language.Name)
}
return contestType
}
// GetContestEffect returns a ContestEffect object
// Acceptable search queries:
// ID
func GetContestEffect(id int) ContestEffect {
searchType := "ID" // Because the only acceptable searchType is ID, we don't need to call the function
query := strconv.Itoa(id)
contestEffect := ContestEffect{}
if checkCache("contest-effect", query, searchType) {
mapstructure.Decode(getDataCache("contest-effect", query, searchType, contestEffect), &contestEffect)
} else {
dataInterface = getDataAPI("contest-effect", query, contestEffect)
if dataInterface != nil {
mapstructure.Decode(dataInterface, &contestEffect)
storeData(true, contestEffect, "contest-effect", contestEffect.ID, "")
}
}
return contestEffect
}
// GetSuperContestEffect returns a SuperContestEffect object
// Acceptable search queries:
// ID
func GetSuperContestEffect(id int) SuperContestEffect {
searchType := "ID"
query := strconv.Itoa(id)
superContestEffect := SuperContestEffect{}
if checkCache("super-contest-effect", query, searchType) {
mapstructure.Decode(getDataCache("super-contest-effect", query, searchType, superContestEffect), &superContestEffect)
} else {
dataInterface = getDataAPI("super-contest-effect", query, superContestEffect)
if dataInterface != nil {
mapstructure.Decode(dataInterface, &superContestEffect)
storeData(true, superContestEffect, "super-contest-effect", superContestEffect.ID, "")
}
}
for _, m := range superContestEffect.Moves {
superContestEffect.GetMoves = append(superContestEffect.GetMoves, getMove(m.Name))
}
return superContestEffect
}