handler

package module
v0.0.0-...-2543c5e Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2022 License: Apache-2.0 Imports: 12 Imported by: 0

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 issue 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

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

type AutocompleteHandler

type AutocompleteHandler func(ctx *AutocompleteContext) error

type Check

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

func CheckAllOf

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

func CheckAnyOf

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

func (Check[T]) And

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

func (Check[T]) Or

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

type Command

type Command struct {
	Name                 string
	Check                Check[*CommandContext]
	AutocompleteCheck    Check[*AutocompleteContext]
	CommandHandlers      map[string]CommandHandler
	AutocompleteHandlers map[string]AutocompleteHandler
}

type CommandContext

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

func (CommandContext) Reply

func (c CommandContext) Reply(content string) ContextReply

func (CommandContext) ReplyEmbed

func (c CommandContext) ReplyEmbed(embed discord.EmbedBuilder) ContextReply

type CommandHandler

type CommandHandler func(ctx *CommandContext) error

type Component

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

type ComponentContext

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

type ComponentHandler

type ComponentHandler func(ctx *ComponentContext) error

type ContextReply

type ContextReply struct {
	discord.MessageCreate
	Context CommandContext
}

func (ContextReply) Create

func (c ContextReply) Create() error

func (ContextReply) WithAllowedMentions

func (c ContextReply) WithAllowedMentions(allowedMentions *discord.AllowedMentions) ContextReply

func (ContextReply) WithComponents

func (c ContextReply) WithComponents(components ...discord.InteractiveComponent) ContextReply

func (ContextReply) WithContent

func (c ContextReply) WithContent(content string) ContextReply

func (ContextReply) WithEmbed

func (c ContextReply) WithEmbed(embed discord.EmbedBuilder) ContextReply

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

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

func (*Handler) OnEvent

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

type I18n

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

func (*I18n) AddLanguage

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

func (*I18n) LoadFromEmbedFS

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

func (*I18n) NewPrinter

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

type ModalContext

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

type ModalHandler

type ModalHandler func(ctx *ModalContext) error

Jump to

Keyboard shortcuts

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