handler

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2022 License: Apache-2.0 Imports: 13 Imported by: 3

README

Go Reference Go Report Go Version License Handler Version Discord

Handler

Handler is a simple Application Command, Component and Modal handler library for DisGo.

Getting Started

Installing
go get github.com/disgoorg/handler
Usage

See the example here.

Documentation

Documentation is wip and can be found under

  • Go Reference

Troubleshooting

For help feel free to open an issues or reach out on Discord

Contributing

Contributions are welcomed but for bigger changes we recommend first reaching out via Discord or create an issue to discuss your problems, intentions and ideas.

License

Distributed under the License. See LICENSE for more information.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AutocompleteContext added in v0.2.0

type AutocompleteContext struct {
	*events.AutocompleteInteractionCreate
	Printer *message.Printer
}

type AutocompleteHandler

type AutocompleteHandler func(ctx *AutocompleteContext) error

type Check added in v0.2.0

type Check[T any] func(ctx T) bool

func CheckAllOf added in v0.2.0

func CheckAllOf[T any](checks ...Check[T]) Check[T]

func CheckAnyOf added in v0.2.0

func CheckAnyOf[T any](checks ...Check[T]) Check[T]

func (Check[T]) And added in v0.2.0

func (c Check[T]) And(check Check[T]) Check[T]

func (Check[T]) Or added in v0.2.0

func (c Check[T]) Or(check Check[T]) Check[T]

type Command

type Command struct {
	Create               discord.ApplicationCommandCreate
	Check                Check[*CommandContext]
	AutocompleteCheck    Check[*AutocompleteContext]
	CommandHandlers      map[string]CommandHandler
	AutocompleteHandlers map[string]AutocompleteHandler
}

type CommandContext added in v0.2.0

type CommandContext struct {
	*events.ApplicationCommandInteractionCreate
	Printer *message.Printer
}

type CommandHandler

type CommandHandler func(ctx *CommandContext) error

type Component

type Component struct {
	Name    string
	Check   Check[*ComponentContext]
	Handler ComponentHandler
}

type ComponentContext added in v0.2.0

type ComponentContext struct {
	*events.ComponentInteractionCreate
	Printer *message.Printer
	Args    []string
}

type ComponentHandler

type ComponentHandler func(ctx *ComponentContext) error

type Handler

type Handler struct {
	Logger     log.Logger
	I18n       *I18n
	NewCtxFunc func() context.Context

	Commands   map[string]Command
	Components map[string]Component
	Modals     map[string]Modal
}

func New

func New(logger log.Logger) *Handler

func (*Handler) AddCommands

func (h *Handler) AddCommands(commands ...Command)

func (*Handler) AddComponents

func (h *Handler) AddComponents(components ...Component)

func (*Handler) AddModals

func (h *Handler) AddModals(modals ...Modal)

func (*Handler) InitI18n added in v0.2.0

func (h *Handler) InitI18n(fallbackLocale language.Tag)

func (*Handler) OnEvent

func (h *Handler) OnEvent(event bot.Event)

func (*Handler) SyncCommands

func (h *Handler) SyncCommands(client bot.Client, guildIDs ...snowflake.ID)

type I18n added in v0.2.0

type I18n struct {
	Logger  log.Logger
	Catalog *catalog.Builder
}

func (*I18n) AddLanguage added in v0.2.0

func (i *I18n) AddLanguage(lang language.Tag, basePath string, data map[string]interface{})

func (*I18n) LoadFromEmbedFS added in v0.2.0

func (i *I18n) LoadFromEmbedFS(fs embed.FS, dir string) error

func (*I18n) NewPrinter added in v0.2.0

func (i *I18n) NewPrinter(locale discord.Locale) *message.Printer
type Modal struct {
	Name    string
	Check   Check[*ModalContext]
	Handler ModalHandler
}

type ModalContext added in v0.2.0

type ModalContext struct {
	*events.ModalSubmitInteractionCreate
	Printer *message.Printer
	Args    []string
}

type ModalHandler

type ModalHandler func(ctx *ModalContext) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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