Documentation
¶
Index ¶
- Constants
- func GetDefaultBase() url.URL
- func GetProxyRanges() ([]string, error)
- type Brigadier
- type BrigadierArgumentDefinition
- type BrigadierCommand
- func (cmd *BrigadierCommand) Boolean(arg_name string) *BrigadierCommand
- func (cmd *BrigadierCommand) Executes(fn func(*BrigadierInvocation)) *BrigadierCommand
- func (cmd *BrigadierCommand) Number(arg_name string) *BrigadierCommand
- func (cmd *BrigadierCommand) String(arg_name string) *BrigadierCommand
- func (cmd *BrigadierCommand) Then(commands ...*BrigadierCommand) *BrigadierCommand
- type BrigadierInvocation
- func (ev *BrigadierInvocation) Error(message string)
- func (ev *BrigadierInvocation) ReadBoolean(arg_name string) bool
- func (ev *BrigadierInvocation) ReadNumber(arg_name string) int
- func (ev *BrigadierInvocation) ReadString(arg_name string) string
- func (ev *BrigadierInvocation) Reply(message string)
- func (ev *BrigadierInvocation) ReplyMarkdown(message string)
- type Chatbox
- type ChatboxCommandPacket
- type ChatboxDiscordRole
- type ChatboxDiscordUser
- type ChatboxGenericEventPacket
- type ChatboxIngameUser
- type ChatboxTellPacket
- type DeathsLeaderboard
- type NewChatboxOptions
- type PlayTimeLeaderboard
- type PlayerCountsResponse
- type SupporterGoal
- type TpsResponse
Examples ¶
Constants ¶
const ( ChatboxFormattingMarkdown = iota ChatboxFormattingFormat )
Variables ¶
This section is empty.
Functions ¶
func GetDefaultBase ¶
func GetProxyRanges ¶
Fetches the current ComputerCraft proxies
Returns an array of IP ranges in CIDR notation that HTTP requests originate from when sent from ComputerCraft. This information can be used to block any traffic not originating from inside SwitchCraft. For an IPv4 address, a CIDR range of /32 means that the IP address will match exactly.
Example ¶
proxies, err := GetProxyRanges()
if err != nil {
log.Fatalln(err)
}
fmt.Printf("Current proxies: %s", strings.Join(proxies, ", "))
Types ¶
type Brigadier ¶
type Brigadier struct {
// contains filtered or unexported fields
}
An instance of Brigadier. Must be created with the NewBrigadier function.
func NewBrigadier ¶
Creates a new instance of Brigadier. Requires an instance of Chatbox passed, along with the name of the command. Returns a reference to a Brigadier struct.
func (*Brigadier) Literal ¶
func (*Brigadier) Literal(command string) *BrigadierCommand
Creates a new command with the prefix supplied. Returns a BrigadierCommand which you will use to make the command.
func (*Brigadier) Register ¶
func (b *Brigadier) Register(commands ...*BrigadierCommand)
Registers command(s) into this Brigadier instance
type BrigadierArgumentDefinition ¶
type BrigadierArgumentDefinition struct {
// contains filtered or unexported fields
}
Definition for an argument. Must be made with any of the argument helpers, such as BrigadierCommand.String or BrigadierCommand.Number.
type BrigadierCommand ¶
type BrigadierCommand struct {
// contains filtered or unexported fields
}
A registered Brigadier Command. Must be made with Brigadier.Literal.
func (*BrigadierCommand) Boolean ¶
func (cmd *BrigadierCommand) Boolean(arg_name string) *BrigadierCommand
Defines a boolean argument with the supplied name.
func (*BrigadierCommand) Executes ¶
func (cmd *BrigadierCommand) Executes(fn func(*BrigadierInvocation)) *BrigadierCommand
Sets the function that will be ran once the command is triggered.
func (*BrigadierCommand) Number ¶
func (cmd *BrigadierCommand) Number(arg_name string) *BrigadierCommand
Defines a number argument with the supplied name.
func (*BrigadierCommand) String ¶
func (cmd *BrigadierCommand) String(arg_name string) *BrigadierCommand
Defines a string argument with the supplied name.
func (*BrigadierCommand) Then ¶
func (cmd *BrigadierCommand) Then(commands ...*BrigadierCommand) *BrigadierCommand
type BrigadierInvocation ¶
type BrigadierInvocation struct {
User *ChatboxIngameUser
OwnerOnly bool
// contains filtered or unexported fields
}
The invocation of a Brigadier command.
func (*BrigadierInvocation) Error ¶
func (ev *BrigadierInvocation) Error(message string)
Replies to the uesr with an error. The message is prepended with "Error: ". Your message has to be in formatting mode, and is by default red.
func (*BrigadierInvocation) ReadBoolean ¶
func (ev *BrigadierInvocation) ReadBoolean(arg_name string) bool
Function to read a boolean defined with the BrigadierCommand.Boolean function. Can panic if you are attempting to read a non-existing argument.
func (*BrigadierInvocation) ReadNumber ¶
func (ev *BrigadierInvocation) ReadNumber(arg_name string) int
Function to read a number defined with the BrigadierCommand.Number function. Can panic if you are attempting to read a non-existing argument.
func (*BrigadierInvocation) ReadString ¶
func (ev *BrigadierInvocation) ReadString(arg_name string) string
Function to read a string defined with the [BrigadierCommand.String function. Can panic if you are attempting to read a non-existing argument.
func (*BrigadierInvocation) Reply ¶
func (ev *BrigadierInvocation) Reply(message string)
Replies to the user with the supplied message, in format mode. Use BrigadierInvocation.ReplyMarkdown to reply with markdown mode.
func (*BrigadierInvocation) ReplyMarkdown ¶
func (ev *BrigadierInvocation) ReplyMarkdown(message string)
Replies to the user with the supplied message, in markdown mode. Use BrigadierInvocation.Reply to reply with format mode.
type Chatbox ¶
type Chatbox struct {
Conn *websocket.Conn
OnRaw func(int, []byte)
OnCommand func(ChatboxCommandPacket)
// contains filtered or unexported fields
}
func NewChatbox ¶
func NewChatbox(opts NewChatboxOptions) *Chatbox
type ChatboxCommandPacket ¶
type ChatboxCommandPacket struct {
Event string `json:"event"`
User ChatboxIngameUser `json:"user"`
Command string `json:"command"`
Args []string `json:"args"`
OwnerOnly bool `json:"ownerOnly"`
}
type ChatboxDiscordRole ¶
type ChatboxDiscordUser ¶
type ChatboxDiscordUser struct {
Type string `json:"type"`
Id uint64 `json:"id"`
Name string `json:"name"`
DisplayName string `json:"displayName"`
Discriminator uint16 `json:"discriminator"`
Avatar string `json:"avatar"`
Roles []*ChatboxDiscordRole `json:"roles"`
LinkedUser *ChatboxIngameUser `json:"linkedUser"`
}
type ChatboxGenericEventPacket ¶
type ChatboxGenericEventPacket struct {
Event string `json:"event"`
}
type ChatboxIngameUser ¶
type ChatboxIngameUser struct {
Type string `json:"type"`
Name string `json:"name"`
Uuid string `json:"uuid"`
DisplayName string `json:"displayName"`
Group string `json:"group"`
Pronouns string `json:"pronouns"`
World string `json:"world"`
Afk bool `json:"afk"`
Alt bool `json:"alt"`
Bot bool `json:"bot"`
Supporter uint8 `json:"supporter"`
LinkedUser *ChatboxDiscordUser `json:"linkedUser"`
}
type ChatboxTellPacket ¶
type DeathsLeaderboard ¶
type DeathsLeaderboard []struct {
Uuid string `json:"uuid"`
Name string `json:"name"`
Count int `json:"count"`
}
func GetDeathsLeaderboard ¶
func GetDeathsLeaderboard() (DeathsLeaderboard, error)
Fetches the leaderboard of most deaths.
Returns an array of players along with the death count. The array is sorted in descending order by most deaths.
Example ¶
deaths, err := GetDeathsLeaderboard()
if err != nil {
log.Fatalln(err)
}
fmt.Printf("%s has most deaths, with %d deaths", deaths[0].Name, deaths[0].Count)
type NewChatboxOptions ¶
type PlayTimeLeaderboard ¶
type PlayTimeLeaderboard struct {
UpdatedAt *time.Time
Entries []struct {
Uuid string `json:"uuid"`
Username string `json:"name"`
Seconds int `json:"time"`
}
}
func GetPlaytimeLeaderboard ¶
func GetPlaytimeLeaderboard() (*PlayTimeLeaderboard, error)
Fetches the leaderboard of who has been the most active player. Players are able to opt-out of this leaderboard. Sorted in descending order.
Example ¶
leaderboard, err := GetPlaytimeLeaderboard()
if err != nil {
log.Fatalln(err)
}
for idx, player := range leaderboard.Entries {
log.Printf("#%d: %s with %.0f hours.", idx+1, player.Username, float64(player.Seconds/60/60))
}
type PlayerCountsResponse ¶
func GetPlayerCounts ¶
func GetPlayerCounts() (*PlayerCountsResponse, error)
Fetches the current player counts from the API. If successful, it returns the response, otherwise it returns the error.
Example ¶
counts, err := GetPlayerCounts()
if err != nil {
log.Fatalln(err)
}
fmt.Printf("There are currently %d players online.", counts.Total)
type SupporterGoal ¶
type SupporterGoal struct {
SupporterUrl string `json:"supporterUrl"`
Current float64 `json:"current"`
Goal float64 `json:"goal"`
GoalMet bool `json:"goalMet"`
}
func GetSupporterGoal ¶
func GetSupporterGoal() (*SupporterGoal, error)
Fetches information about the supporter goal
Assuming success, the following information is returned:
- SupporterUrl is a string containing the URL to support SwitchCraft
- Current is a float of the current donated money this month, in dollars
- Goal is a float of the supporter goal, in dollars
- GoalMet reports whether the goal has been met
In the case that something fails, the first return value is nil and the second is the error
Example ¶
goal, err := GetSupporterGoal()
if err != nil {
log.Fatalln(err)
}
if !goal.GoalMet {
fmt.Printf("The supporter goal has not been reached this month. Consider supporting! %f has been donated so far this month, out of the %f required to operate.", goal.Current, goal.Goal)
}
type TpsResponse ¶
type TpsResponse struct {
AverageTps float32 `json:"tps"`
AverageMillisecondPerTick float32 `json:"avgMsPerTick"`
MillisecondsLastTick float32 `json:"lastMsPerTick"`
}
func GetTps ¶
func GetTps() (*TpsResponse, error)
Fetches information regarding ticks per seconds.
If successful, it returns a variety of statistics:
- The average ticks per second, averaged over the last 100 ticks
- The time per tick, in milliseconds, averaged over the last 100 ticks
- The time per tick, in milliseconds, for the last tick
If the request failed, it will return nil, and the the error.
Example ¶
tpsData, err := GetTps()
if err != nil {
log.Fatalln(err)
}
fmt.Printf("Average TPS: %f", tpsData.AverageTps)