bot

package
v0.8.2 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultTrigger = ".sup"

Variables

This section is empty.

Functions

This section is empty.

Types

type Bot

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

Bot represents the WhatsApp bot instance

func New

func New(opts ...Option) (*Bot, error)

New creates a new Bot instance with the given options. The bot is initialized with a default logger (slog.Default()) and all handlers are automatically registered.

The default plugin manager is also initialized, which loads plugins from the default plugin path ($HOME/.local/share/sup/plugins").

Example:

// Create a bot with default logger
bot := New()

// Create a bot with custom logger
logger := slog.New(slog.NewJSONHandler(os.Stdout, nil))
bot := New(WithLogger(logger))

// Create a bot with custom plugin manager
pm := handlers.NewPluginManager("/custom/plugin/path", cache, store)
bot := New(WithPluginManager(pm))

// Create a bot with custom registry
registry := handlers.NewRegistry()
bot := New(WithRegistry(registry))

func (*Bot) Cache added in v0.3.0

func (b *Bot) Cache() (cache.Cache, error)

Cache returns the cache service

func (*Bot) GetAllHandlers

func (b *Bot) GetAllHandlers() map[string]handlers.Handler

GetAllHandlers returns all registered handlers

func (*Bot) GetHandler

func (b *Bot) GetHandler(name string) (handlers.Handler, error)

GetHandler returns a specific handler by name

func (*Bot) LoadPlugins

func (b *Bot) LoadPlugins() error

LoadPlugins loads all WASM plugins from the plugin directory

func (*Bot) PluginManager

func (b *Bot) PluginManager() handlers.PluginManager

func (*Bot) RegisterDefaultHandlers

func (b *Bot) RegisterDefaultHandlers() error

RegisterDefaultHandlers registers all available bot handlers with the given bot

func (*Bot) RegisterHandler

func (b *Bot) RegisterHandler(handler handlers.Handler) error

RegisterHandler registers a new handler with the bot

func (*Bot) Registry

func (b *Bot) Registry() handlers.Registry

func (*Bot) ReloadPlugins

func (b *Bot) ReloadPlugins() error

ReloadPlugins reloads all WASM plugins

func (*Bot) Start

func (b *Bot) Start(ctx context.Context) error

Start starts the event handler loop

func (*Bot) Store added in v0.4.0

func (b *Bot) Store() (store.Store, error)

Store returns the store service

func (*Bot) UnloadPlugins

func (b *Bot) UnloadPlugins() error

UnloadPlugins unloads all WASM plugins

type Option

type Option func(*Bot)

Option is a function that configures the Bot

func WithAllowedCommands added in v0.8.0

func WithAllowedCommands(commands []string) Option

WithAllowedCommands sets the commands that WASM plugins are allowed to execute.

func WithAllowedGroups added in v0.8.0

func WithAllowedGroups(groups []string) Option

WithAllowedGroups sets the allowed group JIDs. Only messages from these groups will be processed. An empty list means no groups are allowed.

func WithAllowedUsers added in v0.8.0

func WithAllowedUsers(users []string) Option

WithAllowedUsers sets the allowed user JIDs. Only messages from these users will be processed. An empty list means no users are allowed.

func WithCache added in v0.3.0

func WithCache(cache cache.Cache) Option

WithCache sets a custom cache for the bot. If not provided, the bot will create a default cache.

func WithLogger

func WithLogger(logger *slog.Logger) Option

WithLogger sets a custom logger for the bot. If not provided, the bot will use slog.Default().

func WithPluginManager

func WithPluginManager(pm handlers.PluginManager) Option

WithPluginManager sets a custom plugin manager for the bot's registry. This option creates a new registry with the provided plugin manager. If used together with WithRegistry, this option should be applied first.

func WithRegistry

func WithRegistry(registry handlers.Registry) Option

WithRegistry sets a custom handler registry for the bot. If not provided, the bot will create a new registry with default settings.

func WithStore added in v0.4.0

func WithStore(store store.Store) Option

WithStore sets a custom store for the bot. If not provided, the bot will create a default store.

func WithTrigger

func WithTrigger(t string) Option

WithTrigger sets a custom trigger prefix for the bot commands. The default trigger is ".sup". Commands will be recognized when they start with the specified trigger followed by a space and command name.

Example:

bot := New(WithTrigger("mybot"))
// Commands will now be triggered with "mybot ping" instead of "sup ping"

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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