botcli

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2024 License: MPL-2.0 Imports: 13 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AccountNotFoundErr added in v0.5.0

type AccountNotFoundErr struct{ Addr string }

The account was not found.

func (*AccountNotFoundErr) Error added in v0.5.0

func (self *AccountNotFoundErr) Error() string

type BotCli

type BotCli struct {
	AppName string
	// AppDir can be set by the --folder flag in command line
	AppDir string
	// SelectedAddr can be set by the --account flag in command line, if empty it means "all accounts"
	SelectedAddr string
	RootCmd      *cobra.Command
	Logger       *zap.SugaredLogger
	// contains filtered or unexported fields
}

A CLI program, with subcommands that help configuring and running a Delta Chat bot.

func New

func New(appName string) *BotCli

Create a new BotCli instance.

func (*BotCli) AddCommand

func (self *BotCli) AddCommand(cmd *cobra.Command, callback Callback)

Add a subcommand to the CLI. The given callback will be executed when the command is used.

func (*BotCli) AdminChat added in v0.4.0

func (self *BotCli) AdminChat(bot *deltachat.Bot, accId deltachat.AccountId) (deltachat.ChatId, error)

Get the group of bot administrators.

func (*BotCli) GetAccount added in v0.5.0

func (self *BotCli) GetAccount(rpc *deltachat.Rpc, addr string) (deltachat.AccountId, error)

Get account for address, if no account exists with the given address, an error is returned

func (*BotCli) GetAddress added in v0.5.0

func (self *BotCli) GetAddress(rpc *deltachat.Rpc, accId deltachat.AccountId) (string, error)

Get the address of the given account

func (*BotCli) GetConfig added in v0.4.0

func (self *BotCli) GetConfig(bot *deltachat.Bot, accId deltachat.AccountId, key string) (option.Option[string], error)

Get a custom program setting from the given bot. The setting is specific to your application.

The setting is retrieved using Bot.GetUiConfig() and the key is prefixed with BotCli.AppName.

func (*BotCli) GetLogger added in v0.5.0

func (self *BotCli) GetLogger(accId deltachat.AccountId) *zap.SugaredLogger

Get a logger for the given account.

func (*BotCli) GetOrCreateAccount added in v0.5.0

func (self *BotCli) GetOrCreateAccount(rpc *deltachat.Rpc, addr string) (deltachat.AccountId, error)

Get account for address, if no account exists create a new one

func (*BotCli) IsAdmin added in v0.4.0

func (self *BotCli) IsAdmin(bot *deltachat.Bot, accId deltachat.AccountId, contactId deltachat.ContactId) (bool, error)

Returns true if contact is in the bot administrators group, false otherwise.

func (*BotCli) OnBotInit

func (self *BotCli) OnBotInit(callback Callback)

Register function to be called when the bot is initialized.

func (*BotCli) OnBotStart

func (self *BotCli) OnBotStart(callback Callback)

Register function to be called if the bot is about to start serving requests.

func (*BotCli) ResetAdminChat added in v0.4.0

func (self *BotCli) ResetAdminChat(bot *deltachat.Bot, accId deltachat.AccountId) (deltachat.ChatId, error)

Reset the group of bot administrators, all the members of the old group are no longer admins.

func (*BotCli) SetConfig added in v0.4.0

func (self *BotCli) SetConfig(bot *deltachat.Bot, accId deltachat.AccountId, key string, value option.Option[string]) error

Store a custom program setting in the given bot. The setting is specific to your application.

The setting is stored using Bot.SetUiConfig() and the key is prefixed with BotCli.AppName.

func (*BotCli) Start

func (self *BotCli) Start() error

Run the CLI program.

type BotNotConfiguredErr added in v0.4.0

type BotNotConfiguredErr struct{}

The bot is not configured yet.

func (*BotNotConfiguredErr) Error added in v0.4.0

func (self *BotNotConfiguredErr) Error() string

type Callback added in v0.4.0

type Callback func(cli *BotCli, bot *deltachat.Bot, cmd *cobra.Command, args []string)

A function that can be used as callback in OnBotInit(), OnBotStart() and AddCommand().

Jump to

Keyboard shortcuts

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