-
Notifications
You must be signed in to change notification settings - Fork 1
/
server_xp.go
65 lines (50 loc) · 1.83 KB
/
server_xp.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
package guildedgo
import "errors"
type XPObject struct {
Amount int `json:"amount"`
}
type AwardXPResponse struct {
Total int `json:"total"`
}
type xpEndpoints struct{}
func (e *xpEndpoints) Default(serverID, userID string) string {
return guildedApi + "/servers/" + serverID + "/members/" + userID + "/xp"
}
func (e *xpEndpoints) Role(serverID, roleID string) string {
return guildedApi + "/servers/" + serverID + "/roles/" + roleID + "/xp"
}
type ServerXPService interface {
AwardXP(serverID, userID string, xpObject *XPObject) (*AwardXPResponse, error)
SetMemberXP(serverID, userID string, xpObject *XPObject) (*AwardXPResponse, error)
AwardRoleXP(serverID, roleID string, xpObject *XPObject) error
}
type serverXPService struct {
endpoints xpEndpoints
client *Client
}
var _ ServerXPService = &serverXPService{
endpoints: xpEndpoints{},
}
func (service *serverXPService) AwardXP(serverID, userID string, xpObject *XPObject) (*AwardXPResponse, error) {
var response AwardXPResponse
err := service.client.PostRequestV2(service.endpoints.Default(serverID, userID), &xpObject, &response)
if err != nil {
return nil, errors.New("error awarding xp: " + err.Error())
}
return &response, nil
}
func (service *serverXPService) SetMemberXP(serverID, userID string, xpObject *XPObject) (*AwardXPResponse, error) {
var response AwardXPResponse
err := service.client.PutRequestV2(service.endpoints.Default(serverID, userID), &xpObject, &response)
if err != nil {
return nil, errors.New("error setting member xp: " + err.Error())
}
return &response, nil
}
func (service *serverXPService) AwardRoleXP(serverID, roleID string, xpObject *XPObject) error {
err := service.client.PostRequestV2(service.endpoints.Role(serverID, roleID), &xpObject, nil)
if err != nil {
return errors.New("error awarding role xp: " + err.Error())
}
return nil
}