Documentation ¶
Index ¶
- Variables
- func ChannelMentionString(cid snowflake.Snowflake) string
- func ForceUserAccountMention(v string) (string, error)
- func ForceUserNicknameMention(v string) (string, error)
- func IsChannelMention(v string) bool
- func IsRoleMention(v string) bool
- func IsUserMention(v string) bool
- func RoleMentionString(rid snowflake.Snowflake) string
- func UserMentionString(uid snowflake.Snowflake) string
- type CommandHandler
- type EmbedField
- type EmbedResponse
- func (r *EmbedResponse) Channel() snowflake.Snowflake
- func (r *EmbedResponse) HasErrors() bool
- func (r *EmbedResponse) IncludeError(err error)
- func (r *EmbedResponse) MessageReactions() []string
- func (r *EmbedResponse) SetColor(color int)
- func (r *EmbedResponse) SetReplyTo(m Message)
- func (r *EmbedResponse) Split() []Response
- func (r *EmbedResponse) ToMessage() JSONMarshaler
- func (r *EmbedResponse) ToString() string
- type JSONMarshaler
- type Message
- func NewSimpleMessage(ctx context.Context, userID, guildID, channelID, messageID snowflake.Snowflake, ...) Message
- func NewWithContents(m Message, contents string) Message
- func NewWithContext(ctx context.Context, m Message) Message
- func NewWithTokens(m Message, tokens []string, contentErr error) Message
- type MessageHandler
- type MessageHandlerFunc
- type Options
- type ReplyTo
- type Response
- type SimpleEmbedResponse
- func (r *SimpleEmbedResponse) Channel() snowflake.Snowflake
- func (r *SimpleEmbedResponse) HasErrors() bool
- func (r *SimpleEmbedResponse) IncludeError(err error)
- func (r *SimpleEmbedResponse) MessageReactions() []string
- func (r *SimpleEmbedResponse) SetColor(color int)
- func (r *SimpleEmbedResponse) SetReplyTo(m Message)
- func (r *SimpleEmbedResponse) Split() []Response
- func (r *SimpleEmbedResponse) ToMessage() JSONMarshaler
- func (r *SimpleEmbedResponse) ToString() string
- type SimpleResponse
- func (r *SimpleResponse) Channel() snowflake.Snowflake
- func (r *SimpleResponse) HasErrors() bool
- func (r *SimpleResponse) IncludeError(err error)
- func (r *SimpleResponse) MessageReactions() []string
- func (r *SimpleResponse) SetColor(color int)
- func (r *SimpleResponse) SetReplyTo(m Message)
- func (r *SimpleResponse) Split() []Response
- func (r *SimpleResponse) ToMessage() JSONMarshaler
- func (r *SimpleResponse) ToString() string
Constants ¶
This section is empty.
Variables ¶
var ErrMissingHandler = errors.New("missing handler for command")
ErrMissingHandler is the error thrown when an event handler cannot be found
var ErrNotUserMention = errors.New("not a user mention")
ErrNotUserMention is the error returned when a user mention string is required but not provided
Functions ¶
func ChannelMentionString ¶
ChannelMentionString generates a string that discord interprets as a mention of a channel
func ForceUserAccountMention ¶
ForceUserAccountMention converts a user mention into an account mention (if it is not already an account mention)
func ForceUserNicknameMention ¶
ForceUserNicknameMention converts a user mention into a nickname mention (if it is not already a nickname mention)
func IsChannelMention ¶
IsChannelMention determines if a string is a mention of a channel
func IsRoleMention ¶
IsRoleMention determines if a string is a mention of a server role
func IsUserMention ¶
IsUserMention determines if a string is a mention of a user (either by nickname or account name)
func RoleMentionString ¶
RoleMentionString generates a string that discord interprets as a mention of a server role
func UserMentionString ¶
UserMentionString generates a string that discord interprets as a mention of a user by their server nickname
Types ¶
type CommandHandler ¶
type CommandHandler struct {
// contains filtered or unexported fields
}
CommandHandler is a dispatcher for commands
func NewCommandHandler ¶
func NewCommandHandler(p parser.Parser, opts Options) (*CommandHandler, error)
NewCommandHandler creates a new CommandHandler from the given parser
NOTE: the parser's settings must match the Options.CaseSensitive value
func (*CommandHandler) CommandIndicator ¶
func (ch *CommandHandler) CommandIndicator() string
CommandIndicator returns the string prefix required for commands
func (*CommandHandler) HandleMessage ¶
func (ch *CommandHandler) HandleMessage(msg Message) (Response, error)
HandleMessage dispatches a Message to the relevant handler
func (*CommandHandler) SetHandler ¶
func (ch *CommandHandler) SetHandler(cmd string, handler MessageHandler)
SetHandler adds a handler function for the given command, overwriting any previously set ones
type EmbedField ¶
EmbedField is part of an EmbedResponse that represents an embed field
type EmbedResponse ¶
type EmbedResponse struct { To string Title string Description string Color int Fields []EmbedField ToChannel snowflake.Snowflake Reactions []string ReplyTo *ReplyTo // contains filtered or unexported fields }
EmbedResponse is a Response that is intended to present text in an discord embed box, including embed fields
func (*EmbedResponse) Channel ¶
func (r *EmbedResponse) Channel() snowflake.Snowflake
Channel returns the ToChannel value
func (*EmbedResponse) HasErrors ¶
func (r *EmbedResponse) HasErrors() bool
HasErrors returns whether or not the response already includes errors
func (*EmbedResponse) IncludeError ¶
func (r *EmbedResponse) IncludeError(err error)
IncludeError adds an error into the response
func (*EmbedResponse) MessageReactions ¶
func (r *EmbedResponse) MessageReactions() []string
func (*EmbedResponse) SetColor ¶
func (r *EmbedResponse) SetColor(color int)
SetColor sets the side color of the embed box
func (*EmbedResponse) SetReplyTo ¶ added in v16.1.0
func (r *EmbedResponse) SetReplyTo(m Message)
func (*EmbedResponse) Split ¶
func (r *EmbedResponse) Split() []Response
Split separates the current response into possibly-several to account for response length limits
func (*EmbedResponse) ToMessage ¶
func (r *EmbedResponse) ToMessage() JSONMarshaler
ToMessage generates an object that can be marshaled as json and sent to the discord http API
func (*EmbedResponse) ToString ¶
func (r *EmbedResponse) ToString() string
ToString generates a plain-text representation of the response
type JSONMarshaler ¶
JSONMarshaler is the interface implemented by types that can marshal themselves into valid JSON.
type Message ¶
type Message interface { Context() context.Context UserID() snowflake.Snowflake GuildID() snowflake.Snowflake ChannelID() snowflake.Snowflake MessageID() snowflake.Snowflake Contents() []string ContentErr() error }
Message is the api for a message that a command handler will respond to
func NewSimpleMessage ¶
func NewSimpleMessage(ctx context.Context, userID, guildID, channelID, messageID snowflake.Snowflake, contents string) Message
NewSimpleMessage creates a new Message object
func NewWithContents ¶
NewWithContents clones a given message object but substitutes the Contents() with the provided string
type MessageHandler ¶
MessageHandler is the api of a message handler
func NewMessageHandler ¶
func NewMessageHandler(f MessageHandlerFunc) MessageHandler
NewMessageHandler wraps a MessageHandlerFunc into a MessageHandler
type MessageHandlerFunc ¶
MessageHandlerFunc is the api of a function that handles messages
type Options ¶
type Options struct { Placeholder string PreCommand string NoHelpOnUnknownCommands bool HelpOnEmptyCommands bool CaseSensitive bool }
Options provides a way to specify configurable values when creating a CommandHandler
- Placeholder is the string to be used to represent the "command" - PreCommand is a string representing the state of commands prior to this one - NoHelpOnUnknownCommands can be set to true to NOT display a help message when a command isn't known - HelpOnEmptyCommands can be set to true to display a help message when no command is provided - CaseSensitive can se set to true to make command recognition case-sensitive
type ReplyTo ¶ added in v16.1.0
type ReplyTo struct { MessageID snowflake.Snowflake ChannelID snowflake.Snowflake GuildID snowflake.Snowflake }
ReplyTo is the information required to create a message as a reply
type Response ¶
type Response interface { SetColor(int) IncludeError(err error) HasErrors() bool ToString() string ToMessage() JSONMarshaler Channel() snowflake.Snowflake Split() []Response MessageReactions() []string }
Response is the interface that should be returned from a command handler
type SimpleEmbedResponse ¶
type SimpleEmbedResponse struct { To string Title string Description string Color int ToChannel snowflake.Snowflake Reactions []string ReplyTo *ReplyTo // contains filtered or unexported fields }
SimpleEmbedResponse is a Response that is intended to present text in an discord embed box but not include any embed fields
func (*SimpleEmbedResponse) Channel ¶
func (r *SimpleEmbedResponse) Channel() snowflake.Snowflake
Channel returns the ToChannel value
func (*SimpleEmbedResponse) HasErrors ¶
func (r *SimpleEmbedResponse) HasErrors() bool
HasErrors returns whether or not the response already includes errors
func (*SimpleEmbedResponse) IncludeError ¶
func (r *SimpleEmbedResponse) IncludeError(err error)
IncludeError adds an error into the response
func (*SimpleEmbedResponse) MessageReactions ¶
func (r *SimpleEmbedResponse) MessageReactions() []string
func (*SimpleEmbedResponse) SetColor ¶
func (r *SimpleEmbedResponse) SetColor(color int)
SetColor sets the side color of the embed box
func (*SimpleEmbedResponse) SetReplyTo ¶ added in v16.1.0
func (r *SimpleEmbedResponse) SetReplyTo(m Message)
func (*SimpleEmbedResponse) Split ¶
func (r *SimpleEmbedResponse) Split() []Response
Split separates the current response into possibly-several to account for response length limits
func (*SimpleEmbedResponse) ToMessage ¶
func (r *SimpleEmbedResponse) ToMessage() JSONMarshaler
ToMessage generates an object that can be marshaled as json and sent to the discord http API
func (*SimpleEmbedResponse) ToString ¶
func (r *SimpleEmbedResponse) ToString() string
ToString generates a plain-text representation of the response
type SimpleResponse ¶
type SimpleResponse struct { To string Content string ToChannel snowflake.Snowflake Reactions []string ReplyTo *ReplyTo // contains filtered or unexported fields }
SimpleResponse is a Response that is intended to present plain text
func (*SimpleResponse) Channel ¶
func (r *SimpleResponse) Channel() snowflake.Snowflake
Channel returns the ToChannel value
func (*SimpleResponse) HasErrors ¶
func (r *SimpleResponse) HasErrors() bool
HasErrors returns whether or not the response includes errors
func (*SimpleResponse) IncludeError ¶
func (r *SimpleResponse) IncludeError(err error)
IncludeError adds an error into the response
func (*SimpleResponse) MessageReactions ¶
func (r *SimpleResponse) MessageReactions() []string
func (*SimpleResponse) SetColor ¶
func (r *SimpleResponse) SetColor(color int)
SetColor is included for the Response API but is a no-op
func (*SimpleResponse) SetReplyTo ¶ added in v16.1.0
func (r *SimpleResponse) SetReplyTo(m Message)
func (*SimpleResponse) Split ¶
func (r *SimpleResponse) Split() []Response
Split separates the current response into possibly-several to account for response length limits
func (*SimpleResponse) ToMessage ¶
func (r *SimpleResponse) ToMessage() JSONMarshaler
ToMessage generates an object that can be marshaled as json and sent to the discord http API
func (*SimpleResponse) ToString ¶
func (r *SimpleResponse) ToString() string
ToString generates a plain-text representation of the response