slash

package
Version: v0.1.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 18, 2021 License: MIT Imports: 14 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Handler

func Handler(key string, commands []*Command) (http.Handler, error)

Handler returns an http.Handler capable of responding to slash commands

Types

type ApplicationCommand

type ApplicationCommand struct {
	ID            string `json:"id"`
	ApplicationID string `json:"application_id"`
	CreateApplicationCommand
}

ApplicationCommand https://discord.com/developers/docs/interactions/slash-commands#applicationcommand

type ApplicationCommandInteractionData

type ApplicationCommandInteractionData struct {
	ID      string                                     `json:"id"`
	Name    string                                     `json:"name"`
	Options []*ApplicationCommandInteractionDataOption `json:"options"`
}

ApplicationCommandInteractionData https://discord.com/developers/docs/interactions/slash-commands#interaction-applicationcommandinteractiondata

type ApplicationCommandInteractionDataOption

type ApplicationCommandInteractionDataOption struct {
	Name    string                                     `json:"name"`
	Value   interface{}                                `json:"value"`
	Options []*ApplicationCommandInteractionDataOption `json:"options"`
}

ApplicationCommandInteractionDataOption https://discord.com/developers/docs/interactions/slash-commands#interaction-applicationcommandinteractiondataoption

func (ApplicationCommandInteractionDataOption) ValueBool

ValueBool returns the boolean or false

func (ApplicationCommandInteractionDataOption) ValueInt

ValueInt returns the int (forced from JSON float64) or 0

func (ApplicationCommandInteractionDataOption) ValueString

ValueString returns the string or ""

type ApplicationCommandOption

type ApplicationCommandOption struct {
	Type        ApplicationCommandOptionType      `json:"type"`
	Name        string                            `json:"name"`
	Description string                            `json:"description"`
	Required    bool                              `json:"required,omitempty"`
	Choices     []*ApplicationCommandOptionChoice `json:"choices,omitempty"`
	Options     []*ApplicationCommandOption       `json:"options,omitempty"`
}

ApplicationCommandOption https://discord.com/developers/docs/interactions/slash-commands#applicationcommandoption

type ApplicationCommandOptionChoice

type ApplicationCommandOptionChoice struct {
	Name  string      `json:"name"`
	Value interface{} `json:"value"`
}

ApplicationCommandOptionChoice https://discord.com/developers/docs/interactions/slash-commands#applicationcommandoptionchoice

type ApplicationCommandOptionType

type ApplicationCommandOptionType int

ApplicationCommandOptionType (ACOT)

const (
	SubCommandACOT ApplicationCommandOptionType = iota + 1
	SubCommandGroupACOT
	StringACOT
	IntegerACOT
	BooleanACOT
	UserACOT
	ChannelACOT
	RoleACOT
)

https://discord.com/developers/docs/interactions/slash-commands#applicationcommandoptiontype

type CallbackFlags

type CallbackFlags int

CallbackFlags (CF)

const (
	NoneCF      CallbackFlags = 0
	EphemeralCF CallbackFlags = 64
)

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is a slash client

func NewClient

func NewClient(clientID, clientSecret string, opts ...ClientOption) *Client

NewClient creates a new Client for working with slash commands

func (*Client) BulkOverwriteGlobalApplicationCommands

func (c *Client) BulkOverwriteGlobalApplicationCommands(ctx context.Context, cmd []*CreateApplicationCommand) ([]*ApplicationCommand, error)

BulkOverwriteGlobalApplicationCommands bulk overwrites global slash commands

func (*Client) BulkOverwriteGuildApplicationCommands

func (c *Client) BulkOverwriteGuildApplicationCommands(ctx context.Context, guildID string, cmd []*CreateApplicationCommand) ([]*ApplicationCommand, error)

BulkOverwriteGuildApplicationCommands bulk overwrites slash commands for a guild

func (*Client) CreateFollowupMessage

func (c *Client) CreateFollowupMessage(ctx context.Context, interactionToken string, interaction *webhook.Webhook) error

CreateFollowupMessage creates a followup message

func (*Client) CreateGlobalApplicationCommand

