gourd

package module
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2020 License: MIT Imports: 6 Imported by: 0

README

Gourd

A bot wrapper, command handler, and listener manager for the Disgord library

Please Note: Gourd is in active development, so documentation, examples, and the wiki isn't always going to be up-to-date.

For a quick usage example, see the examples folder. For the moment, it covers creating a Gourd wrapper, and registering a module with commands. The wiki will be created soon(tm) and will cover all facets of Gourd in detail.

I do not have a dedicated discord server to support this project [yet?] but I can be found on the official unofficial DiscordAPI server, and reached via DM at Salmonllama#5727.

Important things to note:
  • When creating commands, the first alias always becomes the command name
  • If a command is used without aliases supplied, Gourd will provide an empty slice
  • If a user is an administrator, it is only accounted for when using a PermissionInhibitor.
TODO:
  • Built-in SQLite database (very high priority)
  • Guild-based prefixes (very high priority)
  • User/Guild blacklists (I-don't-even-know-if-this-is-needed priority)
  • Option to include built-in modules. Would include:
    • Help command (meh)
    • Prefix management (high)
    • blacklist management (see blacklist priority)

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Console = ConsoleLogger{}

Functions

This section is empty.

Types

type ArgType

type ArgType int
const (
	TextArg    ArgType = iota // 0
	NumericArg                // 1
	EmojiArg                  // 2
)

type Argument

type Argument struct {
	Name         string
	Descriptor   string
	Type         ArgType
	IsOptional   bool
	UseRemainder bool
	IsQuoted     bool
	Default      string
}

type ArgumentError

type ArgumentError struct {
	Arguments []Argument
}

func (*ArgumentError) Error

func (argError *ArgumentError) Error() string

type Command

type Command struct {
	Name        string
	Description string
	Aliases     []string
	Inhibitor   interface{}
	Arguments   []Argument // Can be nil -> no arguments required
	Private     bool
	Run         func(ctx CommandContext)
}

type CommandContext

type CommandContext struct {
	Prefix        string
	Args          []string
	CommandString string
	Message       *disgord.Message
	Client        *disgord.Client
	Gourd         *Gourd
	Command       *Command
}

func (*CommandContext) Author

func (ctx *CommandContext) Author() *disgord.User

func (*CommandContext) AuthorMember

func (ctx *CommandContext) AuthorMember() *disgord.Member

func (*CommandContext) Guild

func (ctx *CommandContext) Guild() (*disgord.Guild, error)

func (*CommandContext) IsAuthorOwner

func (ctx *CommandContext) IsAuthorOwner() bool

func (*CommandContext) IsPrivate

func (ctx *CommandContext) IsPrivate() bool

func (*CommandContext) Reply

func (ctx *CommandContext) Reply(data ...interface{}) (*disgord.Message, error)

Reply sends a message to the channel the command was used in. Input is any type, see https://github.com/andersfylling/disgord/blob/39ba986ca2e94602ce44f4bf7625063124bdc325/client.go#L705

type ConsoleLogger

type ConsoleLogger struct{}

func (ConsoleLogger) Debug

func (ConsoleLogger) Debug(m ...interface{})

func (ConsoleLogger) Err

func (ConsoleLogger) Err(m ...interface{})

func (ConsoleLogger) Info

func (ConsoleLogger) Info(m ...interface{})

type Gourd

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

func New

func New(token string, ownerId string, defaultPrefix string) *Gourd

New creates a new instance of Gourd

func (*Gourd) AddKeyword

func (bot *Gourd) AddKeyword(userId string, keyword string)

AddKeyword adds a keyword permission to the given user. This keyword is stored in runtime memory and used in the KeywordInhibitor

func (*Gourd) AddModule

func (bot *Gourd) AddModule(mdl *Module) *Gourd

func (*Gourd) AddModules

func (bot *Gourd) AddModules(modules ...*Module) *Gourd

func (*Gourd) Connect

func (bot *Gourd) Connect() error

Connect opens the connection to discord

func (*Gourd) HasKeyword

func (bot *Gourd) HasKeyword(userId string, keyword string) bool

HasKeyword checks if the user has the given keyword. This is automatically checked by the KeywordInhibitor.

type Handler

type Handler struct {
	Commands  []*Command
	Listeners []*ListenerHandler
	Modules   []*Module
}

func (*Handler) AddModule

func (handler *Handler) AddModule(mdl *Module) *Module

func (*Handler) GetCommandMap

func (handler *Handler) GetCommandMap() map[string]*Command

func (*Handler) GetModuleMap

func (handler *Handler) GetModuleMap() map[string]*Module

type KeywordInhibitor

type KeywordInhibitor struct {
	Value    string
	Response interface{}
}

KeywordInhibitor allows command usage if the user has the given keyword. Value is the string keyword they should be assigned to. See <wiki link here> for keyword how-tos

type Listener

type Listener struct {
	Type        string
	Middlewares []MiddlewareHandler
	OnEvent     func(session disgord.Session, event struct{})
}

Listener is the Gourd implementation of event handlers. Type is a required field, and it is suggested to use disgord supplied events (ex: disgord.EvtMessageCreate). OnEvent is the handler function, and takes an interface that should be cast appropriately (ex: event.(*disgord.MessageCreate) ).

type ListenerHandler

type ListenerHandler interface {
	OnEvent(disgord.Session, interface{})
}

type Logger

type Logger interface {
	Debug(m ...interface{})
	Info(m ...interface{})
	Err(m ...interface{})
}

type Middleware

type Middleware struct{}

Middleware is the Gourd representation of Disgord Middlewares

type MiddlewareHandler

type MiddlewareHandler interface {
	// contains filtered or unexported methods
}

type Module

type Module struct {
	Name        string
	Description string
	Commands    []*Command
	Listeners   []*ListenerHandler
}

func (*Module) AddCommand

func (module *Module) AddCommand(cmd *Command) *Module

func (*Module) AddCommands

func (module *Module) AddCommands(cmds ...*Command) *Module

func (*Module) AddListener

func (module *Module) AddListener(l *ListenerHandler) *Module

func (*Module) AddListeners

func (module *Module) AddListeners(l ...*ListenerHandler) *Module

func (*Module) NewCommand

func (module *Module) NewCommand(aliases ...string) *Command

type NilInhibitor

type NilInhibitor struct{}

NilInhibitor allows command usage no matter what. Does not have a value or a response

type OwnerInhibitor

type OwnerInhibitor struct {
	Response interface{}
}

OwnerInhibitor allows command usage only if the user is the bot owner. Does not have a value; the owner ID is supplied in Gourd initialization.

type PermissionInhibitor

type PermissionInhibitor struct {
	Value    uint64
	Response interface{}
}

PermissionInhibitor allows command usage if the user has the permission bit (value). Value is the disgord.PermissionBit. It is recommended to use disgord.PermissionBlahBlah. This inhibitor will not work in private messages as there are no permissions.

type RoleInhibitor

type RoleInhibitor struct {
	Value    string
	Response interface{}
}

RoleInhibitor allows command usage if the user has the role (value). Value is the string ID of the role, **NOT the snowflake!**. This inhibitor will not work in private messages as there are no roles.

Directories

Path Synopsis
_examples

Jump to

Keyboard shortcuts

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