discord

package
v0.7.5 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2024 License: MIT Imports: 26 Imported by: 5

Documentation

Index

Constants

View Source
const (
	ApplicationCommandInteraction interactionType = 2
	MessageComponentInteraction   interactionType = 3
)
View Source
const (
	PrimaryButton   buttonStyle = 1
	SecondaryButton buttonStyle = 2
	DangerButton    buttonStyle = 4
)
View Source
const (
	ActionRowType componentType = 1
)
View Source
const (
	EphemeralMessage int = 1 << 6
)

Variables

This section is empty.

Functions

func IsRetryable added in v0.6.0

func IsRetryable(ctx context.Context, resp *http.Response) bool

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"`
}

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
}

type Author

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

func NewAuthor

func NewAuthor(name, url string) *Author

type Channel added in v0.6.0

type Channel struct {
	ID   string `json:"id"`
	Name string `json:"name"`
}

func Channels added in v0.6.0

func Channels(ctx context.Context, req request.Request, guild Guild) ([]Channel, error)

type Command

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

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"`
}

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"`
}

func NewButton

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

type Config

type Config struct {
	ApplicationID string
	PublicKey     string
	ClientID      string
	ClientSecret  string
	BotToken      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"`
}

func (Embed) SetColor

func (e Embed) SetColor(color int) Embed

type Field

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

func NewField

func NewField(name, value string) Field

type Guild added in v0.6.0

type Guild struct {
	ID   string `json:"id"`
	Name string `json:"name"`
}

func Guilds added in v0.6.0

func Guilds(ctx context.Context, req request.Request) ([]Guild, error)

type Image

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

func NewImage

func NewImage(url string) *Image

type InteractionCallbackType

type InteractionCallbackType uint
const (
	ChannelMessageWithSource         InteractionCallbackType = 4
	DeferredChannelMessageWithSource InteractionCallbackType = 5
	DeferredUpdateMessage            InteractionCallbackType = 6
	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"`
}

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"`
}

type InteractionResponse

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

func AsyncResponse

func AsyncResponse(replace, ephemeral bool) InteractionResponse

func NewEphemeral

func NewEphemeral(replace bool, content string) InteractionResponse

func NewError

func NewError(replace bool, err error) InteractionResponse

func NewReplace added in v0.5.0

func NewReplace(content string) InteractionResponse

func NewResponse

func NewResponse(iType InteractionCallbackType, content string) InteractionResponse

func (InteractionResponse) AddAttachment

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

func (InteractionResponse) AddComponent added in v0.0.3

func (i InteractionResponse) AddComponent(component Component) InteractionResponse

func (InteractionResponse) AddEmbed

func (i InteractionResponse) AddEmbed(embed Embed) InteractionResponse

func (InteractionResponse) Ephemeral

type Member

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

type Message added in v0.6.0

type Message struct {
	ID        string    `json:"id"`
	ChannelID string    `json:"channel_id"`
	Timestamp time.Time `json:"timestamp"`
	Author    User      `json:"author"`
	Content   string    `json:"content"`
	Embeds    []Embed   `json:"Embeds"`
}

func (Message) String added in v0.6.0

func (m Message) String() string

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

func (Service) DeleteMessage added in v0.6.0

func (s Service) DeleteMessage(ctx context.Context, req request.Request, message Message) error

func (Service) Messages added in v0.6.0

func (s Service) Messages(ctx context.Context, req request.Request, channelID string, output chan<- Message) error

func (Service) NewServeMux added in v0.4.7

func (s Service) NewServeMux() *http.ServeMux

func (Service) SigninClient added in v0.6.0

func (s Service) SigninClient(ctx context.Context, scopes ...string) (request.Request, error)

type User added in v0.6.0

type User struct {
	ID       string `json:"id"`
	Username string `json:"username"`
	Bot      bool   `json:"bot"`
}

func CurrentUser added in v0.7.0

func CurrentUser(ctx context.Context, req request.Request) (User, error)

Jump to

Keyboard shortcuts

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