reactawait

package
v0.0.0-...-4e18fe8 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type TimeoutError

type TimeoutError struct {
	UserID discord.UserID
	// Cause contains the cause of the TimeoutError.
	// Currently, this will only be filled, if a context.Context expires, while
	// awaiting a message or reaction.
	// Should that be the case, Cause will hold ctx.Err().
	//
	// If Cause is nil, it can be assumed that the timeout was reached
	// regularly, i.e. by the user stopping to type.
	Cause error
}

TimeoutError is an error that fulfills errors.As for *errors.UserInfo.

func (*TimeoutError) As

func (e *TimeoutError) As(target interface{}) bool

func (*TimeoutError) Error

func (e *TimeoutError) Error() string

func (*TimeoutError) Unwrap

func (e *TimeoutError) Unwrap() error

Unwrap returns the cause for the timeout. Refer to the documentation for Cause for more information.

type Waiter

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

A Waiter is used to await reactions. Wait can either be cancelled by the user through a cancel reaction, or by the Waiter if the timeout expires.

func New

func New(s *state.State, ctx *plugin.Context, messageID discord.MessageID) *Waiter

New creates a new Waiter using the passed state.State and plugin.Context. ctx.Author will be assumed as the user to make the reaction in ctx.ChannelID.

func (*Waiter) Await

func (w *Waiter) Await(timeout time.Duration) (discord.APIEmoji, error)

Await creates a context.Context with the given timeout and calls AwaitContext with it.

func (*Waiter) AwaitContext

func (w *Waiter) AwaitContext(ctx context.Context) (discord.APIEmoji, error)

AwaitContext awaits a reaction of the user until they signal cancellation, the timeout expires or the context expires.

If the user cancels the wait or deletes the message, errors.Abort will be returned. Furthermore, if the guild, channel or message becomes unavailable while adding reactions, errors.Abort will be returned as well. If the context expires, a *TimeoutError with Cause set to ctx.Err() will be returned.

Besides that, the wait can also be canceled through a middleware.

func (*Waiter) Clone

func (w *Waiter) Clone() (cp *Waiter)

Clone creates a deep copy of the Waiter.

func (*Waiter) InChannel

func (w *Waiter) InChannel(id discord.ChannelID) *Waiter

InChannel changes the channel id to the passed discord.ChannelID.

func (*Waiter) NoAutoDelete

func (w *Waiter) NoAutoDelete() *Waiter

NoAutoDelete disables the automatic deletion of the reactions.

func (*Waiter) NoAutoReact

func (w *Waiter) NoAutoReact() *Waiter

NoAutoReact disables automatic reaction and deletion of the reactions.

func (*Waiter) WithCancelReactions

func (w *Waiter) WithCancelReactions(reactions ...discord.APIEmoji) *Waiter

WithCancelReactions adds the passed cancel reactions. If the user reacts with one of the passed emojis, AwaitReply will return errors.Abort.

func (*Waiter) WithMiddlewares

func (w *Waiter) WithMiddlewares(middlewares ...interface{}) *Waiter

WithMiddlewares adds the passed middlewares to the waiter. All middlewares of invalid type will be discarded.

The following types are permitted:

  • func(*state.State, interface{})
  • func(*state.State, interface{}) error
  • func(*state.State, *event.Base)
  • func(*state.State, *event.Base) error
  • func(*state.State, *state.MessageReactionAddEvent)
  • func(*state.State, *state.MessageReactionAddEvent) error

func (*Waiter) WithReactions

func (w *Waiter) WithReactions(reactions ...discord.APIEmoji) *Waiter

WithReactions adds the passed reaction to the wait list.

func (*Waiter) WithUser

func (w *Waiter) WithUser(id discord.UserID) *Waiter

WithUser changes the user that is expected to react to the user with the passed id.

Jump to

Keyboard shortcuts

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