sevcord

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

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

Go to latest
Published: Aug 14, 2022 License: MIT Imports: 11 Imported by: 2

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 (
	// Text channel permissions
	PermissionViewChannel           = Permissions(discordgo.PermissionViewChannel)
	PermissionSendMessages          = Permissions(discordgo.PermissionSendMessages)
	PermissionSendTTSMessages       = Permissions(discordgo.PermissionSendTTSMessages)
	PermissionManageMessages        = Permissions(discordgo.PermissionManageMessages)
	PermissionEmbedLinks            = Permissions(discordgo.PermissionEmbedLinks)
	PermissionAttachFiles           = Permissions(discordgo.PermissionAttachFiles)
	PermissionReadMessageHistory    = Permissions(discordgo.PermissionReadMessageHistory)
	PermissionMentionEveryone       = Permissions(discordgo.PermissionMentionEveryone)
	PermissionUseExternalEmojis     = Permissions(discordgo.PermissionUseExternalEmojis)
	PermissionUseSlashCommands      = Permissions(discordgo.PermissionUseSlashCommands)
	PermissionManageThreads         = Permissions(discordgo.PermissionManageThreads)
	PermissionCreatePublicThreads   = Permissions(discordgo.PermissionCreatePublicThreads)
	PermissionCreatePrivateThreads  = Permissions(discordgo.PermissionCreatePrivateThreads)
	PermissionUseExternalStickers   = Permissions(discordgo.PermissionUseExternalStickers)
	PermissionSendMessagesInThreads = Permissions(discordgo.PermissionSendMessagesInThreads)
	PermissionAddReactions          = Permissions(discordgo.PermissionAddReactions)

	// Voice channel permissions
	PermissionVoiceConnect         = Permissions(discordgo.PermissionVoiceConnect)
	PermissionVoiceSpeak           = Permissions(discordgo.PermissionVoiceSpeak)
	PermissionVoiceMuteMembers     = Permissions(discordgo.PermissionVoiceMuteMembers)
	PermissionVoiceDeafenMembers   = Permissions(discordgo.PermissionVoiceDeafenMembers)
	PermissionVoiceMoveMembers     = Permissions(discordgo.PermissionVoiceMoveMembers)
	PermissionVoiceUseVAD          = Permissions(discordgo.PermissionVoiceUseVAD)
	PermissionVoicePrioritySpeaker = Permissions(discordgo.PermissionVoicePrioritySpeaker)
	PermissionVoiceStreamVideo     = Permissions(discordgo.PermissionVoiceStreamVideo)
	PermissionUseActivities        = Permissions(discordgo.PermissionUseActivities)

	// Management permissions
	PermissionChangeNickname      = Permissions(discordgo.PermissionChangeNickname)
	PermissionManageNicknames     = Permissions(discordgo.PermissionManageNicknames)
	PermissionManageRoles         = Permissions(discordgo.PermissionManageRoles)
	PermissionManageWebhooks      = Permissions(discordgo.PermissionManageWebhooks)
	PermissionManageEmojis        = Permissions(discordgo.PermissionManageEmojis)
	PermissionManageEvents        = Permissions(discordgo.PermissionManageEvents)
	PermissionCreateInstantInvite = Permissions(discordgo.PermissionCreateInstantInvite)
	PermissionKickMembers         = Permissions(discordgo.PermissionKickMembers)
	PermissionBanMembers          = Permissions(discordgo.PermissionBanMembers)
	PermissionAdministrator       = Permissions(discordgo.PermissionAdministrator)
	PermissionManageChannels      = Permissions(discordgo.PermissionManageChannels)
	PermissionManageServer        = Permissions(discordgo.PermissionManageServer)
	PermissionViewAuditLogs       = Permissions(discordgo.PermissionViewAuditLogs)
	PermissionViewGuildInsights   = Permissions(discordgo.PermissionViewGuildInsights)
	PermissionModerateMembers     = Permissions(discordgo.PermissionModerateMembers)
)
View Source
const (
	MessageFlagPublished   = MessageFlags(discordgo.MessageFlagsCrossPosted)   // Whether the message was published to another channel
	MessageFlagCrossPosted = MessageFlags(discordgo.MessageFlagsIsCrossPosted) // Whether the message was received from an announcement channel
	MessageFlagLoading     = MessageFlags(discordgo.MessageFlagsLoading)       // "The bot is thinking..."
)

All possible message flags on a message event

Variables

View Source
var Logger = log.Default()

Functions

func DeleteRole

func DeleteRole(c Ctx, id string, guild string) error

DeleteRole deletes a role

Types

type AutocompleteHandler

type AutocompleteHandler func(Ctx, any) []Choice

type Button

