Documentation ¶
Index ¶
- type Adapter
- func CommandPrefix(prefix string) Adapter
- func Contains(s string, ignoreCase bool, ignoreWhiteSpace bool) Adapter
- func FromUser(user string) Adapter
- func FromUsers(users []string) Adapter
- func MessageType(typeName string) Adapter
- func MinRole(kb *keybase.Keybase, role string) Adapter
- func ReactionTrigger(trigger string) Adapter
- type Bot
- type BotAction
- type BotCommand
- type JobAction
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Adapter ¶
Adapter can modify the behavior of a BotAction
func CommandPrefix ¶
CommandPrefix returns an Adapter that specifies the specific prefix that this command responds to. Note that this will often require that MessageType is called _before_ this adapter to avoid a panic.
func Contains ¶ added in v1.1.0
Contains returns an Adapter that only runs a command when the message contains a specific string. This will also make sure the received message has a type of 'text' or 'edit'
func FromUser ¶ added in v1.1.0
FromUser returns an Adapter that only runs a command when sent by a specific user
func FromUsers ¶ added in v1.1.0
FromUsers returns an Adapter that only runs a command when sent by one of a list of specific users
func MessageType ¶
MessageType returns an Adapter that restricts a command to a specific message type
func MinRole ¶
MinRole returns an Adapter that restricts a command to users with _at least_ the specified role. Note that this _must_ be called _after_ CommandPrefix because this assumes that we already know we're executing the provided command.
func ReactionTrigger ¶
ReactionTrigger returns an Adapter that specifies the specific reaction that this command responds to. Note that you do not need to use the MessageType adapter when using this as we will already be checking to make sure the message type is a reaction.
type Bot ¶
type Bot struct { // The Name string will show up next to the bot's username in chat messages. Setting this // to empty will cause it to be ignored Name string // If CommandPrefix is set, any messages that are received with a TypeName of "text," and // do not have this string prefix will be discarded. This can be useful if all of your // commands start with the same prefix. CommandPrefix string // The Keybase instance KB *keybase.Keybase // The logr instance Logger *logr.Logger // Where you want log messages written to LogWriter io.Writer // If LogConv is not empty, log messages will be sent to this conversation, in addition to // the LogWriter LogConv chat1.ConvIDStr // Whether log messages should be in JSON format JSON bool // Whether to show debug messages in log output Debug bool // Message handlers. You probably should leave the Chat handler alone Handlers keybase.Handlers // Custom run options for the message listener Opts keybase.RunOptions // A slice holding all of you BotCommands. Be sure to populate this prior to calling Run() Commands []BotCommand // You can use this to store custom info in order to pass it around to your bot commands Meta map[string]interface{} // Setting this to true allows the bot to react to its own messages. You'll need to be // careful with your commands when enabling this to make sure your bot doesn't get stuck // in a loop attempting to verify its own message, then sending an error, then trying to // verify, etc. AllowSelfMessages bool // contains filtered or unexported fields }
Bot is where we'll hold the necessary information for the bot to run
func New ¶
New returns a new Bot instance. name will set the Bot.Name and will show up next to the bot's username in chat messages. You can set name to an empty string. You can also pass in any keybase.KeybaseOpt options and they will be passed to keybase.New()
func (*Bot) AdvertiseCommands ¶
func (b *Bot) AdvertiseCommands()
AdvertiseCommands loops through all the bot's commands and sends their advertisements to the Keybase service
func (*Bot) ClearCommands ¶
func (b *Bot) ClearCommands()
ClearCommands clears the advertised commands from the Keybase service
type BotAction ¶
type BotAction func(chat1.MsgSummary, *Bot) (bool, error)
BotAction is a function that's run when a command is received by the bot. If the boolean return is true, the bot will not attempt to execute any other commands after this one. If an error is returned, it will be sent to the logger. If an error is returned and the boolean is also set to true, the returned error will be sent back to the chat as a reply to the message that triggered the command.
func Adapt ¶
Adapt loops through a set of Adapters and runs them on a given BotAction in the order that they're provided. It's important to make sure you're passing adapters in the correct order as some things will need to be checked before others. As an example, the Contains adapter assumes that the incoming message has a MessageType of "text." If we pass that adapter prior to passing the MessageType adapter, then we will end up with a panic any time a message comes through with a MessageType other than "text."
type BotCommand ¶
type BotCommand struct { // Name of the command for use in the logs Name string // This will show in your chat channels when someone starts typing a command in the // message box. Set this to nil if you don't want the command advertised Ad *chat1.UserBotCommandInput // AdType can be one of "public", "conv", "teamconvs", and "teammembers". If AdType is empty or // unknown, it will default to "public". If AdType is one of "teamconvs" or "teammembers", // be sure to specify the corresponding team name in AdTeamName. If AdType is "conv", be // sure to specify the corresponding conversation id in AdConv. Note: These settings only // restrict where the advertisements will show. You will still need to either use // appropriate Adapters, or write your BotAction in a way that limits where the commands // can be called from if that is your intention AdType string // If AdType is one of "teamconvs" or "teammembers", be sure to enter a team name in // AdTeamName, which will restrict your command to either be advertised in this team, or // only be advertised to members of this team AdTeamName string // If AdType is "conv", be sure to enter a conversation id in AdConv, which will restrict // your command to being advertised only in this conversation AdConv chat1.ConvIDStr // The function to run when the command is triggered Run BotAction }
BotCommand holds information regarding a command and its advertisements
Directories ¶
Path | Synopsis |
---|---|
examples
|
|
meta-getset
This is a very simple bot that has 2 commands: set, and get.
|
This is a very simple bot that has 2 commands: set, and get. |
pkg
|
|