dcommand

package
v1.12.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 21, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	String      = &StringArg{}
	Int         = &IntArg{}
	User        = &UserArg{}
	Member      = &MemberArg{}
	Bet         = &BetArg{}
	Duration    = &DurationArg{}
	Coin        = &CoinArg{}
	UserBalance = &BalanceArg{}
)
View Source
var (
	CategoryGeneral = CommandCategory{
		Name:        "General",
		Description: "General bot commands",
	}
	CategoryOwner = CommandCategory{
		Name:        "Owner",
		Description: "Mainanance and other bot-owner commands",
	}
	CategoryEconomy = CommandCategory{
		Name:        "Economy",
		Description: "Gambling and other economy based commands",
	}
	CategoryModeration = CommandCategory{
		Name:        "Moderation",
		Description: "Moderation and guild safety",
	}
)

Functions

This section is empty.

Types

type Arg

type Arg struct {
	Name     string
	Type     ArgumentType
	Optional bool
}

Arg defines the structure to pass argument data with

type ArgumentType

type ArgumentType interface {
	ValidateArg(arg *ParsedArg, data *Data) bool
	Help() string
}

type BalanceArg

type BalanceArg struct{}

func (*BalanceArg) Help

func (b *BalanceArg) Help() string

func (*BalanceArg) ValidateArg

func (b *BalanceArg) ValidateArg(arg *ParsedArg, data *Data) bool

type BetArg

type BetArg struct {
	Min int64
	Max int64
}

func (*BetArg) Help

func (b *BetArg) Help() string

func (*BetArg) ValidateArg

func (b *BetArg) ValidateArg(arg *ParsedArg, data *Data) bool

type CoinArg

type CoinArg struct{}

func (*CoinArg) Help

func (c *CoinArg) Help() string

func (*CoinArg) ValidateArg

func (c *CoinArg) ValidateArg(arg *ParsedArg, data *Data) bool

type CommandCategory

type CommandCategory struct {
	Name        string
	Description string
}

CommandCategory defines the available category types for commands

type CommandHandler

type CommandHandler struct {
	// contains filtered or unexported fields
}

CommandHandler defines the general command handler, the full instances of a command and a string map to retireve them

var CmdHndlr *CommandHandler

func NewCommandHandler

func NewCommandHandler() *CommandHandler

NewCommandHandler creates a new command handler

func (*CommandHandler) HandleMessageCreate

func (c *CommandHandler) HandleMessageCreate(s *discordgo.Session, event *discordgo.MessageCreate)

Handles all message create events to the bot, to pass them to child functions

func (*CommandHandler) RegisterCommands

func (c *CommandHandler) RegisterCommands(cmds ...*SummitCommand)

RegisterCommands adds each command to the command handler

func (*CommandHandler) RegisteredCommands

func (c *CommandHandler) RegisteredCommands() map[string]RegisteredCommand

RegisteredCommands returns an array of each RegisteredCommand

type Data

type Data struct {
	Session *discordgo.Session

	GuildID   string
	ChannelID string
	Author    *discordgo.User

	Message    *discordgo.Message
	ParsedArgs []*ParsedArg

	Handler *CommandHandler
}

Data defines the required data passed to each command

type DurationArg

type DurationArg struct{}

func (*DurationArg) Help

func (d *DurationArg) Help() string

func (*DurationArg) ValidateArg

func (d *DurationArg) ValidateArg(arg *ParsedArg, data *Data) bool

type IntArg

type IntArg struct {
	Min int64
	Max int64
}

func (*IntArg) Help

func (i *IntArg) Help() string

func (*IntArg) ValidateArg

func (i *IntArg) ValidateArg(arg *ParsedArg, data *Data) bool

type MemberArg

type MemberArg struct{}

func (*MemberArg) Help

func (m *MemberArg) Help() string

func (*MemberArg) ValidateArg

func (m *MemberArg) ValidateArg(arg *ParsedArg, data *Data) bool

type ParsedArg

type ParsedArg struct {
	Name  string
	Type  ArgumentType
	Value interface{} // raw value provided by the user
}

ParsedArg represents a single argument parsed from a command invocation. Each argument contains its name, expected type, and the supplied value.

func (*ParsedArg) BalanceType

func (p *ParsedArg) BalanceType() string

BalanceType returns the argument's lowercase string value, trimmed of whitespace. Used for commands that expect a balance source argument such as "bank" or "cash".

func (*ParsedArg) BetAmount

func (p *ParsedArg) BetAmount() string

BetAmount returns the argument's lowercase string value, trimmed of any surrounding whitespace. Typically used for betting-related arguments (e.g., "all", "half", or a specific amount).

func (*ParsedArg) Coin

func (p *ParsedArg) Coin() string

Coin returns the argument's lowercase string value, trimmed of whitespace. Used for commands that require a coin flip guess, e.g., "heads" or "tails".

func (*ParsedArg) Duration

func (p *ParsedArg) Duration() *time.Duration

Duration attempts to parse the argument into a time.Duration pointer. Returns nil if parsing fails or if the argument has no value.

func (*ParsedArg) Int64

func (p *ParsedArg) Int64() int64

Int64 converts and returns the argument's value as an int64. If the value is nil or non-numeric, it safely returns 0.

func (*ParsedArg) Member

func (p *ParsedArg) Member(guildID string) *discordgo.Member

Member attempts to resolve the argument into a Discord guild member. If the value is nil or resolution fails, it returns nil.

func (*ParsedArg) String

func (p *ParsedArg) String() string

String returns the argument's string representation. It safely converts the underlying value to a string, supporting primitive numeric types.

func (*ParsedArg) User

func (p *ParsedArg) User() *discordgo.User

User attempts to resolve the argument into a Discord user. If the value is nil or resolution fails, it returns nil.

type RegisteredCommand

type RegisteredCommand struct {
	Trigger     string
	Category    CommandCategory
	Aliases     []string
	Description string
	Args        []*Arg
}

RegisteredCommand defines the context required to access data surrounding a command

type Run

type Run func(data *Data)

type StringArg

type StringArg struct{}

func (*StringArg) Help

func (s *StringArg) Help() string

func (*StringArg) ValidateArg

func (s *StringArg) ValidateArg(arg *ParsedArg, data *Data) bool

type SummitCommand

type SummitCommand struct {
	Command      string
	Category     CommandCategory
	Aliases      []string
	Description  string
	ArgsRequired int
	Args         []*Arg
	Run          Run
	Data         *Data
}

SummitCommand defines the general data that must be set during the addition of a new command

type UserArg

type UserArg struct{}

func (*UserArg) Help

func (u *UserArg) Help() string

func (*UserArg) ValidateArg

func (u *UserArg) ValidateArg(arg *ParsedArg, data *Data) bool

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL