sevcord

package module
v2.4.1 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2023 License: MIT Imports: 11 Imported by: 8

README

Sevcord: A high level discord library for Go

See the example to learn how to use Sevcord!

Documentation

Index

Constants

View Source
const (
	ContextMenuKindMessage = ContextMenuKind(discordgo.MessageApplicationCommand) // The string passed is message ID
	ContextMenuKindUser    = ContextMenuKind(discordgo.UserApplicationCommand)    // The string passed is User ID
)
View Source
const MaxFileSize = 26214400 // 25MB limit

Variables

View Source
var Logger = log.Default()

Functions

This section is empty.

Types

type AutocompleteHandler

type AutocompleteHandler func(Ctx, any) []Choice

type Button

type Button struct {
	Label string
	Style ButtonStyle

	// Handler
	Handler string // ID of handler
	Params  string // Params to pass to handler

	// Optional
	Emoji    *ComponentEmoji
	URL      string // Only link button can have this
	Disabled bool
}

func NewButton

func NewButton(label string, style ButtonStyle, handler string, params string) *Button

func (*Button) Dg added in v2.2.2

func (*Button) SetDisabled

func (b *Button) SetDisabled(disabled bool) *Button

func (*Button) SetURL

func (b *Button) SetURL(url string) *Button

func (*Button) WithEmoji

func (b *Button) WithEmoji(emoji ComponentEmoji) *Button

type ButtonHandler

type ButtonHandler func(ctx Ctx, params string)

type ButtonStyle

type ButtonStyle int
const (
	ButtonStylePrimary   ButtonStyle = 1
	ButtonStyleSecondary ButtonStyle = 2
	ButtonStyleSuccess   ButtonStyle = 3
	ButtonStyleDanger    ButtonStyle = 4
	ButtonStyleLink      ButtonStyle = 5
)

type Choice

type Choice struct {
	Name  string
	Value string
}

func NewChoice

func NewChoice(name, value string) Choice

type Component

type Component interface {
	Dg() discordgo.MessageComponent
}

type ComponentEmoji

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

func ComponentEmojiCustom

func ComponentEmojiCustom(name, id string, animated bool) ComponentEmoji

func ComponentEmojiDefault

func ComponentEmojiDefault(emoji rune) ComponentEmoji

func (ComponentEmoji) Dg added in v2.2.2

type ContextMenuCommand

type ContextMenuCommand struct {
	Kind    ContextMenuKind
	Name    string
	Handler ContextMenuHandler
}

type ContextMenuHandler

type ContextMenuHandler func(Ctx, string)

type ContextMenuKind

type ContextMenuKind int

type Ctx

type Ctx interface {
	Dg() *discordgo.Session // Allows access to underlying discordgo session

	// Talk to user
	Acknowledge() error            // Indicates progress
	Respond(msg MessageSend) error // Displays message to user (note: in interactions, if not acknowledged this will be ephemeral)

	// Get info
	Author() *discordgo.Member
	Channel() string
	Guild() string
}

type EmbedBuilder

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

func NewEmbed

func NewEmbed() EmbedBuilder

Builder methods

func (EmbedBuilder) AddField

func (e EmbedBuilder) AddField(name, value string, inline bool) EmbedBuilder

func (EmbedBuilder) Author

func (e EmbedBuilder) Author(url, name, iconURL string) EmbedBuilder

func (EmbedBuilder) Color

func (e EmbedBuilder) Color(color int) EmbedBuilder

func (EmbedBuilder) Description

func (e EmbedBuilder) Description(description string) EmbedBuilder

func (EmbedBuilder) Dg added in v2.2.2

func (EmbedBuilder) Footer

func (e EmbedBuilder) Footer(text, iconURL string) EmbedBuilder

func (EmbedBuilder) Image

func (e EmbedBuilder) Image(url string) EmbedBuilder

func (EmbedBuilder) Thumbnail

func (e EmbedBuilder) Thumbnail(url string) EmbedBuilder

func (EmbedBuilder) Timestamp

func (e EmbedBuilder) Timestamp(timestamp string) EmbedBuilder

func (EmbedBuilder) Title

func (e EmbedBuilder) Title(title string) EmbedBuilder

func (EmbedBuilder) URL

func (e EmbedBuilder) URL(url string) EmbedBuilder

type InteractionCtx

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

InteractionCtx represents context for an interaction

func (*InteractionCtx) Acknowledge

func (i *InteractionCtx) Acknowledge() error

func (*InteractionCtx) Author

func (i *InteractionCtx) Author() *discordgo.Member

func (*InteractionCtx) Channel added in v2.1.1

func (i *InteractionCtx) Channel() string

func (*InteractionCtx) Dg

func (i *InteractionCtx) Dg() *discordgo.Session

func (*InteractionCtx) Guild added in v2.1.1

func (i *InteractionCtx) Guild() string

func (*InteractionCtx) Modal

func (i *InteractionCtx) Modal(m Modal) error

func (*InteractionCtx) Respond

func (i *InteractionCtx) Respond(msg MessageSend) error

type MessageCtx added in v2.2.0

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

MessageCtx represents a message context

func (*MessageCtx) Acknowledge added in v2.2.0

func (m *MessageCtx) Acknowledge() error

func (*MessageCtx) Author added in v2.2.0

func (m *MessageCtx) Author() *discordgo.Member

func (*MessageCtx) Channel added in v2.2.0

func (m *MessageCtx) Channel() string

func (*MessageCtx) Dg added in v2.2.0

func (m *MessageCtx) Dg() *discordgo.Session

func (*MessageCtx) Guild added in v2.2.0

func (m *MessageCtx) Guild() string

func (*MessageCtx) Message added in v2.2.0

func (m *MessageCtx) Message() *discordgo.Message

func (*MessageCtx) Respond added in v2.2.0

func (m *MessageCtx) Respond(msg MessageSend) error

type MessageHandler added in v2.2.0

type MessageHandler func(ctx Ctx, content string)

type MessageSend

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

func NewMessage

func NewMessage(content string) MessageSend

func (MessageSend) AddComponentRow

func (m MessageSend) AddComponentRow(components ...Component) MessageSend

func (MessageSend) AddEmbed

func (m MessageSend) AddEmbed(embed EmbedBuilder) MessageSend

func (MessageSend) AddFile

func (m MessageSend) AddFile(name, contentType string, reader io.Reader, size int) MessageSend

AddFile adds a file to the message and will gzip it if it will not fit into the size limit. If 0 is passed to the `size` argument, size will be ignored.

func (MessageSend) Content

func (m MessageSend) Content(content string) MessageSend

func (MessageSend) Dg added in v2.2.2

type MiddlewareFunc added in v2.1.1

type MiddlewareFunc func(ctx Ctx, command string) (ok bool)

MiddlewareFunc accepts context and returns whether or not to continue

type Modal struct {
	Title   string
	Inputs  []ModalInput
	Handler ModalHandler
}

func NewModal

func NewModal(title string, handler ModalHandler) Modal

func (Modal) Input

func (m Modal) Input(inp ModalInput) Modal

type ModalHandler

type ModalHandler func(Ctx, []string)

Modals

type ModalInput

type ModalInput struct {
	Label       string
	Placeholder string
	Style       ModalInputStyle
	Required    bool
	MinLength   int
	MaxLength   int
}

func NewModalInput

func NewModalInput(label, placeholder string, style ModalInputStyle, maxLength int) ModalInput

func (ModalInput) SetLength

func (m ModalInput) SetLength(min, max int) ModalInput

func (ModalInput) SetRequired

func (m ModalInput) SetRequired(required bool) ModalInput

type ModalInputStyle

type ModalInputStyle int
const (
	ModalInputStyleSentence  ModalInputStyle = 1
	ModalInputStyleParagraph ModalInputStyle = 2
)

type Option

type Option struct {
	Name        string
	Description string
	Kind        OptionKind
	Required    bool

	Choices      []Choice            // Optional
	Autocomplete AutocompleteHandler // Optional

	MinVal *float64
	MaxVal float64

	ChannelTypes []discordgo.ChannelType
}

func NewOption

func NewOption(name, description string, kind OptionKind, required bool) Option

func (Option) AddChoices

func (o Option) AddChoices(c ...Choice) Option

func (Option) AutoComplete

func (o Option) AutoComplete(a AutocompleteHandler) Option

func (Option) ChannelFilter added in v2.3.2

func (o Option) ChannelFilter(allowed ...discordgo.ChannelType) Option

ChannelFilter allows specific channels to be shown in a channel option

func (Option) MinMax added in v2.4.1

func (o Option) MinMax(min, max float64) Option

MinMax allows you to set the min and max values for number options, or the min and max length for string options. Use 0 for the max value to leave no upper limit

type OptionKind

type OptionKind int
const (
	OptionKindString     OptionKind = iota // string
	OptionKindInt                          // int
	OptionKindBool                         // bool
	OptionKindUser                         // *User
	OptionKindChannel                      // channel id (string)
	OptionKindRole                         // role id (string)
	OptionKindFloat                        // float64
	OptionKindAttachment                   // *SlashCommandAttachment
)

