interaction

package
v0.0.0-...-f28ea8f Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2025 License: GPL-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrImageDownloadFailed = errors.New("failed to download image after 3 attempts")

Functions

This section is empty.

Types

type ApplicationCommandEvent

type ApplicationCommandEvent struct {
	*events.ApplicationCommandInteractionCreate
	// contains filtered or unexported fields
}

ApplicationCommandEvent wraps ApplicationCommandInteractionCreate.

func (*ApplicationCommandEvent) CustomID

func (e *ApplicationCommandEvent) CustomID() string

func (*ApplicationCommandEvent) Message

func (e *ApplicationCommandEvent) Message() *discord.Message

func (*ApplicationCommandEvent) Modal

func (*ApplicationCommandEvent) ModalData

func (e *ApplicationCommandEvent) ModalData() ModalData

func (*ApplicationCommandEvent) SetMessage

func (e *ApplicationCommandEvent) SetMessage(message *discord.Message)

func (*ApplicationCommandEvent) UpdateMessage

type CommonEvent

type CommonEvent interface {
	// Client returns the Discord client instance handling this event.
	Client() *bot.Client

	// ApplicationID returns the bot's application ID for API requests.
	ApplicationID() snowflake.ID

	// AppPermissions returns the permissions of the bot in the guild.
	AppPermissions() *discord.Permissions

	// Token returns the interaction token for responding to the event.
	Token() string

	// User returns the Discord user who triggered this event.
	User() discord.User

	// GuildID returns the ID of the guild where the event occurred.
	// Returns nil for direct message events.
	GuildID() *snowflake.ID

	// Member returns the member who triggered this event.
	Member() *discord.ResolvedMember

	// Modal shows a modal dialog to the user.
	// For non-ComponentInteractionCreate events, this will panic.
	Modal(discord.ModalCreate) error

	// CustomID returns the custom ID of the interaction.
	// Returns empty string for interactions without custom IDs.
	CustomID() string

	// ModalData returns modal data if this is a modal submit event.
	// Returns nil for other event types.
	ModalData() ModalData

	// UpdateMessage updates the message that triggered this event.
	UpdateMessage(messageUpdate discord.MessageUpdate, opts ...rest.RequestOpt) error

	// SetMessage sets the message that triggered this event.
	SetMessage(message *discord.Message)

	// Message returns the message that triggered this event.
	// Returns nil for events that are not associated with a message.
	Message() *discord.Message
}

CommonEvent extracts shared functionality from different Discord event types. This allows pagination to work with any interaction event without type checking.

func WrapEvent

func WrapEvent(event any, message *discord.Message) CommonEvent

WrapEvent wraps Discord events in our local event types.

type ComponentEvent

type ComponentEvent struct {
	*events.ComponentInteractionCreate
	// contains filtered or unexported fields
}

ComponentEvent wraps ComponentInteractionCreate.

func (*ComponentEvent) CustomID

func (e *ComponentEvent) CustomID() string

func (*ComponentEvent) Message

func (e *ComponentEvent) Message() *discord.Message

func (*ComponentEvent) Modal

func (e *ComponentEvent) Modal(modal discord.ModalCreate) error

func (*ComponentEvent) ModalData

func (e *ComponentEvent) ModalData() ModalData

func (*ComponentEvent) SetMessage

func (e *ComponentEvent) SetMessage(message *discord.Message)

func (*ComponentEvent) UpdateMessage

func (e *ComponentEvent) UpdateMessage(messageUpdate discord.MessageUpdate, opts ...rest.RequestOpt) error

type Context

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

Context wraps the standard context.Context and adds bot functionality.

func New

func New(ctx context.Context, event CommonEvent, session *session.Session, manager *Manager) *Context

New creates a new Context with the given parent context and bot data.

func (*Context) Cancel

func (c *Context) Cancel(content string)

Cancel stops the loading of the new page in the session and refreshes with a new message.

func (*Context) Clear

func (c *Context) Clear(content string)

Clear updates the interaction response with a message and clears the files and components.

func (*Context) ClearComponents

func (c *Context) ClearComponents(content string)

ClearComponents updates the interaction response with a message and clears the components.

func (*Context) Context

func (c *Context) Context() context.Context

Context returns the standard context.Context associated with this context.

func (*Context) Error

func (c *Context) Error(content string)

Error updates the interaction response with an error message.

func (*Context) Event

func (c *Context) Event() CommonEvent

Event returns the Discord event associated with this context.

func (*Context) Modal

func (c *Context) Modal(modal *discord.ModalCreateBuilder)

Modal updates the interaction response with a modal.

func (*Context) NavigateBack

func (c *Context) NavigateBack(content string)

NavigateBack navigates back to the previous page in the history.

func (*Context) Reload

func (c *Context) Reload(content string)

Reload reloads the page being processed with a new message.

func (*Context) RespondWithFiles

func (c *Context) RespondWithFiles(content string, files ...*discord.File)

RespondWithFiles updates the interaction response with a message and file attachments.

func (*Context) Show

func (c *Context) Show(pageName, content string)

Show updates the Discord message with new content and components for the target page.

func (*Context) UpdatePage

func (c *Context) UpdatePage(pageName string)