type Button struct {
	Label   string
	Style   ButtonStyle
	Handler ButtonHandler

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

type ButtonHandler

type ButtonHandler func(ctx Ctx)

type ButtonStyle

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

type Channel

type Channel struct {
	Guild  bool // Whether its a guild channel
	ID     string
	Name   string
	Topic  string
	Type   ChannelType
	NSFW   bool
	Parent string // ID of category, ID of channel a thread is in if its a thread

	// Group DMs
	Icon       string
	Recipients []*User

	// Voice channels
	Bitrate   int
	UserLimit int
}

func GetChannel

func GetChannel(c Ctx, id string) (*Channel, error)

type ChannelType

type ChannelType int

Channels

const (
	ChannelTypeGuildText          ChannelType = 0
	ChannelTypeDM                 ChannelType = 1
	ChannelTypeGuildVoice         ChannelType = 2
	ChannelTypeGroupDM            ChannelType = 3
	ChannelTypeGuildCategory      ChannelType = 4
	ChannelTypeGuildNews          ChannelType = 5
	ChannelTypeGuildStore         ChannelType = 6
	ChannelTypeGuildNewsThread    ChannelType = 10
	ChannelTypeGuildPublicThread  ChannelType = 11
	ChannelTypeGuildPrivateThread ChannelType = 12
	ChannelTypeGuildStageVoice    ChannelType = 13
)

type Choice

type Choice struct {
	Name  string
	Value string
}

type Client

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

func NewClient

func NewClient(token string, params *ClientParams) (*Client, error)

func (*Client) Close

func (c *Client) Close() error

func (*Client) HandleContextMenuCommand

func (c *Client) HandleContextMenuCommand(cmd *ContextMenuCommand)

func (*Client) HandleMessage

func (c *Client) HandleMessage(m MessageHandler)

HandleMessage updates the internal message handler. NOTE: This will replace the previous handler if there was one

func (*Client) HandleSlashCommand

func (c *Client) HandleSlashCommand(cmd SlashCommandObject)

func (*Client) Start

func (c *Client) Start() error

type ClientParams

type ClientParams struct {
	Messages  bool // Whether to listen for messages
	Reactions bool // Whether to listen for reactions
}

type Color

type Color int

Color represents a discord color, and is the decimal representation of a hex color. For example: blue would be `Color(0x0000FF)`

type Component

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

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

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 {
	Acknowledge()
	Respond(*Response)
	Edit(*Response)

	Guild() string
	Channel() string
	User() *User
	// contains filtered or unexported methods
}

type EmbedBuilder

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

func NewEmbedBuilder

func NewEmbedBuilder(title string) *EmbedBuilder

func (*EmbedBuilder) Author

func (e *EmbedBuilder) Author(name, url, 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) Field

func (e *EmbedBuilder) Field(title string, description string, inline bool) *EmbedBuilder

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

type File

type File struct {
	Name        string
	ContentType string
	Reader      io.Reader
}

Responses

type InteractionCtx

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

func (*InteractionCtx) Acknowledge

func (i *InteractionCtx) Acknowledge()

func (*InteractionCtx) Channel

func (i *InteractionCtx) Channel() string

func (*InteractionCtx) Edit

func (i *InteractionCtx) Edit(r *Response)

func (*InteractionCtx) Guild

func (i *InteractionCtx) Guild() string

func (*InteractionCtx) Modal

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

func (*InteractionCtx) Respond

func (i *InteractionCtx) Respond(r *Response)

func (*InteractionCtx) User

func (i *InteractionCtx) User() *User

type Message

type Message struct {
	ID          string
	Channel     string     // The ID of the channel the message was sent in
	Guild       string     // THE ID of the guild the message was sent in
	EditedTime  *time.Time // The time when the message was edited, nil if not edited
	Author      *User
	Attachments []MessageAttachment
	Content     string
	TTS         bool
	ReplyFrom   *ReplyFrom // What this message is replying to (if any)

	// Mentions
	Mentions        []*User  // Users mentioned (NOTE: This does not include their guild data)
	MentionRoles    []string // Role IDs mentioned
	MentionEveryone bool     // Mentions everyone
}

TODO: Interaction info & embed info

type MessageAttachment

type MessageAttachment struct {
	ID        string
	Filename  string
	URL       string
	ProxyURL  string // Use this to download
	Size      int
	Ephemeral bool

	// Image options
	Width  int
	Height int
}

type MessageCtx

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

func (*MessageCtx) Acknowledge

func (m *MessageCtx) Acknowledge()

func (*MessageCtx) Channel

func (m *MessageCtx) Channel() string

func (*MessageCtx) Edit

func (m *MessageCtx) Edit(r *Response)

func (*MessageCtx) Guild

func (m *MessageCtx) Guild() string

func (*MessageCtx) Respond

func (m *MessageCtx) Respond(r *Response)

func (*MessageCtx) User

func (m *MessageCtx) User() *User

type MessageFlags

type MessageFlags int

type MessageHandler

type MessageHandler func(Ctx, *Message)
type Modal struct {
	Title   string
	Inputs  []ModalInput
	Handler ModalHandler
}

type ModalHandler

type ModalHandler func(Ctx, []string)

type ModalInput

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

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
}

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 Permissions