func (c *Client) CreateGlobalApplicationCommand(ctx context.Context, cmd *CreateApplicationCommand) (*ApplicationCommand, error)

CreateGlobalApplicationCommand creates a global slash command

Creating a global application command is an upsert, meaning creating a command with the same name will update it rather than return an error

func (*Client) CreateGuildApplicationCommand

func (c *Client) CreateGuildApplicationCommand(ctx context.Context, guildID string, cmd *CreateApplicationCommand) (*ApplicationCommand, error)

CreateGuildApplicationCommand creates a slash command for a guild

Creating a guild application command is an upsert, meaning creating a command with the same name will update it rather than return an error

func (*Client) CreateInteractionResponse

func (c *Client) CreateInteractionResponse(ctx context.Context, interactionID, interactionToken string, interaction *InteractionResponse) error

CreateInteractionResponse creates an interaction response

func (*Client) DeleteFollowupMessage

func (c *Client) DeleteFollowupMessage(ctx context.Context, interactionToken, messageID string) error

DeleteFollowupMessage deletes a followup message

func (*Client) DeleteGlobalApplicationCommand

func (c *Client) DeleteGlobalApplicationCommand(ctx context.Context, cmdID string) error

DeleteGlobalApplicationCommand deletes a global slash command

func (*Client) DeleteGuildApplicationCommand

func (c *Client) DeleteGuildApplicationCommand(ctx context.Context, guildID, cmdID string) error

DeleteGuildApplicationCommand deletes a slash command for a guild

func (*Client) DeleteInteractionResponse

func (c *Client) DeleteInteractionResponse(ctx context.Context, interactionToken string) error

DeleteInteractionResponse deletes an interaction response

func (*Client) EditFollowupMessage

func (c *Client) EditFollowupMessage(ctx context.Context, interactionToken, messageID string, interaction *webhook.WebhookEdit) error

EditFollowupMessage edits a followup message

func (*Client) EditInteractionResponse

func (c *Client) EditInteractionResponse(ctx context.Context, interactionToken string, interaction *webhook.WebhookEdit) error

EditInteractionResponse edits an interaction response

func (*Client) GetGlobalApplicationCommand

func (c *Client) GetGlobalApplicationCommand(ctx context.Context, cmdID string) (*ApplicationCommand, error)

GetGlobalApplicationCommand gets a global slash command by its ID

func (*Client) GetGlobalApplicationCommands

func (c *Client) GetGlobalApplicationCommands(ctx context.Context) ([]*ApplicationCommand, error)

GetGlobalApplicationCommands gets all global slash commands

func (*Client) GetGuildApplicationCommand

func (c *Client) GetGuildApplicationCommand(ctx context.Context, guildID, cmdID string) (*ApplicationCommand, error)

GetGuildApplicationCommand gets a slash command for a guild by its ID

func (*Client) GetGuildApplicationCommands

func (c *Client) GetGuildApplicationCommands(ctx context.Context, guildID string) ([]*ApplicationCommand, error)

GetGuildApplicationCommands gets all slash commands for a guild

func (*Client) OAuthURL

func (c *Client) OAuthURL() string

OAuthURL returns a URL suitable for giving an app slash command scope

func (*Client) UpdateGlobalApplicationCommand

func (c *Client) UpdateGlobalApplicationCommand(ctx context.Context, cmdID string, cmd *CreateApplicationCommand) (*ApplicationCommand, error)

UpdateGlobalApplicationCommand updates a global slash command

func (*Client) UpdateGuildApplicationCommand

func (c *Client) UpdateGuildApplicationCommand(ctx context.Context, guildID, cmdID string, cmd *CreateApplicationCommand) (*ApplicationCommand, error)

UpdateGuildApplicationCommand updates a slash command for a guild

type ClientOption

type ClientOption func(*Client)

ClientOption is options for a Client

func WithHTTP

func WithHTTP(client *http.Client) ClientOption

WithHTTP sets the http.Client for a Client

type Command

type Command struct {
	ID     string
	Handle CommandHandleFunc
}

Command is used when creating a Handler

ID should map to a corresponding ApplicationCommand Handle is the func to be called whenever the Handler receives a request for the ApplicationCommand

type CommandHandleFunc

