Documentation
¶
Overview ¶
Package bot provides a simple to use IRC bot
Index ¶
- Constants
- func RegisterCommand(command, description, exampleArgs string, cmdFunc activeCmdFuncV1)
- func RegisterCommandV2(command, description, exampleArgs string, cmdFunc activeCmdFuncV2)
- func RegisterPassiveCommand(command string, cmdFunc func(cmd *PassiveCmd) (string, error))
- func RegisterPeriodicCommand(command string, config PeriodicConfig)
- type Bot
- type Cmd
- type CmdResult
- type Handlers
- type PassiveCmd
- type PeriodicConfig
- type ResponseHandler
- type User
Constants ¶
const ( // CmdPrefix is the prefix used to identify a command. // !hello whould be identified as a command CmdPrefix = "!" )
Variables ¶
This section is empty.
Functions ¶
func RegisterCommand ¶
func RegisterCommand(command, description, exampleArgs string, cmdFunc activeCmdFuncV1)
RegisterCommand adds a new command to the bot. The command(s) should be registered in the Init() func of your package command: String which the user will use to execute the command, example: reverse decription: Description of the command to use in !help, example: Reverses a string exampleArgs: Example args to be displayed in !help <command>, example: string to be reversed cmdFunc: Function which will be executed. It will received a parsed command as a Cmd value
func RegisterCommandV2 ¶
func RegisterCommandV2(command, description, exampleArgs string, cmdFunc activeCmdFuncV2)
RegisterCommandV2 adds a new command to the bot. It is the same as RegisterCommand but the command can specify the channel to reply to
func RegisterPassiveCommand ¶
func RegisterPassiveCommand(command string, cmdFunc func(cmd *PassiveCmd) (string, error))
RegisterPassiveCommand adds a new passive command to the bot. The command should be registered in the Init() func of your package Passive commands receives all the text posted to a channel without any parsing command: String used to identify the command, for internal use only (ex: logs) cmdFunc: Function which will be executed. It will received the raw message, channel and nick
func RegisterPeriodicCommand ¶
func RegisterPeriodicCommand(command string, config PeriodicConfig)
RegisterPeriodicCommand adds a command that is run periodically. The command should be registered in the Init() func of your package config: PeriodicConfig which specify CronSpec and a channel list cmdFunc: A no-arg function which gets triggered periodically
Types ¶
type Bot ¶
type Bot struct {
// contains filtered or unexported fields
}
Bot handles the bot instance
type Cmd ¶
type Cmd struct {
Raw string // Raw is full string passed to the command
Channel string // Channel where the command was called
User *User // User who sent the message
Message string // Full string without the prefix
Command string // Command is the first argument passed to the bot
RawArgs string // Raw arguments after the command
Args []string // Arguments as array
}
Cmd holds the parsed user's input for easier handling of commands
type CmdResult ¶
type CmdResult struct {
Channel string // The channel where the bot should send the message
Message string // The message to be sent
}
CmdResult is the result message of V2 commands
type Handlers ¶
type Handlers struct {
Response ResponseHandler
}
Handlers that must be registered to receive callbacks from the bot
type PassiveCmd ¶
type PassiveCmd struct {
Raw string // Raw message sent to the channel
Channel string // Channel which the message was sent to
User *User // User who sent this message
}
PassiveCmd holds the information which will be passed to passive commands when receiving a message
type PeriodicConfig ¶
type PeriodicConfig struct {
CronSpec string // CronSpec that schedules some function
Channels []string // A list of channels to notify
CmdFunc func() (string, error) // func to be executed at the period specified on CronSpec
}
PeriodicConfig holds a cron specification for periodically notifying the configured channels
type ResponseHandler ¶
ResponseHandler must be implemented by the protocol to handle the bot responses