type Permissions int64

Permissions

func CombinePermissions

func CombinePermissions(perms ...Permissions) Permissions

func (Permissions) Add

func (p Permissions) Add(perms ...Permissions) Permissions

func (Permissions) Has

func (p Permissions) Has(perm Permissions) bool

type ReplyFrom

type ReplyFrom struct {
	Message string
	Channel string
	Guild   string
}

type Response

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

func EmbedResponse

func EmbedResponse(e *EmbedBuilder) *Response

func MessageResponse

func MessageResponse(message string) *Response

func (*Response) ComponentRow

func (r *Response) ComponentRow(components ...Component) *Response

func (*Response) File

func (r *Response) File(f File) *Response

type Role

type Role struct {
	// Not used for creating role
	ID       string
	Position int  // Position in role hierarchy
	Managed  bool // If its managed by an integration (if true cannot give/take role)

	// Required to create role
	Name        string
	Mentionable bool
	Hoist       bool  // Shows up seperately in member list
	Color       Color // Hex color of role
	Permissions Permissions
}

func CreateRole

func CreateRole(c Ctx, r *Role, guild string) (*Role, error)

CreateRole creates the role and returns the role created

func GetGuildRole

func GetGuildRole(c Ctx, id string, guild string) (*Role, error)

GetGuildRole gets a role from a guild (NOTE: This will try to get the role from the cache if possible)

func GetGuildRoles

func GetGuildRoles(c Ctx, guild string) ([]*Role, error)

GetGuildRoles gets a sorted list of all roles in a guild

type Select

type Select struct {
	Placeholder string
	Options     []SelectOption
	Handler     SelectHandler

	// Optional
	MinValues int
	MaxValues int
	Disabled  bool
}

type SelectHandler

type SelectHandler func(ctx Ctx, opts []string) // opts is the IDs of the options that are selected

type SelectOption

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

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

type SlashCommand

type SlashCommand struct {
	Name        string
	Description string
	Options     []Option
	Permissions *Permissions // Leave nil for everyone to use, only works for top-level commands
	Handler     SlashCommandHandler
}

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 *Permissions // Leave nil for everyone to use, only works for top-level commands
}

NOTE: Can only have 2 of these and then a command

type SlashCommandHandler

type SlashCommandHandler func(Ctx, []any)

type SlashCommandObject

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

type User

type User struct {
	ID            string
	Username      string
	Discriminator string // 4 numbers after name
	BannerColor   int
	Bot           bool
	System        bool
	AvatarURL     string
	BannerURL     string

	// Guild user options
	Guild          *string // Whether the following fields are filled out or not (if nil, then no, otherwise it is the Guild ID)
	JoinedAt       time.Time
	Nickname       string
	Deaf           bool     // Deafened on guild level
	Mute           bool     // Muted on guild level
	GuildAvatarURL string   // Blank if no custom avatar
	Roles          []string // IDs of roles
	Permissions    Permissions
	// contains filtered or unexported fields
}

func GetGuildUser

func GetGuildUser(c Ctx, id string, guild string) (*User, error)

func GetUser

func GetUser(c Ctx, id string) (*User, error)

func (*User) Avatar

func (u *User) Avatar(ctx Ctx) (image.Image, error)

Avatar gets the user's avatar without making a network request

func (*User) GiveRole

func (u *User) GiveRole(c Ctx, roleID string) error

func (*User) HasFlag

func (u *User) HasFlag(flag UserFlag) bool

func (*User) RemoveRole

func (u *User) RemoveRole(c Ctx, roleID string) error

type UserFlag

type UserFlag int

Users

const (
	UserFlagDiscordEmployee           UserFlag = 1 << 0
	UserFlagDiscordPartner            UserFlag = 1 << 1
	UserFlagHypeSquadEvents           UserFlag = 1 << 2
	UserFlagBugHunterLevel1           UserFlag = 1 << 3
	UserFlagHouseBravery              UserFlag = 1 << 6
	UserFlagHouseBrilliance           UserFlag = 1 << 7
	UserFlagHouseBalance              UserFlag = 1 << 8
	UserFlagEarlySupporter            UserFlag = 1 << 9
	UserFlagTeamUser                  UserFlag = 1 << 10
	UserFlagSystem                    UserFlag = 1 << 12
	UserFlagBugHunterLevel2           UserFlag = 1 << 14
	UserFlagVerifiedBot               UserFlag = 1 << 16
	UserFlagVerifiedBotDeveloper      UserFlag = 1 << 17
	UserFlagDiscordCertifiedModerator UserFlag = 1 << 18
)

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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