Documentation
¶
Overview ¶
Package lightning provides a framework for creating a cross-platform chatbot
Index ¶
- type Attachment
- type BaseMessage
- type Bot
- func (b *Bot) AddCommand(commands ...Command)
- func (b *Bot) AddHandler(listener any)
- func (b *Bot) AddPluginType(name string, constructor PluginConstructor)
- func (b *Bot) DeleteMessages(channelID string, ids []string) error
- func (b *Bot) EditMessage(message *Message, ids []string, opts *SendOptions) ([]string, error)
- func (b *Bot) IsAdmin(user, channelID string) (bool, error)
- func (b *Bot) SendMessage(message *Message, opts *SendOptions) ([]string, error)
- func (b *Bot) SetupChannel(channelID string) (map[string]string, error)
- func (b *Bot) UsePluginType(typeName, instanceName string, config map[string]string) error
- type ChannelDisabled
- type ChannelDisabler
- type Command
- type CommandArgument
- type CommandEvent
- type CommandOptions
- type EditedMessage
- type Embed
- type EmbedAuthor
- type EmbedField
- type EmbedFooter
- type Emoji
- type Media
- type Message
- type MessageAuthor
- type MissingPluginInstanceError
- type MissingPluginTypeError
- type Plugin
- type PluginConstructor
- type PluginMethodError
- type PluginRegisteredError
- type SendOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Attachment ¶
An Attachment on a Message.
type BaseMessage ¶
BaseMessage is basic message information, such as an ID, channel, and timestamp.
type Bot ¶
type Bot struct {
// contains filtered or unexported fields
}
Bot represents the collection of commands, plugins, and events that are used to make a bot using Lightning.
func (*Bot) AddCommand ¶
AddCommand takes [Command]s and registers it with the built-in text command handler and platform-specific command systems.
func (*Bot) AddHandler ¶
AddHandler allows you to register a listener for a given event type. Each handler must take in a *Bot and a pointer to a struct that corresponds with the event you want to listen to. If you provide a listener which does not match a known event signature, it will be ignored.
func (*Bot) AddPluginType ¶
func (b *Bot) AddPluginType(name string, constructor PluginConstructor)
AddPluginType takes in a PluginConstructor and registers it so you can later use it. It overwrites existing plugin types if the name is a duplicate.
func (*Bot) DeleteMessages ¶
DeleteMessages allows you to delete messages in the channel and plugin specified. The 'ids' parameter should contain the IDs of the messages to be edited, as returned by SendMessage.
func (*Bot) EditMessage ¶
EditMessage allows you to edit a message in the channel and plugin specified. The 'ids' parameter should contain the IDs of the messages to be edited, as returned by SendMessage. It will return the message IDs left after editing, which may differ from the original message IDs in content and length.
func (*Bot) IsAdmin ¶ added in v0.8.5
IsAdmin allows you to check if a user can do an action that requires an administrative role, such as SetupChannel.
func (*Bot) SendMessage ¶
func (b *Bot) SendMessage(message *Message, opts *SendOptions) ([]string, error)
SendMessage allows you to send a message to the channel and plugin specified on the provided Message. You may additionally provide *SendOptions. It returns the IDs of the messages sent, which may be nil if an error occurs.
func (*Bot) SetupChannel ¶
SetupChannel allows you to create the platform-specific equivalent of a webhook and allows you to send messages with a different author, when then return value is passed as ChannelData in *SendOptions.
func (*Bot) UsePluginType ¶
UsePluginType takes in a plugin name and config to use a plugin with your bot. It only returns an error if a plugin already exists *or* if the plugin type is not found. If you pass an empty string to instanceName, it will default to typeName, but that value must be unique.
type ChannelDisabled ¶
ChannelDisabled represents whether to disable a channel due to possible errors.
type ChannelDisabler ¶
type ChannelDisabler interface {
Disable() *ChannelDisabled
}
ChannelDisabler is an interface that allows a channel to be disabled in an external system.
type Command ¶
type Command struct {
Executor func(options *CommandOptions)
Name string
Description string
Subcommands map[string]Command
Arguments []CommandArgument
}
A Command registered with Bot.
type CommandArgument ¶
A CommandArgument is a possible argument for a Command.
type CommandEvent ¶
type CommandEvent struct {
*CommandOptions
Subcommand *string
Command string
Options []string
}
CommandEvent represents an execution of a command on a platform.
type CommandOptions ¶
type CommandOptions struct {
BaseMessage
Arguments map[string]string
Author *MessageAuthor
Bot *Bot
Reply func(message *Message, sensitive bool)
Prefix string
}
CommandOptions are provided to a Command executor.
type EditedMessage ¶
EditedMessage is information about an edited message.
type Embed ¶
type Embed struct {
Author *EmbedAuthor
Image *Media
Thumbnail *Media
Video *Media
Timestamp string
Title string
URL string
Description string
Fields []EmbedField
Color int
}
Embed is a Discord-style embed.
func (*Embed) ToMarkdown ¶
ToMarkdown transforms a Discord-style embed to markdown.
type EmbedAuthor ¶
EmbedAuthor is an author on an Embed.
type EmbedField ¶
EmbedField is a field on an Embed.
type Message ¶
type Message struct {
BaseMessage
Author *MessageAuthor
Content string
Attachments []Attachment
Embeds []Embed
Emoji []Emoji
RepliedTo []string
}
Message is a representation of a message on a platform.
type MessageAuthor ¶
MessageAuthor is an author on an Message.
type MissingPluginInstanceError ¶
type MissingPluginInstanceError struct {
Name string
}
MissingPluginInstanceError only occurs when a plugin is not found.
func (MissingPluginInstanceError) Error ¶
func (p MissingPluginInstanceError) Error() string
type MissingPluginTypeError ¶
type MissingPluginTypeError struct {
Name string
}
MissingPluginTypeError only occurs when a plugin type is not found.
func (MissingPluginTypeError) Error ¶
func (p MissingPluginTypeError) Error() string
type Plugin ¶
type Plugin interface {
IsAdmin(user, channel string) (bool, error)
SetupChannel(channel string) (map[string]string, error)
SendMessage(message *Message, opts *SendOptions) ([]string, error)
EditMessage(message *Message, ids []string, opts *SendOptions) ([]string, error)
DeleteMessage(channel string, ids []string) error
SetupCommands(command map[string]Command)
ListenMessages() <-chan *Message
ListenEdits() <-chan *EditedMessage
ListenDeletes() <-chan *BaseMessage
ListenCommands() <-chan *CommandEvent
}
A Plugin provides methods used by Bot to allow bots to not worry about platform specifics, as each Plugin handles that.
type PluginConstructor ¶
PluginConstructor makes a Plugin with the specified config.
type PluginMethodError ¶
PluginMethodError is a wrapped error that occurs when a plugin method fails.
func (PluginMethodError) Error ¶
func (p PluginMethodError) Error() string
func (PluginMethodError) Unwrap ¶
func (p PluginMethodError) Unwrap() error
type PluginRegisteredError ¶
type PluginRegisteredError struct {
Name string
}
PluginRegisteredError only occurs when a plugin is already registered and can't be registered again.
func (PluginRegisteredError) Error ¶
func (p PluginRegisteredError) Error() string