Documentation ¶
Index ¶
- Constants
- Variables
- func EmbedsFromString(txt string, chunkLen int) []*discordgo.MessageEmbed
- type Index
- type Paginator
- func (p *Paginator) Add(embeds ...*discordgo.MessageEmbed)
- func (p *Paginator) Goto(index int) error
- func (p *Paginator) NextPage() error
- func (p *Paginator) Page() (*discordgo.MessageEmbed, error)
- func (p *Paginator) PreviousPage() error
- func (p *Paginator) Running() bool
- func (p *Paginator) SetPageFooters()
- func (p *Paginator) Spawn() error
- func (p *Paginator) Update() error
- type Sub
- type Widget
- func (w *Widget) Handle(emojiName string, handler WidgetHandler) error
- func (w *Widget) LockToUsers(userIDs ...string) error
- func (w *Widget) QueryInput(prompt string, userID string, timeout time.Duration) (*discordgo.Message, error)
- func (w *Widget) RefreshTimeout() error
- func (w *Widget) Reset(d time.Duration) error
- func (w *Widget) Running() bool
- func (w *Widget) Spawn() error
- func (w *Widget) Stop() error
- func (w *Widget) UpdateEmbed(embed *discordgo.MessageEmbed) (*discordgo.Message, error)
- type WidgetHandler
Constants ¶
const ()
emoji constants
Variables ¶
var ( ErrAlreadyRunning = errors.New("err: Widget already running") ErrIndexOutOfBounds = errors.New("err: Index is out of bounds") ErrNilMessage = errors.New("err: Message is nil") ErrNilEmbed = errors.New("err: embed is nil") ErrNotRunning = errors.New("err: not running") ErrTickerNotSet = errors.New("err: Timeout ticker is not set") )
error vars
Functions ¶
func EmbedsFromString ¶
func EmbedsFromString(txt string, chunkLen int) []*discordgo.MessageEmbed
EmbedsFromString splits a string into a slice of MessageEmbeds.
txt : text to split chunkLen: How long the text in each embed should be (if set to 0 or less, it defaults to 2048)
Types ¶
type Index ¶ added in v0.3.0
type Index struct {
// contains filtered or unexported fields
}
Index implements observer pattern for handling events on Paginator index change
func (*Index) Decr ¶ added in v0.3.0
func (i *Index) Decr()
Decr decrements index and notifies all subscribers
type Paginator ¶
type Paginator struct { sync.Mutex Pages []*discordgo.MessageEmbed Index Index // Loop back to the beginning or end when on the first or last page. Loop bool Widget *Widget Ses *discordgo.Session DeleteMessageWhenDone bool DeleteReactionsWhenDone bool ColourWhenDone int // contains filtered or unexported fields }
Paginator provides a method for creating a navigatable embed
func NewPaginator ¶
NewPaginator returns a new Paginator
ses : discordgo session channelID: channelID to spawn the paginator on
func (*Paginator) Add ¶
func (p *Paginator) Add(embeds ...*discordgo.MessageEmbed)
Add a page to the paginator
embed: embed page to add.
func (*Paginator) Goto ¶
Goto jumps to the requested page index
index: The index of the page to go to
func (*Paginator) Page ¶
func (p *Paginator) Page() (*discordgo.MessageEmbed, error)
Page returns the page of the current index
func (*Paginator) PreviousPage ¶
PreviousPage sets the current page index to the previous page.
func (*Paginator) SetPageFooters ¶
func (p *Paginator) SetPageFooters()
SetPageFooters sets the footer of each embed to Be its page number out of the total length of the embeds.
type Widget ¶
type Widget struct { sync.Mutex Embed *discordgo.MessageEmbed Message *discordgo.Message Ses *discordgo.Session ChannelID string Timeout time.Duration Close chan bool // Handlers binds emoji names to functions Handlers map[string]WidgetHandler // keys stores the handlers keys in the order they were added Keys []string // Delete reactions after they are added DeleteReactions bool // Refresh timer after action on a widget RefreshAfterAction bool // Only allow listed users to use reactions. UserWhitelist []string // contains filtered or unexported fields }
Widget is a message embed with reactions for buttons. Accepts custom handlers for reactions.
func NewWidget ¶
NewWidget returns a pointer to a Widget object
ses : discordgo session channelID: channelID to spawn the widget on
func (*Widget) Handle ¶
func (w *Widget) Handle(emojiName string, handler WidgetHandler) error
Handle adds a handler for the given emoji name
emojiName: The unicode value of the emoji handler : handler function to call when the emoji is clicked func(*Widget, *discordgo.MessageReaction)
func (*Widget) LockToUsers ¶ added in v0.2.1
LockToUsers adds defined userIDs to the UserWhitelist locking the widget to them
func (*Widget) QueryInput ¶
func (w *Widget) QueryInput(prompt string, userID string, timeout time.Duration) (*discordgo.Message, error)
QueryInput queries the user with ID `id` for input
prompt : Question prompt userID : UserID to get message from timeout: How long to wait for the user's response
func (*Widget) RefreshTimeout ¶
RefreshTimeout refreshes timeout ticker by Widget's timeout. Returns ErrTickerNotSet when ticker is nil
func (*Widget) Reset ¶
Reset resets timeout ticker by duration. Returns ErrTickerNotSet when ticker is nil
d: New ticker duration
func (*Widget) UpdateEmbed ¶
UpdateEmbed updates the embed object and edits the original message
embed: New embed object to replace w.Embed