Documentation ¶
Overview ¶
Package dbot is a flexible bot framework for creating Discord bots. TODO: unexport things that aren't used outside the package. TODO: package tests.
Index ¶
- Variables
- func FormatBotToken(t string) string
- type Argument
- func (arg *Argument) Channel(session *dgo.Session) (*dgo.Channel, error)
- func (arg *Argument) ChannelID() (string, error)
- func (arg *Argument) EmojiID() (string, error)
- func (arg *Argument) EmojiName() (string, error)
- func (arg *Argument) Float() (float64, error)
- func (arg *Argument) Int() (int, error)
- func (arg *Argument) Member(session *dgo.Session, guildID string) (*dgo.Member, error)
- func (arg *Argument) Role(session *dgo.Session, guildID string) (*dgo.Role, error)
- func (arg *Argument) RoleID() (string, error)
- func (arg *Argument) String() string
- func (arg *Argument) Type() ArgumentType
- func (arg *Argument) URL() (*url.URL, error)
- func (arg *Argument) User(session *dgo.Session) (*dgo.User, error)
- func (arg *Argument) UserID() (string, error)
- type ArgumentType
- type Arguments
- type Bot
- func (bot *Bot) AddCommands(commands ...*Command)
- func (bot *Bot) AddReactives(reactives ...*Reactive)
- func (bot *Bot) DefaultGuildConfig(guildID string) *GuildConfig
- func (bot *Bot) DefaultUserConfig(userID string) *UserConfig
- func (bot *Bot) GetCommand(name string) *Command
- func (bot *Bot) GetGuildConfig(guildID string) *GuildConfig
- func (bot *Bot) GetUserConfig(userID string) *UserConfig
- func (bot *Bot) Run() error
- type BotConfig
- type Command
- func (command *Command) AddAliases(aliases ...string) *Command
- func (command *Command) AddExamples(examples ...string) *Command
- func (command *Command) AddTags(tags ...string) *Command
- func (command *Command) SetCooldown(duration time.Duration) *Command
- func (command *Command) SetDescription(description string) *Command
- func (command *Command) SetFunc(f func(*MessageContext) error) *Command
- type Config
- type GuildConfig
- type MessageContext
- type Options
- type ReactionContext
- type Reactive
- type Storage
- type UserConfig
- type Var
- type VarFolder
Constants ¶
This section is empty.
Variables ¶
var ( // RegexChannelMention matches strings that are channel mentions. RegexChannelMention = regexp.MustCompile(`<#(\d+)>`) // RegexUserMention matches strings that are user mentions. RegexUserMention = regexp.MustCompile(`<@!?(\d+)>`) // RegexRoleMention matches strings that are role mentions. RegexRoleMention = regexp.MustCompile(`<@&(\d+)>`) // RegexEmoji matches strings that are emojis. RegexEmoji = regexp.MustCompile(`<:([a-zA-Z0-9_\-]+):(\d+)>`) )
Functions ¶
func FormatBotToken ¶
FormatBotToken ensures that a bot token begins with "Bot", as required by the Discord API.
Types ¶
type Argument ¶
type Argument struct {
// contains filtered or unexported fields
}
Argument represents a single argument in a command call.
func (*Argument) Channel ¶
Channel parses the argument and returns a pointer to a channel struct, if the argument is of the correct type.
func (*Argument) ChannelID ¶
ChannelID returns the argument as a channel ID, if the argument is of the correct type.
func (*Argument) EmojiID ¶ added in v0.4.1
EmojiID returns the argument as an emoji ID, if the argument is of the correct type.
func (*Argument) EmojiName ¶ added in v0.4.1
EmojiName returns the argument as an emoji name, if the argument is of the correct type.
func (*Argument) Float ¶
Float returns the argument as a float64, if the argument is of the correct type.
func (*Argument) Member ¶
Member parses the argument and returns a pointer to a Member struct, if the argument is of the correct type.
func (*Argument) Role ¶
Role parses the argument and returns a pointer to a Role struct, if the argument is of the correct type.
func (*Argument) RoleID ¶
RoleID returns the argument as a role ID, if the argument is of the correct type.
func (*Argument) Type ¶
func (arg *Argument) Type() ArgumentType
Type returns the type of the argument.
type ArgumentType ¶
type ArgumentType string
ArgumentType represents the argument type.
const ( ArgumentTypeString ArgumentType = "string" ArgumentTypeInt ArgumentType = "int" ArgumentTypeFloat ArgumentType = "float" ArgumentTypeURL ArgumentType = "url" ArgumentTypeChannelMention ArgumentType = "channelMention" ArgumentTypeEveryoneMention ArgumentType = "everyoneMention" ArgumentTypeUserMention ArgumentType = "userMention" ArgumentTypeRoleMention ArgumentType = "roleMention" ArgumentTypeEmoji ArgumentType = "emoji" )
type Arguments ¶
type Arguments struct { Arguments []*Argument // contains filtered or unexported fields }
Arguments represents a collection of arguments along with the raw string.
func ParseArguments ¶
ParseArguments parses a prefix-less string into a set of arguments.
type Bot ¶
type Bot struct { Name string `json:"name"` Version string `json:"version"` Description string `json:"description"` Config *BotConfig `json:"config"` Commands []*Command `json:"commands"` Reactives []*Reactive `json:"reactives"` Log loggo.Logger `json:"logger"` // contains filtered or unexported fields }
Bot represents a collection of commands.
func (*Bot) AddCommands ¶
func (*Bot) AddReactives ¶ added in v0.2.0
func (*Bot) DefaultGuildConfig ¶
func (bot *Bot) DefaultGuildConfig(guildID string) *GuildConfig
func (*Bot) DefaultUserConfig ¶
func (bot *Bot) DefaultUserConfig(userID string) *UserConfig
func (*Bot) GetCommand ¶
func (*Bot) GetGuildConfig ¶
func (bot *Bot) GetGuildConfig(guildID string) *GuildConfig
func (*Bot) GetUserConfig ¶
func (bot *Bot) GetUserConfig(userID string) *UserConfig
type BotConfig ¶
type BotConfig struct { DefaultPrefix string `json:"default_prefix"` IgnoreDMs bool `json:"ignore_dms"` IgnoreMentions bool `json:"ignore_mentions"` IgnoreCase bool `json:"ignore_prefix_case"` Guilds map[string]*GuildConfig `json:"guilds"` Users map[string]*UserConfig `json:"users"` MessageStorage map[string]*Storage `json:"message_storage"` }
type Command ¶
type Command struct { *Config Name string `json:"name"` Description string `json:"description"` Aliases []string `json:"aliases"` Examples []string `json:"usage"` Tags []string `json:"tags"` Cooldown time.Duration `json:"cooldown"` Log loggo.Logger Func func(*MessageContext) error }
func NewCommand ¶ added in v0.4.0
func (*Command) AddAliases ¶ added in v0.4.0
func (*Command) AddExamples ¶ added in v0.4.0
func (*Command) SetCooldown ¶ added in v0.4.0
func (*Command) SetDescription ¶ added in v0.4.0
type GuildConfig ¶
type MessageContext ¶ added in v0.2.0
type MessageContext struct { Arguments []*Argument Command *Command GuildConfig *GuildConfig UserConfig *UserConfig Message *dgo.Message Session *dgo.Session Response *dgo.Message Bot *Bot // Log is a pointer to ctx.Command.Log Log *loggo.Logger // contains filtered or unexported fields }
MessageContext is the context for message-related events.
func (*MessageContext) ResponseStorage ¶ added in v0.2.0
func (ctx *MessageContext) ResponseStorage() *Storage
func (*MessageContext) SetContent ¶ added in v0.2.0
func (ctx *MessageContext) SetContent(content string) error
func (*MessageContext) SetField ¶ added in v0.2.0
func (ctx *MessageContext) SetField(title, content string) error
type Options ¶
type Options struct { Name string `json:"name"` Description string `json:"description"` Version string `json:"version"` Token string `json:"token"` DefaultPrefix string `json:"default_prefix"` GetTokenFromEnvironment bool `json:"get_token_from_environment"` IgnoreDMs bool `json:"ignore_dms"` IgnoreMentions bool `json:"ignore_mentions"` IgnoreCase bool `json:"ignore_prefix_case"` LogLevel loggo.Level `json:"log_level"` }
Options provides a set of options for initialising Discord bots.
type ReactionContext ¶ added in v0.2.0
type ReactionContext struct { Reactive *Reactive BotConfig *BotConfig GuildConfig *GuildConfig UserConfig *UserConfig Storage *Storage Reaction *dgo.MessageReaction Session *dgo.Session Log *loggo.Logger Response *dgo.Message }
ReactionContext is the context for reaction-related events.
type Storage ¶
type Storage struct {
// contains filtered or unexported fields
}
func NewStorage ¶ added in v0.2.0
func NewStorage() *Storage
NewStorage returns a pointer to a properly initialised messageStorage struct.
type UserConfig ¶
type Var ¶
type Var struct { *VarFolder Key string `json:"key"` Value interface{} `json:"value"` // contains filtered or unexported fields }
Var implements a basic key-value structure that can also contain other Vars.