discord

package
v0.0.0-...-7354109 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const ConfigurationKey = "discord"

Variables

Functions

func GenerateOAuthURL

func GenerateOAuthURL(id string) string

func LogSessionEvents

func LogSessionEvents(s *discordgo.Session)

func NewDiscordSession

func NewDiscordSession(p NewSessionParams) (*discordgo.Session, error)

func ParseToken

func ParseToken(t string) (string, error)

ParseToken parses the oauth id out of the bot token

func RegisterCommands

func RegisterCommands(p RegisterCommandsParams) error

Types

type ApplicationCommandWithHandler

type ApplicationCommandWithHandler struct {
	Command discordgo.ApplicationCommand
	Handler HandlerFunc
	// TODO (cthompson) a bit of a hack right now, these should probably be their own type
	MessageComponent bool
	GuildID          string
}

ApplicationCommandWithHandler is a top level Command with a Handler function. Subcommands are TODO todo: define our own handler func? want to use channels to post back messages.

type Channel

type Channel string

Channel represents a Channel ID or Channel URL in the config.

func (*Channel) UnmarshalYAML

func (c *Channel) UnmarshalYAML(unmarshal func(interface{}) error) error

type ConfigParams

type ConfigParams struct {
	fx.In
	Config config.Provider
}

type DiscordConfig

type DiscordConfig struct {
	ApplicationID string           `yaml:"application_id"`
	Token         string           `yaml:"token"`
	Intent        discordgo.Intent `yaml:"intent"`
}

func NewConfig

func NewConfig(p ConfigParams) (cfg DiscordConfig, err error)

type Guild

type Guild string

Guild represents a Guild ID or Guild URL in the config. TODO Make this work properly. Currently requires the user to truncate the channel if they want URL notation.

func (*Guild) UnmarshalYAML

func (g *Guild) UnmarshalYAML(unmarshal func(interface{}) error) error

type HandlerFunc

type HandlerFunc func(ctx context.Context, s *discordgo.Session, i *discordgo.InteractionCreate)

type InteractionHelper

type InteractionHelper interface {
	GetInteraction() *discordgo.InteractionCreate
	Respond() (<-chan *discordgo.WebhookEdit, error)
	RespondWebhook() (<-chan *discordgo.WebhookEdit, error)
}

type MessageHandler

type MessageHandler struct {
	Handler MessageHandlerFunc
}

type MessageHandlerFunc

type MessageHandlerFunc func(ctx context.Context, info MessageInfo, s *discordgo.Session, m *discordgo.MessageCreate)

type MessageInfo

type MessageInfo struct {
	IsBotCommand bool
}

type NewSessionParams

type NewSessionParams struct {
	fx.In
	Config DiscordConfig
}

type RegisterCommandsParams

type RegisterCommandsParams struct {
	fx.In
	Config    DiscordConfig
	Session   *discordgo.Session
	Commands  []*ApplicationCommandWithHandler `group:"command"`
	Handlers  []*MessageHandler                `group:"handler"`
	Lifecycle fx.Lifecycle
}

Jump to

Keyboard shortcuts

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