dgcobra

package module
v0.0.0-...-d00b316 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2021 License: GPL-3.0 Imports: 8 Imported by: 2

README

dgcobra

GoDoc Go Report Card

Cobra based command router for discordgo

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidCommand = errors.New("error: invalid command")
)

Functions

This section is empty.

Types

type Buffer

type Buffer struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func (*Buffer) Append

func (b *Buffer) Append(s string)

func (*Buffer) Clear

func (b *Buffer) Clear()

func (*Buffer) Flush

func (b *Buffer) Flush() string

type BufferedMessageWriter

type BufferedMessageWriter struct {
	sync.RWMutex
	Session *discordgo.Session
	Channel string
	// contains filtered or unexported fields
}

func NewBufferedMessageWriter

func NewBufferedMessageWriter(session *discordgo.Session, channel string) *BufferedMessageWriter

func (*BufferedMessageWriter) Flush

func (w *BufferedMessageWriter) Flush() (n int, err error)

func (*BufferedMessageWriter) Write

func (w *BufferedMessageWriter) Write(b []byte) (n int, err error)

type ErrorInvalidArgs

type ErrorInvalidArgs struct {
	Session *discordgo.Session
	Event   *discordgo.MessageCreate
	Message string
	Err     error
}

ErrorInvalidArgs indicates invalid arguments were passed in a command. You can call Unwrap() to get the underlying error.

func (ErrorInvalidArgs) Error

func (err ErrorInvalidArgs) Error() string

func (ErrorInvalidArgs) Unwrap

func (err ErrorInvalidArgs) Unwrap() error

Unwrap returns the underlying error behind ErrorInvalidArgs.

type Handler

type Handler struct {
	// Root command factory for the bot. This needs to be set.
	RootFactory func(session *discordgo.Session, event *discordgo.MessageCreate) *cobra.Command

	// List of global prefixes for the bot.
	Prefixes []string
	// Function to load prefixes for a specific message. Use this to allow guild-specific prefixes.
	PrefixFunc func(session *discordgo.Session, event *discordgo.MessageCreate) []string
	// If the prefix function returns a list of prefixes, do these override the global list or append to it?
	PrefixFuncOverridesGlobals bool
	// Function that is called when the message event errors for some reason.
	ErrFunc func(err error)
	// Implement your own writer. Uses a BufferedMessageWriter by default. This is used for example by usage functions.
	OutWriterFactory func(s *discordgo.Session, channel string) io.Writer
	// contains filtered or unexported fields
}

Handler represents a dgcobra Command Handler. This builds upon a RootCommandFactory.

To use this, use NewHandler() and add a prefix and a root command factory. Then call Handler.Start(). Examples in examples folder of this repository.

func NewHandler

func NewHandler(session *discordgo.Session) *Handler

NewHandler creates a new handler with a given session.

func (*Handler) AddPrefix

func (h *Handler) AddPrefix(prefix string)

AddPrefix registers a new global Prefix

func (*Handler) Start

func (h *Handler) Start()

Start registers a new handler with discordgo and starts receiving commands. This function is non-blocking.

type MessageWriter

type MessageWriter struct {
	Session *discordgo.Session
	Channel string
}

MessageWriter is a writer implementation for a discord channel. This is used for example by cobra to output usage and help.

func NewMessageWriter

func NewMessageWriter(session *discordgo.Session, channel string) *MessageWriter

NewMessageWriter creates a message writer based on a given session and channel. Each write calls ChannelMessageSend on the session.

func (*MessageWriter) Write

func (w *MessageWriter) Write(b []byte) (n int, err error)

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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