goslash

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2021 License: GPL-3.0 Imports: 7 Imported by: 1

Documentation

Index

Constants

View Source
const DISCORD_API_BASE_URL = "https://discord.com/api/v8"

Variables

This section is empty.

Functions

This section is empty.

Types

type Application

type Application struct {
	http.Client

	Commands        map[string]*Command
	AuthHeader      string
	ClientID        string
	DefaultResponse *InteractionResponse

	Session *discordgo.Session // TODO dont depend on discordgo
}

func NewApp

func NewApp(clientId, auth string) (*Application, error)

func (*Application) AddCommand

func (app *Application) AddCommand(command *Command)

func (*Application) GetCommand

func (app *Application) GetCommand(name string) *Command

func (*Application) HandleInteraction

func (app *Application) HandleInteraction(interaction *Interaction) *InteractionResponse

func (Application) PostJson

func (app Application) PostJson(path string, obj interface{}) ([]byte, error)

func (*Application) RegisterAllGlobal

func (app *Application) RegisterAllGlobal() error

func (*Application) RegisterAllGuild

func (app *Application) RegisterAllGuild(guildid string) error

func (*Application) RegisterGlobal

func (app *Application) RegisterGlobal(command *Command) (*Command, error)

func (*Application) RegisterGuild

func (app *Application) RegisterGuild(guildid string, command *Command) (*Command, error)

func (*Application) SetListener

func (app *Application) SetListener(listener Listener)

type ApplicationCommand

type ApplicationCommand struct {
	ID            string                     `json:"id"`
	ApplicationID string                     `json:"ApplicationID"`
	Name          string                     `json:"name"`
	Description   string                     `json:"description"`
	Options       []ApplicationCommandOption `json:"options"`
}

type ApplicationCommandInteractionData

type ApplicationCommandInteractionData struct {
	ID      string                                    `json:"id"`
	Name    string                                    `json:"name"`
	Options []ApplicationCommandInteractionDataOption `json:"options"`
}

type ApplicationCommandInteractionDataOption

type ApplicationCommandInteractionDataOption struct {
	Name    string                                    `json:"name"`
	Value   interface{}                               `json:"value"`
	Options []ApplicationCommandInteractionDataOption `json:"options"`
}

type ApplicationCommandOption

type ApplicationCommandOption struct {
	Type        ApplicationCommandOptionType     `json:"type"`
	Name        string                           `json:"name"`
	Description string                           `json:"description"`
	Default     bool                             `json:"default"`
	Required    bool                             `json:"required"`
	Choices     []ApplicationCommandOptionChoice `json:"choices"`
	Options     []ApplicationCommandOption       `json:"options"`
}

func Group

func Group(name, description string, options []ApplicationCommandOption) ApplicationCommandOption

func Int

func Int(name, description string, required bool) ApplicationCommandOption

func Role

func Role(name string, description string, required bool) ApplicationCommandOption

func Str

func Str(name, description string, required bool) ApplicationCommandOption

func SubCmd

func SubCmd(name, description string, options []ApplicationCommandOption) ApplicationCommandOption

func User

func User(name string, description string, required bool) ApplicationCommandOption

type ApplicationCommandOptionChoice

type ApplicationCommandOptionChoice struct {
	Name  string      `json:"name"`
	Value interface{} `json:"value"`
}

func Choice

func Choice(name string, value string) ApplicationCommandOptionChoice

type ApplicationCommandOptionType

type ApplicationCommandOptionType int
const (
	SUB_COMMAND ApplicationCommandOptionType = iota + 1
	SUB_COMMAND_GROUP
	STRING
	INTEGER
	BOOLEAN
	USER
	CHANNEL
	ROLE
)

type Command

type Command struct {
	ApplicationCommand
	// contains filtered or unexported fields
}

Command stores an ApplicationCommand and a handler and adds some helper methods

func NewCommand

func NewCommand(name, description string) *Command

func (*Command) AddCheck

func (cmd *Command) AddCheck(command CommandHandler) *Command

func (*Command) AddSubCheck

func (cmd *Command) AddSubCheck(name string, command CommandHandler) *Command

func (*Command) GetHandler

func (cmd *Command) GetHandler(name string) CommandHandler

func (*Command) Handle

func (cmd *Command) Handle(interaction *InteractionContext) *InteractionResponse

func (*Command) IsGlobal

func (cmd *Command) IsGlobal() bool

