Documentation
¶
Overview ¶
Package botmaid is a package for managing bots.
Index ¶
- func GetArgument(c string) []string
- func In(a interface{}, s ...interface{}) bool
- func SplitCommand(c string) []string
- type API
- type Bot
- type BotMaid
- type Chat
- type Command
- type CommandSlice
- type CoolqHTTPAPI
- type ErrorChannel
- type GetUpdatesConfig
- type HelpMenu
- type Message
- type TelegramBotAPI
- type Timer
- type Update
- type UpdateChannel
- type User
- type Word
- type WordSlice
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetArgument ¶ added in v1.3.0
GetArgument returns a slice with a command and an argument.
func SplitCommand ¶ added in v1.0.1
SplitCommand splits a string into a slice of string.
Types ¶
type API ¶
type API interface {
GetUpdates(GetUpdatesConfig) (UpdateChannel, ErrorChannel)
Push(Update) (Update, error)
}
API is an interface including some common behaviors for APIs.
GetUpdates always gets updates and errors into the channels with a given config.
Push always pushes an update and returns it back if existing.
Delete always deletes a specific update.
type Bot ¶
Bot includes some information of a bot.
func (*Bot) IsTestChat ¶ added in v1.4.0
IsTestChat checks if a chat is a test chat of the bot.
type BotMaid ¶
type BotMaid struct {
Bots map[string]*Bot
Conf *toml.Tree
Redis *redis.Client
Commands []Command
Timers []Timer
HelpMenus []HelpMenu
Words map[string][]string
RespTime time.Time
}
BotMaid includes a slice of Bot and some methods to use them.
func (*BotMaid) AddCommand ¶
AddCommand adds a command into the []Command.
type Command ¶
type Command struct {
Do func(*Update, *Bot) bool
Priority int
Menu, Help string
Names []string
ArgsMinLen, ArgsMaxLen int
Master, Test bool
}
Command is a func with priority value so that we can sort some Commands to make them in a specific order.
type CommandSlice ¶
type CommandSlice []Command
CommandSlice is a slice of Command that could be sort.
func (CommandSlice) Less ¶
func (cs CommandSlice) Less(i, j int) bool
Less returns true if CommandSlice[i] is less then CommandSlice[j].
func (CommandSlice) Swap ¶
func (cs CommandSlice) Swap(i, j int)
Swap swaps CommandSlice[i] and CommandSlice[j].
type CoolqHTTPAPI ¶ added in v1.4.0
CoolqHTTPAPI is a struct stores some basic information of the Coolq HTTP API. Please search in Coolq HTTP API document for details.
func (*CoolqHTTPAPI) API ¶ added in v1.4.0
func (a *CoolqHTTPAPI) API(end string, m map[string]interface{}) (interface{}, error)
API returns the body of an HTTP response to the Coolq HTTP API.
func (*CoolqHTTPAPI) GetUpdates ¶ added in v1.4.0
func (a *CoolqHTTPAPI) GetUpdates(pc GetUpdatesConfig) (UpdateChannel, ErrorChannel)
GetUpdates gets updates and errors into the channels with a given config.
type GetUpdatesConfig ¶ added in v1.4.0
GetUpdatesConfig is a struct for getting updates.
Limit decides the number of updates pulled once. Timeout decides the timeout of long polling. RetryWaitingTime decides decides the time waiting after pulling an error.
type TelegramBotAPI ¶ added in v1.4.0
TelegramBotAPI is a struct stores some basic information of the Telegram Bot API. Please search in official API document for details.
func (*TelegramBotAPI) API ¶ added in v1.4.0
func (a *TelegramBotAPI) API(end string, m map[string]interface{}) (interface{}, error)
API returns the body of an HTTP response to the Telegram Bot API.
func (*TelegramBotAPI) GetUpdates ¶ added in v1.4.0
func (a *TelegramBotAPI) GetUpdates(pc GetUpdatesConfig) (UpdateChannel, ErrorChannel)
GetUpdates gets updates and errors into the channels with a given config.