godiscordroute

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

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

Go to latest
Published: Oct 2, 2022 License: BSD-3-Clause Imports: 3 Imported by: 0

README

godiscourdrote

A basic wrapper for godiscord. Adds gorilla mux like syntax for godiscord application commands. The goal of the project is to mimic the gorilla mux syntax. If you are familiar with the gorilla mux syntax, this project should feel instantly familiar to you.

Early Alpha

Example

import(
    discord "github.com/wheelbarrow777/godiscordroute"
)

func loggingMiddlewareTwo(next discord.Handler) discord.Handler {
	return discord.HandlerFunc(func(s *discordgo.Session, i *discordgo.InteractionCreate) {
        // Do stuff here
        log.Println(r.RequestURI)
        // Call the next handler, which can be another middleware in the cain, or the final handler.
		next.Respond(s, i)
	})
}


cmd := discord.NewCommand().SetHandler(
		discord.HandlerFunc(func(s *discordgo.Session, i *discordgo.InteractionCreate) {
			s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
				Type: discordgo.InteractionResponseChannelMessageWithSource,
				Data: &discordgo.InteractionResponseData{
					Content: "hey there, binding works. Emoji? :smiley:",
				},
			})
		}),
	    ).AddMiddleware(loggingMiddlewareTwo).
		SetApplicationCmd(discordgo.ApplicationCommand{
			Name:        "binding-command",
			Description: "A basic binding command",
		}).Build()

binding, err := discord.NewBinding("guildid", "bottoken")
if err != nil {
    panic(err)
}
binding.AddCommand(cmd)

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCommandAlreadyExist = errors.New("command already exist")
	ErrCommandDoesNotExist = errors.New("command doesn't exist")
)

Functions

func Error

func Error(s *discordgo.Session, i *discordgo.InteractionCreate, errorMsg string)

func ErrorUpdate

func ErrorUpdate(s *discordgo.Session, i *discordgo.InteractionCreate, errorMsg string)

func SimpleMessage

func SimpleMessage(s *discordgo.Session, i *discordgo.InteractionCreate, msg string)

func SimpleUpdateMessage

func SimpleUpdateMessage(s *discordgo.Session, i *discordgo.InteractionCreate, msg string)

Types

type CommandBuilder

type CommandBuilder interface {
	SetHandler(Handler) CommandBuilder
	SetApplicationCmd(cmd discordgo.ApplicationCommand) CommandBuilder
	AddMiddleware(MiddlewareFunc) CommandBuilder
	AddPermission(permission discordgo.ApplicationCommandPermissions) CommandBuilder
	SetOptions(opts DiscordCommandOptions) CommandBuilder
	AddSubcommand(cmd DiscordCommad) CommandBuilder
	Build() DiscordCommad
}

func NewCommand

func NewCommand() CommandBuilder

type DiscordBinding

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

func NewBinding

func NewBinding(guild string, token string) (*DiscordBinding, error)

func (*DiscordBinding) AddCommand

func (b *DiscordBinding) AddCommand(cmd DiscordCommad) error

func (*DiscordBinding) DeleteAllCommands

func (b *DiscordBinding) DeleteAllCommands() error

type DiscordCommad

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

func (*DiscordCommad) AddMiddleware

func (dc *DiscordCommad) AddMiddleware(middleware MiddlewareFunc) CommandBuilder

func (*DiscordCommad) AddPermission

func (*DiscordCommad) AddSubcommand

func (dc *DiscordCommad) AddSubcommand(cmd DiscordCommad) CommandBuilder

func (*DiscordCommad) Build

func (dc *DiscordCommad) Build() DiscordCommad

func (*DiscordCommad) SetApplicationCmd

func (dc *DiscordCommad) SetApplicationCmd(cmd discordgo.ApplicationCommand) CommandBuilder

func (*DiscordCommad) SetHandler

func (dc *DiscordCommad) SetHandler(handler Handler) CommandBuilder

func (*DiscordCommad) SetOptions

func (dc *DiscordCommad) SetOptions(opts DiscordCommandOptions) CommandBuilder

type DiscordCommandOptions

type DiscordCommandOptions struct {
	KeepExistingPermissions bool
}

type Handler

type Handler interface {
	Respond(s *discordgo.Session, i *discordgo.InteractionCreate, opts AppCmdOptions)
}

func AckMiddleware

func AckMiddleware(next Handler) Handler

type HandlerFunc

type HandlerFunc func(s *discordgo.Session, i *discordgo.InteractionCreate, opts AppCmdOptions)

func (HandlerFunc) Respond

type MiddlewareFunc

type MiddlewareFunc func(Handler) Handler

func (MiddlewareFunc) Middleware

func (mw MiddlewareFunc) Middleware(handler Handler) Handler

Jump to

Keyboard shortcuts

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