Documentation
¶
Overview ¶
Example ¶
package main
import (
"fmt"
"github.com/botopolis/bot"
"github.com/botopolis/bot/help"
"github.com/botopolis/bot/mock"
)
type HelperPlugin struct{ *mock.Plugin }
func (HelperPlugin) Help() []help.Text {
return []help.Text{
{Respond: true, Command: "foo", Description: "bar"},
{Respond: false, Command: "baz", Description: "bar"},
}
}
type mockChat struct {
blocking chan struct{}
*mock.Chat
}
func newMockChat() *mockChat {
m := &mockChat{Chat: mock.NewChat(), blocking: make(chan struct{})}
m.Name = "bot"
m.MessageChan = make(chan bot.Message, 1)
m.SendFunc = func(msg bot.Message) error {
fmt.Println(msg.Text)
close(m.blocking)
return nil
}
return m
}
func (m *mockChat) SendMessage(text string) {
m.MessageChan <- bot.Message{Text: text}
close(m.MessageChan)
}
func (m *mockChat) Wait() { <-m.blocking }
func main() {
chat := newMockChat()
go chat.SendMessage("@bot help")
bot.New(
chat,
help.New(),
&HelperPlugin{mock.NewPlugin()},
).Run()
chat.Wait()
}
Output: bot help - Displays all the help commands that this bot knows about. bot help <query> - Displays all help commands that match <query>. bot foo - bar baz - bar
Example (WithQuery) ¶
package main
import (
"fmt"
"github.com/botopolis/bot"
"github.com/botopolis/bot/help"
"github.com/botopolis/bot/mock"
)
type HelperPlugin struct{ *mock.Plugin }
func (HelperPlugin) Help() []help.Text {
return []help.Text{
{Respond: true, Command: "foo", Description: "bar"},
{Respond: false, Command: "baz", Description: "bar"},
}
}
type mockChat struct {
blocking chan struct{}
*mock.Chat
}
func newMockChat() *mockChat {
m := &mockChat{Chat: mock.NewChat(), blocking: make(chan struct{})}
m.Name = "bot"
m.MessageChan = make(chan bot.Message, 1)
m.SendFunc = func(msg bot.Message) error {
fmt.Println(msg.Text)
close(m.blocking)
return nil
}
return m
}
func (m *mockChat) SendMessage(text string) {
m.MessageChan <- bot.Message{Text: text}
close(m.MessageChan)
}
func (m *mockChat) Wait() { <-m.blocking }
func main() {
chat := newMockChat()
go chat.SendMessage("@bot help bar")
bot.New(
chat,
help.New(),
&HelperPlugin{mock.NewPlugin()},
).Run()
chat.Wait()
}
Output: bot foo - bar baz - bar
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Plugin ¶
type Plugin struct {
// contains filtered or unexported fields
}
Plugin is the help Plugin for botopolis/bot. It implements bot.Plugin and help.Helper.
type Provider ¶
type Provider interface {
Help() []Text
}
Provider is the interface a Plugin is expected to implement in order to provide help text.
type Text ¶
type Text struct {
// Respond is true if the command needs to be sent at a bot.
// Example: @bot <command>
Respond bool
// The command for which we are writing help text.
// Example: create link <name> <link>
Command string
// The description of the command.
// Example: Creates a link with the <name> short URL to the <link>.
Description string
}
Text is a representation of what is returned to the user. Example: Text{Respond: true, Command: "foo", Description: "bar"} turns into "<robot.Username> foo - bar"
Click to show internal directories.
Click to hide internal directories.