UpdatePage updates the session with a new page. This does not refresh or reload the page, it just updates the page in the session.

func (*Context) WithContext

func (c *Context) WithContext(ctx context.Context) *Context

WithContext returns a copy of the Context with the given context.Context as parent.

func (*Context) WithValue

func (c *Context) WithValue(key, val any) *Context

WithValue returns a copy of the Context with the given key-value pair added.

type DownloadResult

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

DownloadResult represents the result of an image download.

type ImageStreamer

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

ImageStreamer handles progressive loading and merging of images.

func NewImageStreamer

func NewImageStreamer(manager *Manager, logger *zap.Logger, client *client.Client) *ImageStreamer

NewImageStreamer creates a new ImageStreamer instance.

func (*ImageStreamer) Stream

func (is *ImageStreamer) Stream(req StreamRequest)

Stream starts the image streaming process.

type Manager

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

Manager maintains a map of pages indexed by their names and handles the routing of Discord interactions to the appropriate page handlers.

func NewManager

func NewManager(sessionManager *session.Manager, logger *zap.Logger) *Manager

NewManager initializes a new pagination manager.

func (*Manager) AddPages

func (m *Manager) AddPages(pages []*Page)

AddPages stores pages for the manager using their names as keys.

func (*Manager) Display

func (m *Manager) Display(
	event CommonEvent, s *session.Session, page *Page, content string, files ...*discord.File,
)

Display updates the page in the session and displays it to the user.

func (*Manager) GetPage

func (m *Manager) GetPage(name string) *Page

GetPage retrieves a page from the manager's pages using the provided name.

func (*Manager) HandleInteraction

func (m *Manager) HandleInteraction(event CommonEvent, s *session.Session)

HandleInteraction routes Discord interactions to the appropriate handler function based on the interaction type (select menu, button, or modal) and the current page. If no handler is found for an interaction, an error is logged.

func (*Manager) RespondWithClear

func (m *Manager) RespondWithClear(event CommonEvent, message string)

RespondWithClear updates the interaction response with a message. This also clears message files and container components.

func (*Manager) RespondWithError

func (m *Manager) RespondWithError(event CommonEvent, message string)

RespondWithError updates the interaction response with an error message.

func (*Manager) Show

func (m *Manager) Show(event CommonEvent, s *session.Session, pageName, content string)

Show updates the Discord message with new content and components for the target page.

func (*Manager) UpdatePage

func (m *Manager) UpdatePage(s *session.Session, newPage *Page)

UpdatePage updates the session with a new page.

type ModalData

type ModalData interface {
	// Text returns the value of a text input component with the given custom ID.
	Text(customID string) string
	// OptText returns the value of a text input component and whether it exists.
	OptText(customID string) (string, bool)
}

ModalData provides access to modal functionality.

type ModalSubmitEvent

type ModalSubmitEvent struct {
	*events.ModalSubmitInteractionCreate
	// contains filtered or unexported fields
}

ModalSubmitEvent wraps ModalSubmitInteractionCreate.

func (*ModalSubmitEvent) CustomID

func (e *ModalSubmitEvent) CustomID() string

func (*ModalSubmitEvent) Message

func (e *ModalSubmitEvent) Message() *discord.Message

func (*ModalSubmitEvent) Modal

func (*ModalSubmitEvent) ModalData

func (e *ModalSubmitEvent) ModalData() ModalData

func (*ModalSubmitEvent) SetMessage

func (e *ModalSubmitEvent) SetMessage(message *discord.Message)

func (*ModalSubmitEvent) UpdateMessage

func (e *ModalSubmitEvent) UpdateMessage(messageUpdate discord.MessageUpdate, opts ...rest.RequestOpt) error

type Page

type Page struct {
	Name                   string
	Message                func(s *session.Session) *discord.MessageUpdateBuilder
	DisableSelectMenuReset bool

	// ShowHandlerFunc is called when the page is shown.
	ShowHandlerFunc func(
		ctx *Context,
		s *session.Session,
	)

	// ResetHandlerFunc is called when the page is opened for the first time.
	ResetHandlerFunc func(
		s *session.Session,
	)
	// CleanupHandlerFunc is called when the page is closed.
	CleanupHandlerFunc func(
		s *session.Session,
	)

	// SelectHandlerFunc processes select menu interactions.
	SelectHandlerFunc func(
		ctx *Context,
		s *session.Session,
		customID,
		option string,
	)
	// ButtonHandlerFunc processes button clicks.
	ButtonHandlerFunc func(
		ctx *Context,
		s *session.Session,
		customID string,
	)
	// ModalHandlerFunc processes form submissions.
	ModalHandlerFunc func(
		ctx *Context,
		s *session.Session,
	)
}

Page holds the structure for a single interactive page, containing handlers for different types of Discord interactions (select menus, buttons, modals) and a message builder function. The handlers are optional - a page may only use some interaction types.

type StreamRequest

type StreamRequest struct {
	Event     CommonEvent
	Session   *session.Session
	Page      *Page
	URLFunc   func() []string
	Columns   int
	Rows      int
	MaxItems  int
	OnSuccess func(buf *bytes.Buffer)
}

StreamRequest contains all the parameters needed for streaming images.

Jump to

Keyboard shortcuts

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