type Select

type Select struct {
	Kind        SelectKind
	Placeholder string
	Options     []SelectOption

	// Handler
	Handler string // ID of handler
	Params  string // Params to pass to handler

	// Optional
	MinValues int
	MaxValues int
	Disabled  bool

	// Fill this for channel select menu
	ChannelFilter []discordgo.ChannelType
}

func NewSelect

func NewSelect(placeholder string, handler string, params string) *Select

func (*Select) ChannelMenuFilter added in v2.3.0

func (s *Select) ChannelMenuFilter(allowed ...discordgo.ChannelType) *Select

func (*Select) Dg added in v2.2.2

func (*Select) Option

func (s *Select) Option(option SelectOption) *Select

func (*Select) SetDisabled

func (s *Select) SetDisabled(disabled bool) *Select

func (*Select) SetKind added in v2.3.0

func (s *Select) SetKind(kind SelectKind) *Select

func (*Select) SetRange

func (s *Select) SetRange(min, max int) *Select

type SelectHandler

type SelectHandler func(ctx Ctx, params string, selected []string)

type SelectKind added in v2.3.0

type SelectKind int
const (
	SelectKindString SelectKind = iota
	SelectKindUser
	SelectKindRole
	SelectKindMentionable // Users or Roles
	SelectKindChannel
)

func (SelectKind) Dg added in v2.3.0

type SelectOption

type SelectOption struct {
	Label       string
	Description string
	ID          string // Must be unique

	// Optional
	Emoji   *ComponentEmoji
	Default bool // Whether it is automatically ticked
}

func NewSelectOption

func NewSelectOption(label, description, id string) SelectOption

func (SelectOption) SetDefault

func (s SelectOption) SetDefault(defaulted bool) SelectOption

func (SelectOption) WithEmoji

func (s SelectOption) WithEmoji(emoji ComponentEmoji) SelectOption

type Sevcord

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

func New

func New(token string) (*Sevcord, error)

func (*Sevcord) AddButtonHandler

func (s *Sevcord) AddButtonHandler(id string, handler ButtonHandler)

func (*Sevcord) AddMiddleware added in v2.1.1

func (s *Sevcord) AddMiddleware(m MiddlewareFunc)

AddMiddleware adds middleware, a function that is run before every command handler is called. Middleware is run in the order it is added. Note that middleware is not run for message handlers

func (*Sevcord) AddSelectHandler

func (s *Sevcord) AddSelectHandler(id string, handler SelectHandler)

func (*Sevcord) Dg

func (s *Sevcord) Dg() *discordgo.Session

Dg gets the global discordgo session. NOTE: Only use this to add handlers/intents, use the one provided with Ctx for anything else

func (*Sevcord) Listen

func (s *Sevcord) Listen()

func (*Sevcord) RegisterSlashCommand

func (s *Sevcord) RegisterSlashCommand(cmd SlashCommandObject)

func (*Sevcord) SetMessageHandler added in v2.2.0

func (s *Sevcord) SetMessageHandler(handler MessageHandler)

type SlashCommand

type SlashCommand struct {
	Name        string
	Description string
	Options     []Option
	Permissions *int
	Handler     SlashCommandHandler
}

func NewSlashCommand

func NewSlashCommand(name, description string, handler SlashCommandHandler, options ...Option) *SlashCommand

func (*SlashCommand) RequirePermissions

func (s *SlashCommand) RequirePermissions(p int) *SlashCommand

RequirePermissions accepts a discordgo permissions bit mask

type SlashCommandAttachment

type SlashCommandAttachment struct {
	Filename    string
	URL         string
	ProxyURL    string // Use this to download
	ContentType string
}

type SlashCommandGroup

type SlashCommandGroup struct {
	Name        string
	Description string
	Children    []SlashCommandObject
	Permissions *int
}

NOTE: Can only have 2 levels of subcommands

func NewSlashCommandGroup

func NewSlashCommandGroup(name string, description string, children ...SlashCommandObject) *SlashCommandGroup

func (*SlashCommandGroup) RequirePermissions

func (s *SlashCommandGroup) RequirePermissions(p int) *SlashCommandGroup

RequirePermissions accepts a discordgo permissions bit mask

type SlashCommandHandler

type SlashCommandHandler func(Ctx, []any)

type SlashCommandObject

type SlashCommandObject interface {
	// contains filtered or unexported methods
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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