bacotell_common

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2023 License: GPL-3.0 Imports: 1 Imported by: 9

Documentation

Overview

Package bacotell_common provides interfaces and structs to be used by plugins and BacoTell alike.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AutocompleteProxy

type AutocompleteProxy interface {
	// Respond sends the user the autocomplete suggestions.
	Respond(choices ...*discordgo.ApplicationCommandOptionChoice) error

	// FocusedOption returns the name and current partial value of the option for which autocompletion is requested.
	FocusedOption() (string, any, error)
}

An AutocompleteProxy provides methods for responding to the interaction as well as accessing the command option to be autocompleted.

type Command

type Command interface {
	// Data returns a discordgo.ApplicationCommand with all required fields set.
	//
	// Using this BacoTell registers this command to all guilds so it can be executed by users.
	// To ensure that commands from different plugins do not conflict with each other the command name has to be prefixed with the plugin id.
	// While it is possible for this method to return an error, it is in most cases regarded as a programming error rather than typical behavior.
	Data() (discordgo.ApplicationCommand, error)

	// Execute gets called whenever a user runs this command.
	Execute(ExecuteProxy) error

	// Autocomplete gets called when a user is typing this command and the autocomplete flag was set for one of the command options.
	Autocomplete(AutocompleteProxy) error
}

A Command represents a chat/message/user application command.

It provides all information necessary to register the command to a guild, as well as the command handler implementation.

type Component

type Component interface {
	// CustomID returns the custom id associated with the component.
	//
	// To ensure that components from different plugins do not conflict with each other the custom id has to be prefixed with the plugin id.
	// While it is possible for this method to return an error, it is in most cases regarded as a programming error rather than typical behavior.
	CustomID() (string, error)

	// Handle gets called when a user interacts with a matching component.
	Handle(HandleProxy) error
}

A Component represents a message component.

It provides the component handler implementation for a specific custom id.

type ExecuteProxy

type ExecuteProxy interface {
	InteractionProxy

	// StringOption retrieves the value of a string option by name. Returns an error if it was not set or the value is not a string.
	StringOption(name string) (string, error)

	// IntegerOption retrieves the value of an integer option by name. Returns an error if it was not set or the value is not a integer.
	IntegerOption(name string) (int64, error)

	// NumberOption retrieves the value of a number option by name. Returns an error if it was not set or the value is not a number.
	NumberOption(name string) (float64, error)

	// BooleanOption retrieves the value of a boolean option by name. Returns an error if it was not set or the value is not a boolean.
	BooleanOption(name string) (bool, error)

	// UserOption retrieves the value of a user option by name. Returns an error if it was not set or the value is not a user.
	UserOption(name string) (*discordgo.User, error)

	// RoleOption retrieves the value of a role option by name. Returns an error if it was not set or the value is not a role.
	RoleOption(name string) (*discordgo.Role, error)

	// ChannelOption retrieves the value of a channel option by name. Returns an error if it was not set or the value is not a channel.
	ChannelOption(name string) (*discordgo.Channel, error)

	// AttachmentOption retrieves the value of an attachment option by name. Returns an error if it was not set or the value is not a attachment.
	AttachmentOption(name string) (*discordgo.MessageAttachment, error)
}

An ExecuteProxy provides methods for responding to the interaction as well as accessing interaction data and command options during command execution.

type HandleProxy

type HandleProxy interface {
	InteractionProxy

	// ComponentType returns the type of the component with which the user interacted.
	ComponentType() (discordgo.ComponentType, error)

	// SelectedValues returns the selected values of a select menu component or nil if the component is not a select menu.
	SelectedValues() ([]string, error)
}

A HandleProxy provides methods for responding to the interaction as well as accessing interaction and component data and during component handling.

type InteractionProxy

