lightning

package
v0.8.8 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package lightning provides a framework for creating a cross-platform chatbot

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Attachment

type Attachment struct {
	URL  string
	Name string
	Size int64
}

An Attachment on a Message.

type BaseMessage

type BaseMessage struct {
	Time      time.Time
	EventID   string
	ChannelID string
}

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 NewBot

func NewBot(prefix string) *Bot

NewBot creates a new *Bot based on the [BotOptions] provided to it.

func (*Bot) AddCommand

func (b *Bot) AddCommand(commands ...Command)

AddCommand takes [Command]s and registers it with the built-in text command handler and platform-specific command systems.

func (*Bot) AddHandler

func (b *Bot) AddHandler(listener any)

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

func (b *Bot) DeleteMessages(channelID string, ids []string) error

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

func (b *Bot) EditMessage(message *Message, ids []string, opts *SendOptions) ([]string, error)

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

func (b *Bot) IsAdmin(user, channelID string) (bool, error)

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

func (b *Bot) SetupChannel(channelID string) (map[string]string, error)

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

func (b *Bot) UsePluginType(typeName, instanceName string, config map[string]string) error

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

type ChannelDisabled struct {
	Read  bool `json:"read"`
	Write bool `json:"write"`
}

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

type CommandArgument struct {
	Name        string
	Description string
}

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

type EditedMessage struct {
	*Message

	Edited time.Time
}

EditedMessage is information about an edited message.

type Embed

type Embed struct {
	Author      *EmbedAuthor
	Footer      *EmbedFooter
	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

func (embed *Embed) ToMarkdown() string

ToMarkdown transforms a Discord-style embed to markdown.

type EmbedAuthor

type EmbedAuthor struct {
	URL     string
	IconURL string
	Name    string
}

EmbedAuthor is an author on an Embed.

type EmbedField

type EmbedField struct {
	Name   string
	Value  string
	Inline bool
}

EmbedField is a field on an Embed.

type EmbedFooter

type EmbedFooter struct {
	IconURL string
	Text    string
}

EmbedFooter is a footer on an Embed.

type Emoji

type Emoji struct {
	URL  string
	ID   string
	Name string
}

Emoji represents custom emoji in a Message.

type Media

type Media struct {
	URL    string
	Height int
	Width  int
}

Media represents images/videos 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

type MessageAuthor struct {
	ID             string
	Username       string
	ProfilePicture string
	Color          string
}

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

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

type PluginConstructor func(config map[string]string) (Plugin, error)

PluginConstructor makes a Plugin with the specified config.

type PluginMethodError

type PluginMethodError struct {
	ID     string
	Method string
	// contains filtered or unexported fields
}

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

type SendOptions

type SendOptions struct {
	CommandUser        string
	ChannelData        map[string]string
	CommandResponse    bool
	AllowEveryonePings bool
}

SendOptions is possible options to use when sending a message.

Jump to

Keyboard shortcuts

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