Documentation ¶
Index ¶
- Constants
- Variables
- func CommandHelp(service Service, command, arguments, help string) []string
- func MatchesCommand(service Service, commandString string, message Message) bool
- func MatchesCommandStringPrefix(prefix, commandString string, private bool, message string) bool
- func MessageRecover()
- func ParseCommand(service Service, message Message) (string, []string)
- func ParseCommandStringPrefix(prefix, message string) (string, []string)
- type Bot
- type CommandHelpFunc
- type CommandMessageFunc
- type CommandPlugin
- func (p *CommandPlugin) AddCommand(commandString string, message CommandMessageFunc, help CommandHelpFunc)
- func (p *CommandPlugin) Help(bot *Bot, service Service, message Message, detailed bool) []string
- func (p *CommandPlugin) Load(bot *Bot, service Service, data []byte) error
- func (p *CommandPlugin) Message(bot *Bot, service Service, message Message)
- func (p *CommandPlugin) Name() string
- func (p *CommandPlugin) Save() ([]byte, error)
- func (p *CommandPlugin) Stats(bot *Bot, service Service, message Message) []string
- type Discord
- func (d *Discord) BanUser(channel, userID string, duration int) error
- func (d *Discord) Channel(channelID string) (channel *discordgo.Channel, err error)
- func (d *Discord) ChannelCount() int
- func (d *Discord) CommandPrefix() string
- func (d *Discord) DeleteMessage(channel, messageID string) error
- func (d *Discord) Guild(guildID string) (guild *discordgo.Guild, err error)
- func (d *Discord) Guilds() []*discordgo.Guild
- func (d *Discord) IsBotOwner(message Message) bool
- func (d *Discord) IsChannelOwner(message Message) bool
- func (d *Discord) IsMe(message Message) bool
- func (d *Discord) IsModerator(message Message) bool
- func (d *Discord) IsPrivate(message Message) bool
- func (d *Discord) Join(join string) error
- func (d *Discord) Member(guildID string, userID string) (member *discordgo.Member, err error)
- func (d *Discord) MessageColor(message Message) int
- func (d *Discord) MessagePermissions(message Message) (apermissions int64, err error)
- func (d *Discord) Name() string
- func (d *Discord) Nickname(message Message) string
- func (d *Discord) NicknameForID(userID, userName, channelID string) string
- func (d *Discord) Open() (<-chan Message, error)
- func (d *Discord) PrivateMessage(userID, message string) error
- func (d *Discord) SendAction(channel, message string) error
- func (d *Discord) SendFile(channel, name string, r io.Reader) error
- func (d *Discord) SendMessage(channel, message string) error
- func (d *Discord) SupportsMultiline() bool
- func (d *Discord) SupportsPrivateMessages() bool
- func (d *Discord) Typing(channel string) error
- func (d *Discord) UnbanUser(channel, userID string) error
- func (d *Discord) UpdateStatus(idle int, game string)
- func (d *Discord) UpdateStreamingStatus(idle int, game string, url string)
- func (d *Discord) UserChannelPermissions(userID, channelID string) (apermissions int64, err error)
- func (d *Discord) UserColor(userID, channelID string) int
- func (d *Discord) UserID() string
- func (d *Discord) UserName() string
- type DiscordMessage
- func (m *DiscordMessage) AttachmentURL() string
- func (m *DiscordMessage) AttachmentURLLarge() string
- func (m *DiscordMessage) Channel() string
- func (m *DiscordMessage) MatchesCommand(prefix, command string) (bool, bool)
- func (m *DiscordMessage) Message() string
- func (m *DiscordMessage) MessageID() string
- func (m *DiscordMessage) ParseCommand(prefix string) (string, []string, bool)
- func (m *DiscordMessage) RawMessage() string
- func (m *DiscordMessage) Type() MessageType
- func (m *DiscordMessage) UserAvatar() string
- func (m *DiscordMessage) UserID() string
- func (m *DiscordMessage) UserName() string
- type HelpFunc
- type LoadFunc
- type Message
- type MessageFunc
- type MessageType
- type MockMessage
- func (m *MockMessage) Channel() string
- func (m *MockMessage) MatchesCommand(prefix, command string) (bool, bool)
- func (m *MockMessage) Message() string
- func (m *MockMessage) MessageID() string
- func (m *MockMessage) ParseCommand(prefix string) (string, []string, bool)
- func (m *MockMessage) RawMessage() string
- func (m *MockMessage) SetAvatar(avatar string) *MockMessage
- func (m *MockMessage) SetChannel(channel string) *MockMessage
- func (m *MockMessage) SetMessage(message string) *MockMessage
- func (m *MockMessage) SetMessageID(messageID string) *MockMessage
- func (m *MockMessage) SetRawMessage(message string) *MockMessage
- func (m *MockMessage) SetUserID(userid string) *MockMessage
- func (m *MockMessage) SetUserName(username string) *MockMessage
- func (m *MockMessage) Type() MessageType
- func (m *MockMessage) UserAvatar() string
- func (m *MockMessage) UserID() string
- func (m *MockMessage) UserName() string
- type MockService
- func (s *MockService) BanUser(channel, userID string, duration int) error
- func (s *MockService) ChannelCount() int
- func (s *MockService) CommandPrefix() string
- func (s *MockService) DeleteMessage(channel, messageID string) error
- func (s *MockService) IsBotOwner(message Message) bool
- func (s *MockService) IsChannelOwner(message Message) bool
- func (s *MockService) IsMe(message Message) bool
- func (s *MockService) IsModerator(message Message) bool
- func (s *MockService) IsPrivate(message Message) bool
- func (s *MockService) Join(join string) error
- func (s *MockService) Name() string
- func (s *MockService) NewMessage(message Message)
- func (s *MockService) Open() (<-chan Message, error)
- func (s *MockService) PrivateMessage(userID, messageID string) error
- func (s *MockService) SendAction(channel, message string) error
- func (s *MockService) SendFile(channel, name string, r io.Reader) error
- func (s *MockService) SendMessage(channel, message string) error
- func (m *MockService) SetName(name string) *MockService
- func (m *MockService) SetUserID(userid string) *MockService
- func (m *MockService) SetUserName(username string) *MockService
- func (s *MockService) SupportsMultiline() bool
- func (s *MockService) SupportsPrivateMessages() bool
- func (s *MockService) Typing(channel string) error
- func (s *MockService) UnbanUser(channel, userID string) error
- func (s *MockService) UserID() string
- func (s *MockService) UserName() string
- type ParsedCommand
- type Plugin
- type SaveFunc
- type Service
- type SimplePlugin
- func (p *SimplePlugin) Help(bot *Bot, service Service, message Message, detailed bool) []string
- func (p *SimplePlugin) Load(bot *Bot, service Service, data []byte) error
- func (p *SimplePlugin) Message(bot *Bot, service Service, message Message)
- func (p *SimplePlugin) Name() string
- func (p *SimplePlugin) Save() ([]byte, error)
- func (p *SimplePlugin) Stats(bot *Bot, service Service, message Message) []string
- type StatsFunc
Constants ¶
const ( // MessageTypeCreate is the message type for message creation. MessageTypeCreate MessageType = "create" // MessageTypeUpdate is the message type for message updates. MessageTypeUpdate = "update" // MessageTypeDelete is the message type for message deletion. MessageTypeDelete = "delete" )
const DiscordServiceName string = "Discord"
DiscordServiceName is the service name for the Discord service.
const VersionString string = "0.12"
VersionString is the current version of the bot
Variables ¶
var ErrAlreadyJoined = errors.New("Already joined.")
ErrAlreadyJoined is an error dispatched on Join if the bot is already joined to the request.
Functions ¶
func CommandHelp ¶
CommandHelp is a helper message that creates help text for a command. eg. CommandHelp(service, "foo", "<bar>", "Foo bar baz") will return:
!foo <bar> - Foo bar baz
The string is automatatically styled in Discord.
func MatchesCommand ¶
MatchesCommand returns true if a message matches a command.
func MatchesCommandStringPrefix ¶
MatchesCommandStringPrefix returns true if a message matches a command. Commands will be matched ignoring case with a prefix if they are not private messages.
func MessageRecover ¶
func MessageRecover()
MessageRecover is the default panic handler for bruxism.
func ParseCommand ¶
ParseCommand parses a message.
func ParseCommandStringPrefix ¶
ParseCommandStringPrefix will strip all prefixes from a message string, and return that string, and a space separated tokenized version of that string.
Types ¶
type Bot ¶
type Bot struct { Services map[string]*serviceEntry ImgurID string ImgurAlbum string MashableKey string }
Bot enables registering of Services and Plugins.
func (*Bot) Open ¶
func (b *Bot) Open()
Open will open all the current services and begins listening.
func (*Bot) RegisterPlugin ¶
RegisterPlugin registers a plugin on a service.
func (*Bot) RegisterService ¶
RegisterService registers a service with the bot.
type CommandHelpFunc ¶
CommandHelpFunc is the function signature for command help methods.
func NewCommandHelp ¶
func NewCommandHelp(args, help string) CommandHelpFunc
NewCommandHelp creates a new Command Help function.
type CommandMessageFunc ¶
type CommandMessageFunc func(bot *Bot, service Service, message Message, args string, parts []string)
CommandMessageFunc is the function signature for bot message commands.
type CommandPlugin ¶
type CommandPlugin struct {
// contains filtered or unexported fields
}
CommandPlugin is a plugin that can have commands registered and will handle messages matching that command by calling functions.
func NewCommandPlugin ¶
func NewCommandPlugin() *CommandPlugin
NewCommandPlugin will create a new command plugin.
func (*CommandPlugin) AddCommand ¶
func (p *CommandPlugin) AddCommand(commandString string, message CommandMessageFunc, help CommandHelpFunc)
AddCommand adds a command.
func (*CommandPlugin) Help ¶
Help returns a list of help strings that are printed when the user requests them.
func (*CommandPlugin) Load ¶
func (p *CommandPlugin) Load(bot *Bot, service Service, data []byte) error
Load will load plugin state from a byte array.
func (*CommandPlugin) Message ¶
func (p *CommandPlugin) Message(bot *Bot, service Service, message Message)
Message handler. Iterates over the registered commands and executes them if the message matches.
func (*CommandPlugin) Name ¶
func (p *CommandPlugin) Name() string
Name returns the name of the plugin.
func (*CommandPlugin) Save ¶
func (p *CommandPlugin) Save() ([]byte, error)
Save will save plugin state to a byte array.
type Discord ¶
type Discord struct { // The first session, used to send messages (and maintain backwards compatibility). Session *discordgo.Session Sessions []*discordgo.Session OwnerUserID string ApplicationClientID string // contains filtered or unexported fields }
Discord is a Service provider for Discord.
func NewDiscord ¶
func NewDiscord(args ...interface{}) *Discord
NewDiscord creates a new discord service.
func (*Discord) ChannelCount ¶
ChannelCount returns the number of channels the bot is in.
func (*Discord) CommandPrefix ¶
CommandPrefix returns the command prefix for the service.
func (*Discord) DeleteMessage ¶
DeleteMessage deletes a message.
func (*Discord) IsBotOwner ¶
IsBotOwner returns whether or not a message sender was the owner of the bot.
func (*Discord) IsChannelOwner ¶
IsChannelOwner returns whether or not the sender of a message is a moderator.
func (*Discord) IsModerator ¶
IsModerator returns whether or not the sender of a message is a moderator.
func (*Discord) Join ¶
Join accept an invite or return an error. If AlreadyJoinedError is return, @me has already accepted that invite.
func (*Discord) MessageColor ¶
func (*Discord) MessagePermissions ¶
func (*Discord) NicknameForID ¶
func (*Discord) Open ¶
Open opens the service and returns a channel which all messages will be sent on.
func (*Discord) PrivateMessage ¶
PrivateMessage will send a private message to a user.
func (*Discord) SendAction ¶
SendAction sends an action.
func (*Discord) SendMessage ¶
SendMessage sends a message.
func (*Discord) SupportsMultiline ¶
SupportsMultiline returns whether the service supports multiline messages.
func (*Discord) SupportsPrivateMessages ¶
SupportsPrivateMessages returns whether the service supports private messages.
func (*Discord) UpdateStatus ¶
func (*Discord) UpdateStreamingStatus ¶
func (*Discord) UserChannelPermissions ¶
type DiscordMessage ¶
type DiscordMessage struct { sync.RWMutex Discord *Discord DiscordgoMessage *discordgo.Message MessageType MessageType Nick *string Content *string // contains filtered or unexported fields }
DiscordMessage is a Message wrapper around discordgo.Message.
func (*DiscordMessage) AttachmentURL ¶
func (m *DiscordMessage) AttachmentURL() string
func (*DiscordMessage) AttachmentURLLarge ¶
func (m *DiscordMessage) AttachmentURLLarge() string
func (*DiscordMessage) Channel ¶
func (m *DiscordMessage) Channel() string
Channel returns the channel id for this message.
func (*DiscordMessage) MatchesCommand ¶
func (m *DiscordMessage) MatchesCommand(prefix, command string) (bool, bool)
func (*DiscordMessage) Message ¶
func (m *DiscordMessage) Message() string
Message returns the message content for this message.
func (*DiscordMessage) MessageID ¶
func (m *DiscordMessage) MessageID() string
MessageID returns the message ID for this message.
func (*DiscordMessage) ParseCommand ¶
func (m *DiscordMessage) ParseCommand(prefix string) (string, []string, bool)
func (*DiscordMessage) RawMessage ¶
func (m *DiscordMessage) RawMessage() string
RawMessage returns the raw message content for this message.
func (*DiscordMessage) Type ¶
func (m *DiscordMessage) Type() MessageType
Type returns the type of message.
func (*DiscordMessage) UserAvatar ¶
func (m *DiscordMessage) UserAvatar() string
UserAvatar returns the avatar url for this message.
func (*DiscordMessage) UserID ¶
func (m *DiscordMessage) UserID() string
UserID returns the user id for this message.
func (*DiscordMessage) UserName ¶
func (m *DiscordMessage) UserName() string
UserName returns the user name for this message.
type Message ¶
type Message interface { Channel() string UserName() string UserID() string UserAvatar() string Message() string RawMessage() string MessageID() string Type() MessageType MatchesCommand(prefix, command string) (bool, bool) ParseCommand(prefix string) (string, []string, bool) }
Message is a message interface, wraps a single message from a service.
type MessageFunc ¶
MessageFunc is the function signature for a message handler.
type MessageType ¶
type MessageType string
MessageType is a type used to determine the CRUD state of a message.
type MockMessage ¶
type MockMessage struct {
// contains filtered or unexported fields
}
func NewMockMessage ¶
func NewMockMessage() *MockMessage
func (*MockMessage) Channel ¶
func (m *MockMessage) Channel() string
Satisfy Message interface below
func (*MockMessage) MatchesCommand ¶
func (m *MockMessage) MatchesCommand(prefix, command string) (bool, bool)
func (*MockMessage) Message ¶
func (m *MockMessage) Message() string
func (*MockMessage) MessageID ¶
func (m *MockMessage) MessageID() string
func (*MockMessage) ParseCommand ¶
func (m *MockMessage) ParseCommand(prefix string) (string, []string, bool)
func (*MockMessage) RawMessage ¶
func (m *MockMessage) RawMessage() string
func (*MockMessage) SetAvatar ¶
func (m *MockMessage) SetAvatar(avatar string) *MockMessage
func (*MockMessage) SetChannel ¶
func (m *MockMessage) SetChannel(channel string) *MockMessage
Functional options to set various properties
func (*MockMessage) SetMessage ¶
func (m *MockMessage) SetMessage(message string) *MockMessage
func (*MockMessage) SetMessageID ¶
func (m *MockMessage) SetMessageID(messageID string) *MockMessage
func (*MockMessage) SetRawMessage ¶
func (m *MockMessage) SetRawMessage(message string) *MockMessage
func (*MockMessage) SetUserID ¶
func (m *MockMessage) SetUserID(userid string) *MockMessage
func (*MockMessage) SetUserName ¶
func (m *MockMessage) SetUserName(username string) *MockMessage
func (*MockMessage) Type ¶
func (m *MockMessage) Type() MessageType
func (*MockMessage) UserAvatar ¶
func (m *MockMessage) UserAvatar() string
func (*MockMessage) UserID ¶
func (m *MockMessage) UserID() string
func (*MockMessage) UserName ¶
func (m *MockMessage) UserName() string
type MockService ¶
type MockService struct {
// contains filtered or unexported fields
}
Service is a service interface, wraps a single service such as YouTube or Discord.
func NewMockService ¶
func NewMockService() *MockService
func (*MockService) BanUser ¶
func (s *MockService) BanUser(channel, userID string, duration int) error
func (*MockService) ChannelCount ¶
func (s *MockService) ChannelCount() int
func (*MockService) CommandPrefix ¶
func (s *MockService) CommandPrefix() string
func (*MockService) DeleteMessage ¶
func (s *MockService) DeleteMessage(channel, messageID string) error
func (*MockService) IsBotOwner ¶
func (s *MockService) IsBotOwner(message Message) bool
func (*MockService) IsChannelOwner ¶
func (s *MockService) IsChannelOwner(message Message) bool
func (*MockService) IsMe ¶
func (s *MockService) IsMe(message Message) bool
func (*MockService) IsModerator ¶
func (s *MockService) IsModerator(message Message) bool
func (*MockService) IsPrivate ¶
func (s *MockService) IsPrivate(message Message) bool
func (*MockService) Join ¶
func (s *MockService) Join(join string) error
func (*MockService) Name ¶
func (s *MockService) Name() string
func (*MockService) NewMessage ¶
func (s *MockService) NewMessage(message Message)
func (*MockService) Open ¶
func (s *MockService) Open() (<-chan Message, error)
func (*MockService) PrivateMessage ¶
func (s *MockService) PrivateMessage(userID, messageID string) error
func (*MockService) SendAction ¶
func (s *MockService) SendAction(channel, message string) error
func (*MockService) SendFile ¶
func (s *MockService) SendFile(channel, name string, r io.Reader) error
func (*MockService) SendMessage ¶
func (s *MockService) SendMessage(channel, message string) error
func (*MockService) SetName ¶
func (m *MockService) SetName(name string) *MockService
func (*MockService) SetUserID ¶
func (m *MockService) SetUserID(userid string) *MockService
func (*MockService) SetUserName ¶
func (m *MockService) SetUserName(username string) *MockService
func (*MockService) SupportsMultiline ¶
func (s *MockService) SupportsMultiline() bool
func (*MockService) SupportsPrivateMessages ¶
func (s *MockService) SupportsPrivateMessages() bool
func (*MockService) Typing ¶
func (s *MockService) Typing(channel string) error
func (*MockService) UnbanUser ¶
func (s *MockService) UnbanUser(channel, userID string) error
func (*MockService) UserID ¶
func (s *MockService) UserID() string
func (*MockService) UserName ¶
func (s *MockService) UserName() string
type ParsedCommand ¶
type Plugin ¶
type Plugin interface { Name() string Load(*Bot, Service, []byte) error Save() ([]byte, error) Help(*Bot, Service, Message, bool) []string Message(*Bot, Service, Message) Stats(*Bot, Service, Message) []string }
Plugin is a plugin interface, supports loading and saving to a byte array and has help and message handlers.
type Service ¶
type Service interface { Name() string UserName() string UserID() string Open() (<-chan Message, error) IsMe(message Message) bool SendMessage(channel, message string) error SendAction(channel, message string) error DeleteMessage(channel, messageID string) error SendFile(channel, name string, r io.Reader) error BanUser(channel, userID string, duration int) error UnbanUser(channel, userID string) error Join(join string) error Typing(channel string) error PrivateMessage(userID, messageID string) error IsBotOwner(message Message) bool IsPrivate(message Message) bool IsChannelOwner(message Message) bool IsModerator(message Message) bool SupportsPrivateMessages() bool SupportsMultiline() bool CommandPrefix() string ChannelCount() int }
Service is a service interface, wraps a single service such as YouTube or Discord.
type SimplePlugin ¶
type SimplePlugin struct { LoadFunc LoadFunc `json:"-"` SaveFunc SaveFunc `json:"-"` MessageFunc MessageFunc `json:"-"` HelpFunc HelpFunc `json:"-"` StatsFunc StatsFunc `json:"-"` // contains filtered or unexported fields }
SimplePlugin is a simple wrapper around a Plugin that can implement handlers by function reference.
func NewSimplePlugin ¶
func NewSimplePlugin(name string) *SimplePlugin
NewSimplePlugin creates a new simple plugin.
func (*SimplePlugin) Help ¶
Help returns a list of help strings that are printed when the user requests them.
func (*SimplePlugin) Load ¶
func (p *SimplePlugin) Load(bot *Bot, service Service, data []byte) error
Load will load plugin state from a byte array.
func (*SimplePlugin) Message ¶
func (p *SimplePlugin) Message(bot *Bot, service Service, message Message)
Message handler.
func (*SimplePlugin) Name ¶
func (p *SimplePlugin) Name() string
Name returns the name of the plugin.
func (*SimplePlugin) Save ¶
func (p *SimplePlugin) Save() ([]byte, error)
Save will save plugin state to a byte array.