type CommandHandleFunc func(*Interaction) (*InteractionResponse, error)

CommandHandleFunc is a func for Command.Handle

type CreateApplicationCommand

type CreateApplicationCommand struct {
	Name        string                      `json:"name"`
	Description string                      `json:"description"`
	Options     []*ApplicationCommandOption `json:"options,omitempty"`
}

CreateApplicationCommand https://discord.com/developers/docs/interactions/slash-commands#applicationcommand

type Interaction

type Interaction struct {
	ID        string                             `json:"id"`
	Type      InteractionType                    `json:"type"`
	Data      *ApplicationCommandInteractionData `json:"data"`
	GuildID   string                             `json:"guild_id"`
	ChannelID string                             `json:"channel_id"`
	Member    *Member                            `json:"member"`
	User      *User                              `json:"user"`
	Token     string                             `json:"token"`
	Version   int                                `json:"version"`
}

https://discord.com/developers/docs/interactions/slash-commands#interaction

type InteractionApplicationCommandCallbackData

type InteractionApplicationCommandCallbackData struct {
	TTS             bool                   `json:"tts"`
	Content         string                 `json:"content"`
	Embeds          []*embed.Embed         `json:"embeds"`
	AllowedMentions *embed.AllowedMentions `json:"allowed_mentions"`
	Flags           CallbackFlags          `json:"flags"`
}

InteractionApplicationCommandCallbackData https://discord.com/developers/docs/interactions/slash-commands#interaction-response-interactionapplicationcommandcallbackdata

type InteractionResponse

type InteractionResponse struct {
	Type InteractionResponseType                    `json:"type"`
	Data *InteractionApplicationCommandCallbackData `json:"data"`
}

InteractionResponse https://discord.com/developers/docs/interactions/slash-commands#interaction-response

type InteractionResponseType

type InteractionResponseType int

InteractionResponseType (IRT)

const (
	PongIRT InteractionResponseType = iota + 1

	ChannelMessageWithSourceIRT
	DeferredChannelMessageWithSourceIRT
)

https://discord.com/developers/docs/interactions/slash-commands#interaction-response-interactionresponsetype

type InteractionType

type InteractionType int

InteractionType (IT)

type Member

type Member struct {
	User         *User    `json:"user"`
	Nick         string   `json:"nick"`
	Roles        []string `json:"roles"`
	JoinedAt     string   `json:"joined_at"`
	PremiumSince string   `json:"premium_since"`
	Deaf         bool     `json:"deaf"`
	Mute         bool     `json:"mute"`
	Pending      bool     `json:"pending"`
	Permissions  string   `json:"permissions"`
}

Member https://discord.com/developers/docs/resources/guild#guild-member-object

type PremiumType

type PremiumType int

PremiumType (PT)

type User

type User struct {
	ID            string      `json:"id"`
	Username      string      `json:"username"`
	Discriminator string      `json:"discriminator"`
	Avatar        string      `json:"avatar"`
	Bot           bool        `json:"bot"`
	System        bool        `json:"system"`
	MFAEnabled    bool        `json:"mfa_enabled"`
	Locale        string      `json:"locale"`
	Verified      bool        `json:"verified"`
	Email         string      `json:"email"`
	Flags         UserFlags   `json:"flags"`
	PremiumType   PremiumType `json:"premium_type"`
	PublicFlags   UserFlags   `json:"public_flags"`
}

User https://discord.com/developers/docs/resources/user#user-object

type UserFlags

type UserFlags int

UserFlags (UF)

const (
	NoneUF            UserFlags = 0
	DiscordEmployeeUF UserFlags = 1 << iota
	PartneredServerOwnerUF
	HypeSquadEventsUF
	BugHunterLevel1UF

	HouseBraveryUF
	HouseBrillianceUF
	HouseBalanceUF
	EarlySupporterUF
	TeamUserUF

	SystemUF

	BugHunterLevel2UF

	VerifiedBotUF
	EarlyVerifiedBotDeveloperUF
)

https://discord.com/developers/docs/resources/user#user-object-user-flags

func (UserFlags) Has

func (u UserFlags) Has(f UserFlags) bool

Has checks for a specific UserFlags

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL