interaction

package
v0.0.0-...-1ceee6a Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2021 License: Unlicense Imports: 7 Imported by: 0

Documentation

Overview

Package interaction provides types for handling Discord webhook interactions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Verify

func Verify(r *http.Request, key ed25519.PublicKey) bool

Verify implements the verification side of the discord interactions api signing algorithm, as documented here: https://discord.com/developers/docs/interactions/slash-commands#security-and-authorization

Types

type Data

type Data struct {
	// Application commands only
	ID       discord.CommandID                  `json:"id"`
	Name     string                             `json:"name"`
	Type     discord.CommandType                `json:"type"`
	Resolved ResolvedData                       `json:"resolved"`
	Options  []discord.CommandInteractionOption `json:"options"`

	// Components only
	CustomID      string                `json:"custom_id"`
	ComponentType discord.ComponentType `json:"component_type"`
	// Select only
	Values []string `json:"values"`

	// User/message commands only
	TargetID discord.Snowflake `json:"target_id"`
}

Data is the interaction data.

func (Data) Message

func (d Data) Message() *discord.Message

Message gets the targeted message, if any.

func (Data) User

func (d Data) User() *discord.User

User gets the targeted user, if any.

type Interaction

type Interaction struct {
	ID      discord.InteractionID `json:"id"`
	Token   string                `json:"token"`
	Version uint                  `json:"version"`

	ApplicationID discord.AppID               `json:"application_id"`
	Type          discord.InteractionDataType `json:"type"`

	Data *Data `json:"data"`

	GuildID   discord.GuildID   `json:"guild_id"`
	ChannelID discord.ChannelID `json:"channel_id"`

	Member *discord.Member `json:"member"`
	User   *discord.User   `json:"user"`

	Message *discord.Message `json:"message"`
}

Interaction is an interaction received from Discord.

func (Interaction) GetUser

func (i Interaction) GetUser() *discord.User

GetUser gets this interaction's user, if any.

func (Interaction) UserID

func (i Interaction) UserID() discord.UserID

UserID returns the user ID of this interaction, if any.

type ResolvedData

type ResolvedData struct {
	Users    map[discord.UserID]discord.User       `json:"users"`
	Members  map[discord.UserID]discord.Member     `json:"members"`
	Roles    map[discord.RoleID]discord.Role       `json:"roles"`
	Channels map[discord.ChannelID]discord.Channel `json:"channels"`
	Messages map[discord.MessageID]discord.Message `json:"messages"`
}

ResolvedData is the resolved data for this interaction.

Jump to

Keyboard shortcuts

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