2020-08-13 20:14:25 +00:00
|
|
|
package serverapi
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
2020-10-06 03:21:20 +00:00
|
|
|
// Unban is a Minecraft pardon
|
|
|
|
type Unban struct {
|
|
|
|
Target string `json:"target"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// Kick is a Minecraft kick
|
|
|
|
type Kick struct {
|
|
|
|
Unban
|
|
|
|
Reason string `json:"reason"`
|
|
|
|
}
|
|
|
|
|
2020-08-13 20:14:25 +00:00
|
|
|
// Ban is a Minecraft ban
|
|
|
|
type Ban struct {
|
2020-10-06 03:21:20 +00:00
|
|
|
Kick
|
|
|
|
Source string `json:"source"`
|
|
|
|
Created int64 `json:"created"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ban is a Minecraft ban with an expiration
|
|
|
|
type TempBan struct {
|
|
|
|
Ban
|
|
|
|
Expiration int64 `json:"expiration"`
|
2020-08-13 20:14:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// CreatedTime is Created converted to a time.Time
|
|
|
|
func (b *Ban) CreatedTime() time.Time {
|
|
|
|
return time.Unix(b.Created/1000, 0)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ExpirationTime is Expiration converted to a time.Time
|
2020-10-06 03:21:20 +00:00
|
|
|
func (t *TempBan) ExpirationTime() time.Time {
|
|
|
|
return time.Unix(t.Expiration/1000, 0)
|
2020-08-13 20:14:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Bans gets a list of Ban from a ServerAPI instance
|
2020-08-13 20:41:14 +00:00
|
|
|
func (c *Client) Bans() (bans Ban, err error) {
|
2020-10-06 03:21:20 +00:00
|
|
|
return bans, c.jsonGET(fmt.Sprintf("%s/bans", c.endpoint), &bans)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Kick kicks a player
|
|
|
|
func (c *Client) Kick(k Kick) (int, error) {
|
|
|
|
return c.jsonPOST(fmt.Sprintf("%s/kick", c.endpoint), k)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ban bans a player
|
|
|
|
func (c *Client) Ban(b Ban) (int, error) {
|
|
|
|
return c.jsonPOST(fmt.Sprintf("%s/ban", c.endpoint), b)
|
|
|
|
}
|
|
|
|
|
|
|
|
// TempBan temporarily bans a player
|
|
|
|
func (c *Client) TempBan(t TempBan) (int, error) {
|
|
|
|
return c.jsonPOST(fmt.Sprintf("%s/ban", c.endpoint), t)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Unban pardons a player
|
|
|
|
func (c *Client) Unban(u Unban) (int, error) {
|
|
|
|
return c.jsonPOST(fmt.Sprintf("%s/unban", c.endpoint), u)
|
2020-08-13 20:14:25 +00:00
|
|
|
}
|