Documentation
¶
Index ¶
- Constants
- type Bot
- func (b *Bot) Cache() (cache.Cache, error)
- func (b *Bot) GetAllHandlers() map[string]handlers.Handler
- func (b *Bot) GetHandler(name string) (handlers.Handler, error)
- func (b *Bot) LoadPlugins() error
- func (b *Bot) PluginManager() handlers.PluginManager
- func (b *Bot) RegisterDefaultHandlers() error
- func (b *Bot) RegisterHandler(handler handlers.Handler) error
- func (b *Bot) Registry() handlers.Registry
- func (b *Bot) ReloadPlugins() error
- func (b *Bot) Start(ctx context.Context) error
- func (b *Bot) Store() (store.Store, error)
- func (b *Bot) UnloadPlugins() error
- type Option
- func WithAllowedCommands(commands []string) Option
- func WithAllowedGroups(groups []string) Option
- func WithAllowedUsers(users []string) Option
- func WithCache(cache cache.Cache) Option
- func WithLogger(logger *slog.Logger) Option
- func WithPluginManager(pm handlers.PluginManager) Option
- func WithRegistry(registry handlers.Registry) Option
- func WithStore(store store.Store) Option
- func WithTrigger(t string) Option
Constants ¶
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 ¶
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) GetAllHandlers ¶
GetAllHandlers returns all registered handlers
func (*Bot) GetHandler ¶
GetHandler returns a specific handler by name
func (*Bot) LoadPlugins ¶
LoadPlugins loads all WASM plugins from the plugin directory
func (*Bot) PluginManager ¶
func (b *Bot) PluginManager() handlers.PluginManager
func (*Bot) RegisterDefaultHandlers ¶
RegisterDefaultHandlers registers all available bot handlers with the given bot
func (*Bot) RegisterHandler ¶
RegisterHandler registers a new handler with the bot
func (*Bot) ReloadPlugins ¶
ReloadPlugins reloads all WASM plugins
func (*Bot) UnloadPlugins ¶
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
WithAllowedCommands sets the commands that WASM plugins are allowed to execute.
func WithAllowedGroups ¶ added in v0.8.0
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
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
WithCache sets a custom cache for the bot. If not provided, the bot will create a default cache.
func WithLogger ¶
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 ¶
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
WithStore sets a custom store for the bot. If not provided, the bot will create a default store.
func WithTrigger ¶
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"