Documentation ¶
Index ¶
- Constants
- Variables
- func CommandHelp(service Discord, command, arguments, help string) []string
- func MatchesCommand(service Discord, commandString string, message DiscordMessage) bool
- func MatchesCommandString(service Discord, commandString string, private bool, message string) bool
- func ParseCommand(service Discord, message DiscordMessage) (string, []string)
- func ParseCommandString(service Discord, 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 Discord, message DiscordMessage, detailed bool) []string
- func (p *CommandPlugin) Load(bot *Bot, service Discord, data []byte) error
- func (p *CommandPlugin) Message(bot *Bot, service Discord, message DiscordMessage)
- func (p *CommandPlugin) Name() string
- func (p *CommandPlugin) Save() ([]byte, error)
- 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) GetRoleByName(channel, roleName string) *discordgo.Role
- func (d *Discord) GetRoles(channel string) []*discordgo.Role
- func (d *Discord) Guild(guildID string) (guild *discordgo.Guild, err error)
- func (d *Discord) GuildLeave(guildID string) (err error)
- func (d *Discord) GuildMemberRoleAdd(guild, user, role string) bool
- func (d *Discord) GuildMemberRoleRemove(guild, user, role string) bool
- func (d *Discord) Guilds() []*discordgo.Guild
- func (d *Discord) IsBotOwner(message DiscordMessage) bool
- func (d *Discord) IsChannelOwner(message DiscordMessage) bool
- func (d *Discord) IsMe(message DiscordMessage) bool
- func (d *Discord) IsModerator(message DiscordMessage) bool
- func (d *Discord) IsPrivate(message DiscordMessage) bool
- func (d *Discord) Join(join string) error
- func (d *Discord) MessageHistory(channel string) []*DiscordMessage
- func (d *Discord) Name() string
- func (d *Discord) Nickname(message DiscordMessage) string
- func (d *Discord) NicknameForID(userID, userName, channelID string) string
- func (d *Discord) Open() (<-chan *DiscordMessage, 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) SupportsMessageHistory() bool
- 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) 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
- func (d *Discord) UserRoles(guild, memberID string) []string
- type DiscordMessage
- func (m DiscordMessage) Channel() string
- func (m DiscordMessage) Message() string
- func (m DiscordMessage) MessageID() string
- 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 MessageFunc
- type MessageType
- type Plugin
- type SaveFunc
- 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.11"
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 ¶
func MatchesCommand(service Discord, commandString string, message DiscordMessage) bool
MatchesCommand returns true if a message matches a command.
func MatchesCommandString ¶
MatchesCommandString returns true if a message matches a command. Commands will be matched ignoring case with a prefix if they are not private messages.
func ParseCommand ¶
func ParseCommand(service Discord, message DiscordMessage) (string, []string)
ParseCommand parses a message.
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) MessageRecover ¶
MessageRecover is the default panic handler
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 ¶
type CommandHelpFunc func(bot *Bot, service Discord, message DiscordMessage) (string, string)
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 Discord, message DiscordMessage, 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 ¶
func (p *CommandPlugin) Help(bot *Bot, service Discord, message DiscordMessage, detailed bool) []string
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 Discord, data []byte) error
Load will load plugin state from a byte array.
func (*CommandPlugin) Message ¶
func (p *CommandPlugin) Message(bot *Bot, service Discord, message DiscordMessage)
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 { Shards int // 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) GetRoleByName ¶
GetRoleByName returns the Discord role for the given role name
func (*Discord) GuildLeave ¶
GuildLeave leaves a Guild. guildID : The ID of a Guild
func (*Discord) GuildMemberRoleAdd ¶
GuildMemberRoleAdd gives a guild member a role
func (*Discord) GuildMemberRoleRemove ¶
GuildMemberRoleRemove takes a guild member's role
func (*Discord) IsBotOwner ¶
func (d *Discord) IsBotOwner(message DiscordMessage) bool
IsBotOwner returns whether or not a message sender was the owner of the bot.
func (*Discord) IsChannelOwner ¶
func (d *Discord) IsChannelOwner(message DiscordMessage) bool
IsChannelOwner returns whether or not the sender of a message is a moderator.
func (*Discord) IsMe ¶
func (d *Discord) IsMe(message DiscordMessage) bool
IsMe returns whether or not a message was sent by the bot.
func (*Discord) IsModerator ¶
func (d *Discord) IsModerator(message DiscordMessage) bool
IsModerator returns whether or not the sender of a message is a moderator.
func (*Discord) IsPrivate ¶
func (d *Discord) IsPrivate(message DiscordMessage) bool
IsPrivate returns whether or not a message was private.
func (*Discord) Join ¶
Join accept an invite or return an error. If AlreadyJoinedError is return, @me has already accepted that invite.
func (*Discord) MessageHistory ¶
func (d *Discord) MessageHistory(channel string) []*DiscordMessage
MessageHistory returns the message history for a channel.
func (*Discord) Nickname ¶
func (d *Discord) Nickname(message DiscordMessage) string
Nickname gets the nickname of the speaker of a message
func (*Discord) NicknameForID ¶
NicknameForID gets the nickname of the given user
func (*Discord) Open ¶
func (d *Discord) Open() (<-chan *DiscordMessage, error)
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) SupportsMessageHistory ¶
SupportsMessageHistory returns if the service supports message history.
func (*Discord) SupportsMultiline ¶
SupportsMultiline returns whether the service supports multiline messages.
func (*Discord) SupportsPrivateMessages ¶
SupportsPrivateMessages returns whether the service supports private messages.
func (*Discord) UserChannelPermissions ¶
UserChannelPermissions gets the bits for the user's permissions
type DiscordMessage ¶
type DiscordMessage struct { Discord *Discord DiscordgoMessage *discordgo.Message MessageType MessageType Nick *string Content *string }
DiscordMessage is a Message wrapper around discordgo.Message.
func (DiscordMessage) Channel ¶
func (m DiscordMessage) Channel() string
Channel returns the channel id for this message.
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) 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 HelpFunc ¶
type HelpFunc func(*Bot, Discord, DiscordMessage, bool) []string
HelpFunc is the function signature for a help handler.
type MessageFunc ¶
type MessageFunc func(*Bot, Discord, DiscordMessage)
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 Plugin ¶
type Plugin interface { Name() string Load(*Bot, Discord, []byte) error Save() ([]byte, error) Help(*Bot, Discord, DiscordMessage, bool) []string Message(*Bot, Discord, DiscordMessage) }
Plugin is a plugin interface, supports loading and saving to a byte array and has help and message handlers.