-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.go
56 lines (44 loc) · 1022 Bytes
/
bot.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
package revolt
import (
"encoding/json"
"time"
"github.com/oklog/ulid/v2"
)
// Bot struct.
type Bot struct {
Client *Client
CreatedAt time.Time
Id string `json:"_id"`
OwnerId string `json:"owner"`
Token string `json:"token"`
IsPublic bool `json:"public"`
InteractionsUrl string `json:"interactionsURL"`
}
// Fetched bots struct.
type FetchedBots struct {
Bots []*Bot `json:"bots"`
Users []*User `json:"users"`
}
// Calculate creation date and edit the struct.
func (b *Bot) CalculateCreationDate() error {
ulid, err := ulid.Parse(b.Id)
if err != nil {
return err
}
b.CreatedAt = time.UnixMilli(int64(ulid.Time()))
return nil
}
// Edit the bot.
func (b *Bot) Edit(eb *EditBot) error {
data, err := json.Marshal(eb)
if err != nil {
return err
}
_, err = b.Client.Request("PATCH", "/bots/"+b.Id, data)
return err
}
// Delete the bot.
func (b *Bot) Delete() error {
_, err := b.Client.Request("DELETE", "/bots/"+b.Id, []byte{})
return err
}