discord

package
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2024 License: MIT Imports: 26 Imported by: 1

Documentation

Index

Constants

View Source
const (

	// ApplicationCommandInteraction occurs when user enter a slash command
	ApplicationCommandInteraction interactionType = 2
	// MessageComponentInteraction occurs when user interact with an action
	MessageComponentInteraction interactionType = 3
)
View Source
const (
	// PrimaryButton is green
	PrimaryButton buttonStyle = 1
	// SecondaryButton is grey
	SecondaryButton buttonStyle = 2
	// DangerButton is red
	DangerButton buttonStyle = 4
)
View Source
const (
	// ActionRowType for row
	ActionRowType componentType = 1
)
View Source
const (
	// EphemeralMessage int value
	EphemeralMessage int = 1 << 6
)

Variables

This section is empty.

Functions

func RestoreCustomID added in v0.2.1

func RestoreCustomID(ctx context.Context, redisApp redis.Client, prefix, customID string, statics []string) (url.Values, error)

func SaveCustomID added in v0.2.1

func SaveCustomID(ctx context.Context, redisApp redis.Client, prefix string, values url.Values) (string, error)

Types

type AllowedMentions

type AllowedMentions struct {
	Parse []string `json:"parse"`
}

AllowedMentions list

type Attachment

type Attachment struct {
	Filename string `json:"filename"`

	ID        int   `json:"id"`
	Size      int64 `json:"size,omitempty"`
	Ephemeral bool  `json:"ephemeral,omitempty"`
	// contains filtered or unexported fields
}

Attachment for file upload

type Author

type Author struct {
	Name string `json:"name"`
	URL  string `json:"url,omitempty"`
}

Author content

func NewAuthor

func NewAuthor(name, url string) *Author

NewAuthor create an author

type Command

type Command struct {
	Name        string          `json:"name,omitempty"`
	Description string          `json:"description,omitempty"`
	Options     []CommandOption `json:"options,omitempty"`
	Guilds      []string        `json:"-"`
}

Command configuration

type CommandOption

type CommandOption struct {
	Name        string `json:"name,omitempty"`
	Description string `json:"description,omitempty"`
	Value       string `json:"value,omitempty"`
	Type        int    `json:"type,omitempty"`
	Required    bool   `json:"required,omitempty"`
}

CommandOption configuration option

type Component

type Component struct {
	Label      string        `json:"label,omitempty"`
	CustomID   string        `json:"custom_id,omitempty"`
	Components []Component   `json:"components,omitempty"`
	Type       componentType `json:"type,omitempty"`
	Style      buttonStyle   `json:"style,omitempty"`
}

Component describes an interactive component

func NewButton

func NewButton(style buttonStyle, label, customID string) Component

NewButton creates a new button

type Config

type Config struct {
	ApplicationID string
	PublicKey     string
	ClientID      string
	ClientSecret  string
}

func Flags

func Flags(fs *flag.FlagSet, prefix string, overrides ...flags.Override) *Config

type Embed

type Embed struct {
	Thumbnail   *Image  `json:"thumbnail,omitempty"`
	Image       *Image  `json:"image,omitempty"`
	Author      *Author `json:"author,omitempty"`
	Title       string  `json:"title,omitempty"`
	Description string  `json:"description,omitempty"`
	URL         string  `json:"url,omitempty"`
	Fields      []Field `json:"fields,omitempty"`
	Color       int     `json:"color,omitempty"`
}

Embed of content

func (Embed) SetColor

func (e Embed) SetColor(color int) Embed

SetColor define color of embed

type Field

type Field struct {
	Name   string `json:"name"`
	Value  string `json:"value"`
	Inline bool   `json:"inline,omitempty"`
}

Field for embed

func NewField

func NewField(name, value string) Field

NewField creates new field

type Image

type Image struct {
	URL string `json:"url"`
}

Image content

func NewImage

func NewImage(url string) *Image