type InteractionProxy interface {
	// Defer defers the response to the interaction which shows a possibly ephemeral loading message to the user.
	Defer(ephemeral bool) error

	// Respond responds to the user with the specified message and ephemerality.
	Respond(message Response, ephemeral bool) error

	// Modal shows a modal to the user with the specified custom id, title, and components.
	Modal(customId, title string, components ...discordgo.MessageComponent) error

	// Followup sends a follow-up message to the user with the specified message and ephemerality. The message id of the follow-up message is returned.
	Followup(message Response, ephemeral bool) (string, error)

	// Edit edits the message with the specified id. If id is the empty string it edits the original interaction response.
	Edit(id string, message Response) error

	// Delete deletes the message with the specified id. If id is the empty string it deletes the original interaction response.
	Delete(id string) error

	// GuildID returns the ID of the guild where the interaction occurred, if it was sent from a guild channel. Otherwise an empty string.
	GuildID() (string, error)

	// ChannelID returns the ID of the channel where the interaction occurred.
	ChannelID() (string, error)

	// UserLocale returns the locale of the user who triggered the interaction.
	UserLocale() (discordgo.Locale, error)

	// GuildLocale returns the locale of the guild where the interaction occurred, if it was sent from a guild channel. Otherwise it returns the user's locale.
	GuildLocale() (discordgo.Locale, error)

	// User returns the user who triggered the interaction, if it was sent from a DM channel. Otherwise nil.
	User() (*discordgo.User, error)

	// Member returns the member who triggered the interaction, if it was sent from a guild channel. Otherwise nil.
	Member() (*discordgo.Member, error)

	// Message returns the message on which interaction was used. Only available for message application commands and component, otherwise it will be nil.
	Message() (*discordgo.Message, error)

	// Permissions returns a bitwise set of permissions the bot has within the channel the interaction was sent from.
	Permissions() (int64, error)
}

An InteractionProxy provides methods for responding to the interaction as well as accessing interaction data.

type Modal interface {
	// CustomID returns the custom id associated with the modal.
	//
	// To ensure that modals from different plugins do not conflict with each other the custom id has to be prefixed with the plugin id.
	// While it is possible for this method to return an error, it is in most cases regarded as a programming error rather than typical behavior.
	CustomID() (string, error)

	// Submit gets called when a user submits a matching modal.
	Submit(SubmitProxy) error
}

A Modal represents a Discord modal.

It provides the modal handler implementation for a specific custom id.

type Plugin

type Plugin interface {
	// ID returns a unique plugin identifier.
	ID() (string, error)

	// ApplicationCommands returns all available commands that this plugin provides.
	ApplicationCommands() ([]Command, error)

	// ApplicationCommands returns all available components that this plugin can handle.
	MessageComponents() ([]Component, error)

	// Modals returns all available modals that this plugin can respond to.
	Modals() ([]Modal, error)
}

A Plugin is the top-level interface used by plugins to provide implementations for commands, components, etc to BacoTell.

While it is possible for all methods to return an error, it is in most cases regarded as a programming error rather than typical behavior.

type Response

type Response struct {
	// Content is the text content of the message.
	Content string

	// SuppressEmbeds specifies whether to suppress generated embeds in the message for e.g. links.
	SuppressEmbeds bool

	// TTS specifies whether the message should be spoken to the user.
	TTS bool

	// AllowedMentions specifies which mentions should be parsed by Discord.
	AllowedMentions discordgo.MessageAllowedMentions

	// Components specifies the message components to be included on the response message.
	Components []discordgo.MessageComponent

	// Embeds specify the message embeds to be included in the response message.
	Embeds []*discordgo.MessageEmbed

	// Files specify the files to be attached to the response message.
	Files []*discordgo.File
}

Response represents a response message for an interaction.

type SubmitProxy

type SubmitProxy interface {
	InteractionProxy

	// InputValue retrieves the value of a text input by custom id. Returns an error if it was not set or the component is not a text input.
	InputValue(customID string) (string, error)
}

A SubmitProxy provides methods for responding to the interaction as well as accessing interaction and modal data and during modal handling.

Jump to

Keyboard shortcuts

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