Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( Client *slash.Client Commands = make([]*slash.CreateApplicationCommand, 0) Responses = make([]slash.CommandHandleFunc, 0) )
View Source
var NameHistoryCommand = &slash.CreateApplicationCommand{ Name: "name-history", Description: "Get a player's name history (optionally starting at a specific time)", Options: []*slash.ApplicationCommandOption{ { Name: "player", Description: "Minecraft username", Required: true, Type: slash.StringACOT, }, { Name: "at", Description: "Timestamp", Type: slash.IntegerACOT, }, }, }
View Source
var NameHistoryResponse = func(interaction *slash.Interaction) (*slash.InteractionResponse, error) { username := interaction.Data.Options[0].ValueString() at := time.Unix(0, 0) if len(interaction.Data.Options) > 1 { at = time.Unix(int64(interaction.Data.Options[1].ValueInt()), 0) } resp, err := gojangClient.Profile(username, at) if err != nil { return nil, err } names, err := gojangClient.UUIDToNameHistory(resp.UUID) if err != nil { return nil, err } // Response var history string for _, name := range names { cleaned := strings.NewReplacer("_", "\\_", "*", "\\*").Replace(name.Name) history += fmt.Sprintf("\n%s", cleaned) if name.ChangedToAt == 0 { history += " (original)" } else { history += fmt.Sprintf(" (%s)", name.ChangedToAtTime().Format("01/02/2006")) } } e := &embed.Embed{ Color: 0x7ed321, Thumbnail: &embed.Thumbnail{ URL: fmt.Sprintf("https://minotar.net/helm/%s/100.png", names.Current().Name), }, Fields: []*embed.Field{ { Name: fmt.Sprintf("%s's Name History", username), Value: history, }, }, } return &slash.InteractionResponse{ Type: slash.ChannelMessageWithSourceIRT, Data: &slash.InteractionApplicationCommandCallbackData{ Embeds: []*embed.Embed{ e, }, }, }, nil }
View Source
var StatusCommand = &slash.CreateApplicationCommand{ Name: "status", Description: "Get a server's status via ping or query", Options: []*slash.ApplicationCommandOption{ { Name: "address", Description: "Server address", Required: true, Type: slash.StringACOT, }, { Name: "port", Description: "Port", Type: slash.IntegerACOT, }, }, }
View Source
var StatusResponse = func(interaction *slash.Interaction) (*slash.InteractionResponse, error) { address := interaction.Data.Options[0].ValueString() port := 25565 if len(interaction.Data.Options) > 1 { port = interaction.Data.Options[1].ValueInt() } go func() { var status statuser server := query.NewServer(address, port) timeout := time.Second * 5 deadline := time.Second * 5 q, err := server.Query(timeout, deadline) if err == nil { status = queryStatus{q} } else { p, err := server.Ping(timeout, deadline) if err != nil { if err := Client.EditInteractionResponse(context.Background(), interaction.Token, &webhook.WebhookEdit{ Content: fmt.Sprintf("could not query or ping server at %s:%d", address, port), }); err != nil { beaver.Error(err) return } } status = pingStatus{p} } e := &embed.Embed{ Title: fmt.Sprintf("`%s`", address), Description: status.motd(), Color: 0x7ed321, Fields: []*embed.Field{ { Name: "Version", Value: status.version(), Inline: true, }, { Name: "Players Online", Value: status.ratio(), Inline: true, }, { Name: "Players", Value: status.players(), }, }, } if err := Client.EditInteractionResponse(context.Background(), interaction.Token, &webhook.WebhookEdit{ Embeds: []*embed.Embed{ e, }, }); err != nil { beaver.Error(err) return } }() return &slash.InteractionResponse{ Type: slash.DeferredChannelMessageWithSourceIRT, }, nil }
View Source
var UUIDCommand = &slash.CreateApplicationCommand{ Name: "uuid", Description: "Get a player's UUID (optionally at a specific time)", Options: []*slash.ApplicationCommandOption{ { Name: "player", Description: "Minecraft username", Required: true, Type: slash.StringACOT, }, { Name: "at", Description: "Timestamp", Type: slash.IntegerACOT, }, }, }
View Source
var UUIDResponse = func(interaction *slash.Interaction) (*slash.InteractionResponse, error) { username := interaction.Data.Options[0].ValueString() at := time.Unix(0, 0) if len(interaction.Data.Options) > 1 { at = time.Unix(int64(interaction.Data.Options[1].ValueInt()), 0) } profile, err := gojangClient.Profile(username, at) if err != nil { return nil, err } e := &embed.Embed{ Color: 0x7ed321, Thumbnail: &embed.Thumbnail{ URL: fmt.Sprintf("https://minotar.net/helm/%s/100.png", profile.CurrentUsername), }, Fields: []*embed.Field{ { Name: fmt.Sprintf("%s's UUID", username), Value: profile.UUID, }, }, } return &slash.InteractionResponse{ Type: slash.ChannelMessageWithSourceIRT, Data: &slash.InteractionApplicationCommandCallbackData{ Embeds: []*embed.Embed{ e, }, }, }, nil }
Functions ¶
This section is empty.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.