NewImage create an image

type InteractionCallbackType

type InteractionCallbackType uint

InteractionCallbackType defines types of possible answer

const (

	// ChannelMessageWithSource answer
	ChannelMessageWithSource InteractionCallbackType = 4
	// DeferredChannelMessageWithSource deferred answer
	DeferredChannelMessageWithSource InteractionCallbackType = 5
	// DeferredUpdateMessage deferred in-place
	DeferredUpdateMessage InteractionCallbackType = 6
	// UpdateMessageCallback in place
	UpdateMessageCallback InteractionCallbackType = 7
)

type InteractionDataResponse

type InteractionDataResponse struct {
	Content         string          `json:"content,omitempty"`
	AllowedMentions AllowedMentions `json:"allowed_mentions"`
	Embeds          []Embed         `json:"embeds"`      // no `omitempty` to pass empty array when cleared
	Components      []Component     `json:"components"`  // no `omitempty` to pass empty array when cleared
	Attachments     []Attachment    `json:"attachments"` // no `omitempty` to pass empty array when cleared
	Flags           int             `json:"flags"`
}

InteractionDataResponse for responding to user

func NewDataResponse added in v0.0.3

func NewDataResponse(content string) InteractionDataResponse

NewDataResponse create a data response

func (InteractionDataResponse) AddEmbed added in v0.0.3

AddEmbed add given embed to response

type InteractionRequest

type InteractionRequest struct {
	Member        Member `json:"member"`
	ID            string `json:"id"`
	GuildID       string `json:"guild_id"`
	Token         string `json:"token"`
	ApplicationID string `json:"application_id"`
	Message       struct {
		Interaction struct {
			Name string `json:"name"`
		} `json:"interaction"`
	} `json:"message"`
	Data struct {
		Name     string          `json:"name"`
		CustomID string          `json:"custom_id"`
		Options  []CommandOption `json:"options"`
	} `json:"data"`
	Type interactionType `json:"type"`
}

InteractionRequest when user perform an action

type InteractionResponse

type InteractionResponse struct {
	Data InteractionDataResponse `json:"data,omitempty"`
	Type InteractionCallbackType `json:"type,omitempty"`
}

InteractionResponse for responding to user

func AsyncResponse

func AsyncResponse(replace, ephemeral bool) InteractionResponse

AsyncResponse to the user

func NewEphemeral

func NewEphemeral(replace bool, content string) InteractionResponse

NewEphemeral creates an ephemeral response

func NewError

func NewError(replace bool, err error) InteractionResponse

NewError creates an error response

func NewResponse

func NewResponse(iType InteractionCallbackType, content string) InteractionResponse

NewResponse creates a response

func (InteractionResponse) AddAttachment

func (i InteractionResponse) AddAttachment(filename, filepath string, size int64) InteractionResponse

AddAttachment add given attachment to response

func (InteractionResponse) AddComponent added in v0.0.3

func (i InteractionResponse) AddComponent(component Component) InteractionResponse

AddComponent add given component to response

func (InteractionResponse) AddEmbed

func (i InteractionResponse) AddEmbed(embed Embed) InteractionResponse

AddEmbed add given embed to response

func (InteractionResponse) Ephemeral

Ephemeral set response to ephemeral

type Member

type Member struct {
	User struct {
		ID       string `json:"id,omitempty"`
		Username string `json:"username,omitempty"`
	} `json:"user,omitempty"`
}

Member of discord

type OnMessage

OnMessage handle message event

type Service added in v0.3.2

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

func New

func New(config *Config, website string, handler OnMessage, tracerProvider trace.TracerProvider) (Service, error)

func (Service) ConfigureCommands added in v0.3.2

func (s Service) ConfigureCommands(ctx context.Context, commands map[string]Command) error

ConfigureCommands with the API

func (Service) Handler added in v0.3.2

func (s Service) Handler() http.Handler

Jump to

Keyboard shortcuts

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