wetgear

package module
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2021 License: MIT Imports: 10 Imported by: 0

README

wetgear

Need a command router for discordgo? wetgear is framework for routing, and parsing discordgo messages to commands

Why the name?

wetgear kinda sounds like netgear, the company that manufactured most of my home routers, and well since this is a router, just a different kind, I figured that it was a clever name.

Where's the documentation?

I will write proper documentation when I get the time, however a quick look at the code should be suffecient for most when it comes to figuring out how to use wetgear.

Notice

This project currently in it's early stages, so be aware that some fundamental changes to how wetgear works, may change over time.

TODO
  • Use hashmaps rather than slices in Command and Router for holding commands and sub-commands
  • Write better comments and documentation for use with godoc
  • Write basic examples
  • Write unit tests
  • Add backtick argument parsing, will add when I need it for my bot.

Documentation

Index

Constants

View Source
const (
	ColorBlurple         = 0x7289DA
	ColorFullWhite       = 0xFFFFFF
	ColorDarkButNotBlack = 0x2C2F33
	ColorNotQuiteBlack   = 0x23272A
	ColorCrimson         = 0xDC143C
	ColorDarkSalmon      = 0xE9967A
	ColorLightCoral      = 0xF08080
	ColorPink            = 0xFFC0CB
	ColorHotPink         = 0xFF69B4
	ColorDeepPink        = 0xFF1493
	ColorTomato          = 0xFF6347
	ColorGold            = 0xFFD700
	ColorLemonChiffon    = 0xFFFACD
	ColorPapayawhip      = 0xFFEFD5
	ColorMoccasin        = 0xFFE4B5
	ColorDarkKhaki       = 0xBDB76B
	ColorViolet          = 0xEE82EE
	ColorMediumOrchid    = 0xBA55D3
	ColorIndigo          = 0x4B0082
	ColorSlateBlue       = 0x6A5ACD
	ColorChartreuse      = 0x7FFF00
	ColorSeaGreen        = 0x2E8B57
	ColorAqua            = 0x00FFFF
	ColorSteelBlue       = 0x4682B4
	ColorMaroon          = 0x800000
	ColorTeal            = 0x008080
	ColorMidnightBlue    = 0x191970
	ColorChocolate       = 0xD2691E
)
View Source
const (
	EmojiFastBackward  = "\u23EA"
	EmojiBackwardArrow = "\u2B05\uFE0F"
	EmojiForwardArrow  = "\u27A1\uFE0F"
	EmojiFastForward   = "\u23E9"
)

Variables

View Source
var ArgumentRegex = regexp.MustCompile(`[^" \n\r\t` + "`" + `]+|"[^"\n\r\t` + "`" + `]*"`)

Ugly as hell

View Source
var Logger *log.Logger = log.New(os.Stdout, "[WETGEAR] ", log.LstdFlags)
View Source
var MentionChannelRegex = regexp.MustCompile(`<#(?P<Identifier>\d+)>`)
View Source
var MentionCustomEmojiAnimatedRegex = regexp.MustCompile(`<a:(?P<EmojiName>\w+):(?P<Identifier>\d+)>`)
View Source
var MentionCustomEmojiRegex = regexp.MustCompile(`<:(?P<EmojiName>\w+):(?P<Identifier>\d+)>`)
View Source
var MentionRoleRegex = regexp.MustCompile(`<@&(?P<Identifier>\d+)>`)
View Source
var MentionUserNicknameRegex = regexp.MustCompile(`<@!(?P<Identifier>\d+)>`)
View Source
var MentionUserRegex = regexp.MustCompile(`<@(?P<Identifier>\d+)>`)

Functions

func ChannelMessageSendEmbedReply

func ChannelMessageSendEmbedReply(session *discordgo.Session, channelID string, embed *discordgo.MessageEmbed, reference *discordgo.MessageReference) (*discordgo.Message, error)

func CombinePermissions added in v0.0.4

func CombinePermissions(perms ...int) int

func IsMention

func IsMention(content string) bool

IsMention tests string to determine whether or not it matches any mention regular expressions

Types

type Argument

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

func ParseArguments

func ParseArguments(content string) []Argument

ParseArguments takes in an input string and parses out valid arguments for use in commands

func (Argument) Empty

func (a Argument) Empty() bool

func (Argument) GetBool

func (a Argument) GetBool() *bool

GetBool attempts to parse the argument as a bool. Upon failure, returns nil

func (Argument) GetFloat

func (a Argument) GetFloat() *float64

GetFloat attempts to parse the argument as a float64. Upon failure, returns nil

func (Argument) GetInt

func (a Argument) GetInt() *int64

GetInt attempts to parse the argument as a int64. Upon failure, returns nil

func (Argument) GetUint

func (a Argument) GetUint() *uint64

GetUint attempts to parse the argument as a uint64. Upon failure, returns nil

func (Argument) Quoted

func (a Argument) Quoted() bool

func (Argument) Raw

func (a Argument) Raw() string

func (Argument) SurroundQuotes

func (a Argument) SurroundQuotes() string

type Command

