Documentation
¶
Index ¶
- Variables
- type ApplicationCommandEvent
- func (e *ApplicationCommandEvent) CustomID() string
- func (e *ApplicationCommandEvent) Message() *discord.Message
- func (e *ApplicationCommandEvent) Modal(discord.ModalCreate) error
- func (e *ApplicationCommandEvent) ModalData() ModalData
- func (e *ApplicationCommandEvent) SetMessage(message *discord.Message)
- func (e *ApplicationCommandEvent) UpdateMessage(_ discord.MessageUpdate, _ ...rest.RequestOpt) error
- type CommonEvent
- type ComponentEvent
- func (e *ComponentEvent) CustomID() string
- func (e *ComponentEvent) Message() *discord.Message
- func (e *ComponentEvent) Modal(modal discord.ModalCreate) error
- func (e *ComponentEvent) ModalData() ModalData
- func (e *ComponentEvent) SetMessage(message *discord.Message)
- func (e *ComponentEvent) UpdateMessage(messageUpdate discord.MessageUpdate, opts ...rest.RequestOpt) error
- type Context
- func (c *Context) Cancel(content string)
- func (c *Context) Clear(content string)
- func (c *Context) ClearComponents(content string)
- func (c *Context) Context() context.Context
- func (c *Context) Error(content string)
- func (c *Context) Event() CommonEvent
- func (c *Context) Modal(modal *discord.ModalCreateBuilder)
- func (c *Context) NavigateBack(content string)
- func (c *Context) Reload(content string)
- func (c *Context) RespondWithFiles(content string, files ...*discord.File)
- func (c *Context) Show(pageName, content string)
- func (c *Context) UpdatePage(pageName string)
- func (c *Context) WithContext(ctx context.Context) *Context
- func (c *Context) WithValue(key, val any) *Context
- type DownloadResult
- type ImageStreamer
- type Manager
- func (m *Manager) AddPages(pages []*Page)
- func (m *Manager) Display(event CommonEvent, s *session.Session, page *Page, content string, ...)
- func (m *Manager) GetPage(name string) *Page
- func (m *Manager) HandleInteraction(event CommonEvent, s *session.Session)
- func (m *Manager) RespondWithClear(event CommonEvent, message string)
- func (m *Manager) RespondWithError(event CommonEvent, message string)
- func (m *Manager) Show(event CommonEvent, s *session.Session, pageName, content string)
- func (m *Manager) UpdatePage(s *session.Session, newPage *Page)
- type ModalData
- type ModalSubmitEvent
- func (e *ModalSubmitEvent) CustomID() string
- func (e *ModalSubmitEvent) Message() *discord.Message
- func (e *ModalSubmitEvent) Modal(discord.ModalCreate) error
- func (e *ModalSubmitEvent) ModalData() ModalData
- func (e *ModalSubmitEvent) SetMessage(message *discord.Message)
- func (e *ModalSubmitEvent) UpdateMessage(messageUpdate discord.MessageUpdate, opts ...rest.RequestOpt) error
- type Page
- type StreamRequest
Constants ¶
This section is empty.
Variables ¶
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 (e *ApplicationCommandEvent) Modal(discord.ModalCreate) error
func (*ApplicationCommandEvent) ModalData ¶
func (e *ApplicationCommandEvent) ModalData() ModalData
func (*ApplicationCommandEvent) SetMessage ¶
func (e *ApplicationCommandEvent) SetMessage(message *discord.Message)
func (*ApplicationCommandEvent) UpdateMessage ¶
func (e *ApplicationCommandEvent) UpdateMessage(_ discord.MessageUpdate, _ ...rest.RequestOpt) error
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.
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 ¶
Cancel stops the loading of the new page in the session and refreshes with a new message.
func (*Context) Clear ¶
Clear updates the interaction response with a message and clears the files and components.
func (*Context) ClearComponents ¶
ClearComponents updates the interaction response with a message and clears the components.
func (*Context) Context ¶
Context returns the standard context.Context associated with this context.
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 ¶
NavigateBack navigates back to the previous page in the history.
func (*Context) RespondWithFiles ¶
RespondWithFiles updates the interaction response with a message and file attachments.
func (*Context) Show ¶
Show updates the Discord message with new content and components for the target page.
func (*Context) UpdatePage ¶
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 ¶
WithContext returns a copy of the Context with the given context.Context as parent.
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 ¶
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 ¶
NewManager initializes a new pagination manager.
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 ¶
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.
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 (e *ModalSubmitEvent) Modal(discord.ModalCreate) error
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.