func (*Command) SetHandler

func (cmd *Command) SetHandler(command CommandHandler) *Command

func (*Command) SetOptions

func (cmd *Command) SetOptions(options ...ApplicationCommandOption) *Command

func (*Command) SetSubHandler

func (cmd *Command) SetSubHandler(name string, command CommandHandler) *Command

type CommandHandler

type CommandHandler func(interaction *InteractionContext) *InteractionResponse

type GuildMember

type GuildMember struct {
	Deaf         bool        `json:"deaf"`
	IsPending    bool        `json:"is_pending"`
	JoinedAt     time.Time   `json:"joined_at"`
	Mute         bool        `json:"mute"`
	Nick         interface{} `json:"nick"`
	Pending      bool        `json:"pending"`
	Permissions  string      `json:"permissions"`
	PremiumSince interface{} `json:"premium_since"`
	Roles        []string    `json:"roles"`
	User         *GuildUser
}

type GuildUser

type GuildUser struct {
	Username      string `json:"username"`
	PublicFlags   int    `json:"public_flags"`
	ID            string `json:"id"`
	Discriminator string `json:"discriminator"`
	Avatar        string `json:"avatar"`
}

type Interaction

type Interaction struct {
	ID        string                            `json:"id"`
	Type      InteractionType                   `json:"type"`
	ChannelID string                            `json:"channel_id"`
	Data      ApplicationCommandInteractionData `json:"data"`
	GuildID   string                            `json:"guild_id"`
	Member    *GuildMember                      `json:"member"`
	User      *GuildUser
	Token     string `json:"token"`
	Version   int    `json:"version"`
}

func (Interaction) GetUser

func (interaction Interaction) GetUser() *GuildUser

func (Interaction) IsDM

func (interaction Interaction) IsDM() bool

type InteractionApplicationCommandCallbackData

type InteractionApplicationCommandCallbackData struct {
	TTS             bool                               `json:"tts"`
	Content         string                             `json:"content"`
	Embeds          []discordgo.MessageEmbed           `json:"embeds,omitempty"`
	AllowedMentions []discordgo.MessageAllowedMentions `json:"allowed_mentions,omitempty"`
	Flags           int                                `json:"flags"`
}

type InteractionContext

type InteractionContext struct {
	*Interaction
	App *Application

	InvokedCommands []string
}

InteractionContext contains an Interaction and other relevant information handlers need

func (*InteractionContext) GetInt

func (ctx *InteractionContext) GetInt(name string) int

func (*InteractionContext) GetOption

InteractionContext.GetOption returns an ApplicationCommandInteractionDataOption from the interactions list of options

func (*InteractionContext) GetString

func (ctx *InteractionContext) GetString(name string) string

func (*InteractionContext) Respond

func (ctx *InteractionContext) Respond(response *InteractionResponse)

func (*InteractionContext) Send

type InteractionHandler

type InteractionHandler func(interaction *Interaction) *InteractionResponse

type InteractionResponse

type InteractionResponse struct {
	Type InteractionResponseType                    `json:"type"`
	Data *InteractionApplicationCommandCallbackData `json:"data,omitempty"`
}

func Acknowledge

func Acknowledge() *InteractionResponse

func Response

func Response(content string) *InteractionResponse

func (*InteractionResponse) Embed

func (*InteractionResponse) Ephemeral

func (resp *InteractionResponse) Ephemeral() *InteractionResponse

func (*InteractionResponse) KeepSource

func (resp *InteractionResponse) KeepSource() *InteractionResponse

func (*InteractionResponse) OnlyAuthor

func (resp *InteractionResponse) OnlyAuthor() *InteractionResponse

type InteractionResponseType

type InteractionResponseType int
const (
	PONG InteractionResponseType = iota + 1
	ACK
	CHANNEL_MESSAGE
	CHANNEL_MESSAGE_WITH_SOURCE
	ACK_WITH_SOURCE
)

type InteractionType

type InteractionType int
const (
	PING InteractionType = iota + 1
	APPLICATION_COMMAND
)

type Listener

type Listener interface {
	SetHandler(handler InteractionHandler)
}

a Listener handles receiving and responding to an interaction while letting an InteractionHandler decide the response some listeners supported included with goslash are lambda.Listener (for aws lambda), httplistener.Listener and gateway.Listener (for receiving interactions from the discord gateway)

Jump to

Keyboard shortcuts

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