type Command struct {
	Description         string
	SubCommands         map[string]*Command
	Aliases             []string
	Name                string
	Router              *Router
	Session             *discordgo.Session
	CommandExecutor     CommandExecutor
	Middlwares          []CommandMiddleware
	RequiredPermissions int64 // Use CombinePermissions to use multiple
}

Command represents a discord command.

func NewCommand

func NewCommand(router *Router) *Command

func (*Command) AddAliases

func (c *Command) AddAliases(aliases ...string) *Command

func (*Command) AddMiddlewares added in v0.0.4

func (c *Command) AddMiddlewares(middlewares ...CommandMiddleware) *Command

func (*Command) AddSubCommand

func (c *Command) AddSubCommand(command *Command) *Command

func (*Command) SetDescription

func (c *Command) SetDescription(description string) *Command

func (*Command) SetExecutor

func (c *Command) SetExecutor(executor CommandExecutor) *Command

func (*Command) SetName

func (c *Command) SetName(name string) *Command

type CommandExecutor

type CommandExecutor func(ctx Context)

func DefaultCommandFound added in v0.0.9

func DefaultCommandFound(command *Command) CommandExecutor

func DefaultCommandNotFound added in v0.0.9

func DefaultCommandNotFound(parentCommand *Command, commandName string) CommandExecutor

type CommandFoundExecutor added in v0.0.9

type CommandFoundExecutor func(command *Command) CommandExecutor

type CommandMiddleware added in v0.0.4

type CommandMiddleware func(exe CommandExecutor) CommandExecutor

type CommandNotFoundExecutor added in v0.0.9

type CommandNotFoundExecutor func(parentCommand *Command, commandName string) CommandExecutor

type Context

type Context struct {
	MessageCreate *discordgo.MessageCreate
	Command       *Command
	Alias         string
	Arguments     []Argument
}

func (*Context) ArgumentsString

func (c *Context) ArgumentsString() string

func (*Context) GetSession

func (c *Context) GetSession() *discordgo.Session

type HelpSettings added in v0.0.9

type HelpSettings struct {
	Enabled          bool
	NotFoundExecutor CommandNotFoundExecutor
	FoundExecutor    CommandFoundExecutor
	Aliases          []string
}

HelpSettings defines the settings for the router's built-in help command.

type Mention

type Mention struct {
	MentionType MentionType
	ID          string
	EmojiName   string // The name of the emoji, if the mention is an emoji
}

Mention represents a mention

func GetMention

func GetMention(content string) *Mention

GetMention tries to make a Mention out of a string. Upon failure, return nil.

func (Mention) Stringify

func (m Mention) Stringify() string

type MentionType

type MentionType int

MentionType describes mention types

const (
	MentionUser                MentionType = 0
	MentionUserNickname        MentionType = 1
	MentionChannel             MentionType = 2
	MentionRole                MentionType = 3
	MentionCustomEmoji         MentionType = 4
	MentionCustomEmojiAnimated MentionType = 5
)

func GetMentionType

func GetMentionType(content string) MentionType

GetMentionType attempts to get the MentionType of a string, upon failure returns -1 as a MentionType

type Pagination added in v0.0.8

type Pagination struct {
	Embeds    []PaginationPage
	RepliesTo *discordgo.MessageReference
	Router    *Router
	Done      bool
	Current   uint
	ChannelID string
	MessageID string
	AuthorID  string
}

func (*Pagination) AddEmbeds added in v0.0.8

func (p *Pagination) AddEmbeds(embeds ...PaginationPage) *Pagination

func (*Pagination) SetRepliesTo added in v0.0.8

func (p *Pagination) SetRepliesTo(repliesTo *discordgo.MessageReference) *Pagination

func (*Pagination) Spawn added in v0.0.8

func (p *Pagination) Spawn() error

func (*Pagination) Update added in v0.0.8

func (p *Pagination) Update(index uint) error

type PaginationPage added in v0.0.8

type PaginationPage func() *discordgo.MessageEmbed

func EmbedToPage added in v0.0.8

func EmbedToPage(embed *discordgo.MessageEmbed) PaginationPage

type PrefixSettings

type PrefixSettings struct {
	Prefixes   []string
	IgnoreCase bool
	HandlePing bool // whether or not to treat a ping as a command prefix. Example: "@BotName help" does the same thing as "!help" if "!" is a prefix.
}

PrefixSettings defines the settings for a router's prefixes

type Router

type Router struct {
	Session          *discordgo.Session
	Commands         map[string]*Command
	PrefixSettings   PrefixSettings
	BotsAllowed      bool
	GlobalMiddlwares []CommandMiddleware
	RemoveHandlers   []func()
	HelpSettings     HelpSettings
	Paginations      struct {
		Values map[string]*Pagination
		sync.RWMutex
	}
}

Router is a command router

func NewRouter

func NewRouter(session *discordgo.Session, baseRouter *Router) (*Router, error)

NewRouter creates a *Router and configures a *discordgo.Session to work with the command system

func (*Router) AddCommand

func (r *Router) AddCommand(command *Command) *Router

func (*Router) CreatePagination added in v0.0.8

func (r *Router) CreatePagination(channelID, authorID string) *Pagination

func (*Router) GetMentions

func (r *Router) GetMentions() []string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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