Documentation
¶
Overview ¶
The Commands package both contains the CommandManager framework and the bot commands. Everything is pretty modular and can be adapted to your own use cases.
Index ¶
- Variables
- func AboutCommandFunc(ctx CommandContext, args []string) error
- func HelpCommandFunc(ctx CommandContext, args []string) error
- func InviteCommandFunc(ctx CommandContext, args []string) error
- func LoadTags(f string, log *logrus.Logger)
- func OwnerCommandFunc(ctx CommandContext, args []string) error
- func PingCommandFunc(ctx CommandContext, args []string) error
- func SuggestCommandFunc(ctx CommandContext, args []string) error
- func TagCommandFunc(ctx CommandContext, args []string) error
- func TagsCommandFunc(ctx CommandContext, _ []string) error
- func UserInfoCommandFunc(ctx CommandContext, args []string) error
- type Command
- type CommandContext
- type CommandFunc
- type CommandManager
- func (cmdm *CommandManager) AddCommand(cmd *Command)
- func (cmdm *CommandManager) AddNewCommand(name string, aliases []string, desc string, owneronly, hidden bool, ...)
- func (cmdm *CommandManager) AddPrefix(prefix string)
- func (cmdm *CommandManager) CommandHandler(s *discordgo.Session, m *discordgo.MessageCreate)
- func (cmdm *CommandManager) GetCommand(name string) (cmd *Command, exists bool, index int)
- func (cmdm *CommandManager) GetPrefixes() []string
- func (cmdm *CommandManager) IsOwner(id string) bool
- func (cmdm *CommandManager) RemoveCommand(name string)
- func (cmdm *CommandManager) RemovePrefix(prefix string)
- func (cmdm *CommandManager) SetPrefixes(prefixes []string)
- type CommandManagerOnErrorFunc
- type CommandType
Constants ¶
This section is empty.
Variables ¶
var AboutCommand = &Command{ Name: "about", Description: "Get some information about the bot", OwnerOnly: false, Hidden: false, UserPermissions: 0, BotPermissions: Shared.PermissionMessagesSend | Shared.PermissionMessagesEmbedLinks, Type: CommandTypeEverywhere, Run: AboutCommandFunc, }
var HelpCommand = &Command{ Name: "help", Aliases: []string{"h", "halp"}, Description: "Get some help with the bot.", OwnerOnly: false, Hidden: false, UserPermissions: 0, BotPermissions: Shared.PermissionMessagesSend | Shared.PermissionMessagesEmbedLinks, Type: CommandTypeEverywhere, Run: HelpCommandFunc, }
var InviteCommand = &Command{ Name: "invite", Description: "Invite Me!", OwnerOnly: false, Hidden: false, UserPermissions: 0, BotPermissions: Shared.PermissionMessagesSend | Shared.PermissionMessagesEmbedLinks, Type: CommandTypeEverywhere, Run: InviteCommandFunc, }
var OwnerCommand = &Command{ Name: "owner", Aliases: []string{"o"}, Description: "The general owner command", OwnerOnly: true, Hidden: false, UserPermissions: 0, BotPermissions: Shared.PermissionMessagesSend | Shared.PermissionMessagesEmbedLinks, Type: CommandTypeEverywhere, Run: OwnerCommandFunc, }
var PingCommand = &Command{ Name: "ping", Description: "Check if the bot is alive", OwnerOnly: false, Hidden: false, UserPermissions: 0, BotPermissions: Shared.PermissionMessagesSend, Type: CommandTypeEverywhere, Run: PingCommandFunc, }
var SuggestCommand = &Command{ Name: "suggest", Description: "Suggest a thing for the bot!", OwnerOnly: false, Hidden: false, UserPermissions: 0, BotPermissions: Shared.PermissionMessagesSend, Type: CommandTypeEverywhere, Run: SuggestCommandFunc, }
var TagCommand = &Command{ Name: "tag", Aliases: []string{"t"}, Description: "Get a tag", OwnerOnly: false, Hidden: false, UserPermissions: 0, BotPermissions: Shared.PermissionMessagesSend, Type: CommandTypeEverywhere, Run: TagCommandFunc, }
var TagsCommand = &Command{ Name: "tags", Aliases: []string{"ts"}, Description: "Get a list of tags", OwnerOnly: false, Hidden: false, UserPermissions: 0, BotPermissions: Shared.PermissionMessagesSend | Shared.PermissionMessagesEmbedLinks, Type: CommandTypeEverywhere, Run: TagsCommandFunc, }
var UserInfoCommand = &Command{ Name: "userinfo", Aliases: []string{"ui"}, Description: "Returns information about a given user", OwnerOnly: false, Hidden: false, UserPermissions: 0, BotPermissions: Shared.PermissionMessagesSend | Shared.PermissionMessagesEmbedLinks, Type: CommandTypeEverywhere, Run: UserInfoCommandFunc, }
Functions ¶
func AboutCommandFunc ¶ added in v0.16.0
func AboutCommandFunc(ctx CommandContext, args []string) error
AboutCommandFunc is a CommandRunFunc. It supplies the user who runs it information about the bot. It returns an error if any occurred.
Usage: {prefix}about
func HelpCommandFunc ¶ added in v0.16.0
func HelpCommandFunc(ctx CommandContext, args []string) error
HelpCommandFunc is a CommandRunFunc. It supplies the user a list of commands in the CommandManager it is assigned to. It returns an error if any occurred.
Usage: {prefix}help [command]
func InviteCommandFunc ¶ added in v0.16.0
func InviteCommandFunc(ctx CommandContext, args []string) error
InviteCommandFunc is a CommandRunFunc. It supplies the user an invite to the bot. It returns an error if any occurred.
Usage: {prefix}invite
func OwnerCommandFunc ¶ added in v0.16.0
func OwnerCommandFunc(ctx CommandContext, args []string) error
OwnerCommandFunc is a CommandRunFunc. It currently has no use. It returns an error if any occurred.
Usage: {prefix}owner {reloadtags|updateSuggestion}
func PingCommandFunc ¶ added in v0.16.0
func PingCommandFunc(ctx CommandContext, args []string) error
PingCommandFunc is a CommandRunFunc. It supplies the user a message if the bot is alive. It returns an error if any occurred.
Usage: {prefix}ping
func SuggestCommandFunc ¶ added in v0.16.0
func SuggestCommandFunc(ctx CommandContext, args []string) error
SuggestCommandFunc is a CommandRunFunc. It submits a suggestion to the channel specific in the config. It returns an error if any occurred.
Usage: {prefix}suggest <suggestion>
func TagCommandFunc ¶ added in v0.16.0
func TagCommandFunc(ctx CommandContext, args []string) error
TagCommandFunc is a CommandRunFunc. It supplies the user with the tag description if the tag supplied exists. It returns an error if any occurred.
Usage: {prefix}tag <tag>
func TagsCommandFunc ¶ added in v0.16.0
func TagsCommandFunc(ctx CommandContext, _ []string) error
TagsCommandFunc is a CommandRunFunc. It supplies the user with a list of the initialized tags. It returns an error if any occurred.
Usage: {prefix}tags
func UserInfoCommandFunc ¶ added in v0.16.0
func UserInfoCommandFunc(ctx CommandContext, args []string) error
UserInfoCommand is a CommandRunFunc. It supplies the user information about another user. It returns an error if any occurred.
Usage: {prefix}userinfo [user]
Types ¶
type Command ¶
type Command struct {
// The name of the command (What it will be triggered by).
Name string
// Command aliases
Aliases []string
// The command's description.
Description string
// If the command is only able to be ran by an owner.
OwnerOnly bool
// If the command is hidden from help.
Hidden bool
// The permissions the user is required to have to execute the command.
UserPermissions Shared.Permission
// The permissions the bot is required to have to execute the command.
BotPermissions Shared.Permission
// The CommandType designates where the command can be ran.
Type CommandType
// The function that will be executed whenever a message fits the criteria to execute the command.
Run CommandFunc
}
A Command represents any given command contained in a bot.
func RemoveCommandFromSlice ¶ added in v0.11.0
type CommandContext ¶
type CommandContext struct {
// The connection to Discord.
Session *discordgo.Session
// The event that fired the CommandHandler.
Event *discordgo.MessageCreate
// The CommandManager that handled this command.
Manager *CommandManager
// The bot's StatusManager.
StatusManager *Status.StatusManager
// The Message that fired this event.
Message *discordgo.Message
// The User that fired this event.
User *discordgo.User
// The Channel the event was fired in.
Channel *discordgo.Channel
// The guild the Channel belongs to.
Guild *discordgo.Guild
// The User's guild member.
Member *discordgo.Member
}
A CommandContext is passed to a CommandRunFunc. It contains the information needed for a command to execute.
func (*CommandContext) Reply ¶
func (ctx *CommandContext) Reply(message string) (*discordgo.Message, error)
Reply sends a message to the channel a CommandContext was initiated for.
func (*CommandContext) ReplyEmbed ¶
func (ctx *CommandContext) ReplyEmbed(embed *discordgo.MessageEmbed) (*discordgo.Message, error)
ReplyEmbed sends an embed to the channel a CommandContext was initiated for.
type CommandFunc ¶
type CommandFunc func(CommandContext, []string) error
A CommandFunc is ran whenever a CommandManager gets a message supposed to run the given command.
type CommandManager ¶
type CommandManager struct {
// The bot configuration
Config Configuration.Configuration
// The bot database
DB *gorm.DB
// The array of prefixes a CommandManager will respond to.
Prefixes []string
// The array of IDs that will be considered a bot owner.
Owners []string
// The bot's StatusManager.
StatusManager *Status.StatusManager
// The bot instance Logger.
Logger *logrus.Logger
// The map of Commands in the CommandManager.
Commands *[]*Command
// If the CommandManager ignores bots or not.
IgnoreBots bool
// The function that will be ran when the CommandManager encounters an error.
OnErrorFunc CommandManagerOnErrorFunc
}
A CommandManager represents a set of prefixes, owners and commands, with some extra utility to create a command handler.
func NewCommandManager ¶
func NewCommandManager(c Configuration.Configuration, db *gorm.DB, sm *Status.StatusManager, l *logrus.Logger, ignoreBots bool, errorFunc CommandManagerOnErrorFunc) CommandManager
NewCommandManager instantiates a new CommandManager. It returns a CommandManager.
func (*CommandManager) AddCommand ¶
func (cmdm *CommandManager) AddCommand(cmd *Command)
AddCommand adds an existent command to the CommandManager's command list. It returns nothing.
func (*CommandManager) AddNewCommand ¶
func (cmdm *CommandManager) AddNewCommand(name string, aliases []string, desc string, owneronly, hidden bool, userperms, botperms Shared.Permission, cmdType CommandType, run CommandFunc)
AddNewCommand adds a new command to the CommandManager's command list. It returns nothing.
func (*CommandManager) AddPrefix ¶
func (cmdm *CommandManager) AddPrefix(prefix string)
AddPrefix adds a new prefix to the CommandManager's prefix list. It returns nothing.
func (*CommandManager) CommandHandler ¶
func (cmdm *CommandManager) CommandHandler(s *discordgo.Session, m *discordgo.MessageCreate)
CommandHandler works as the CommandManager's message listener. It returns nothing.
func (*CommandManager) GetCommand ¶ added in v0.11.0
func (cmdm *CommandManager) GetCommand(name string) (cmd *Command, exists bool, index int)
func (*CommandManager) GetPrefixes ¶
func (cmdm *CommandManager) GetPrefixes() []string
GetPrefixes gets the CommandManager's prefix list. It returns a string array.
func (*CommandManager) IsOwner ¶
func (cmdm *CommandManager) IsOwner(id string) bool
IsOwner checks if a user ID is is in the owner list. It returns a bool.
func (*CommandManager) RemoveCommand ¶
func (cmdm *CommandManager) RemoveCommand(name string)
RemoveCommand removes a command from the CommandManager's command list. It returns nothing.
func (*CommandManager) RemovePrefix ¶
func (cmdm *CommandManager) RemovePrefix(prefix string)
RemovePrefix removes a prefix from the CommandManager's prefix list. It returns nothing.
func (*CommandManager) SetPrefixes ¶
func (cmdm *CommandManager) SetPrefixes(prefixes []string)
SetPrefixes sets the CommandManager's prefix list. It returns nothing.
type CommandManagerOnErrorFunc ¶
type CommandManagerOnErrorFunc func(cmdm *CommandManager, ctx CommandContext, err error)
A CommandManagerOnErrorFunc is a function that will run whenever the CommandManager encounters an error.
type CommandType ¶
type CommandType int
A CommandType represents the locations commands can be used.
const ( // A Command that is only supposed to run in a personal message CommandTypePM CommandType = iota // A command that is only supposed to run in a Guild CommandTypeGuild // A Command that is able to run anywhere CommandTypeEverywhere )