discord

package
v0.0.0-...-2bffabc Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2021 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EmbedTypeRich     = "rich"
	EmbedTypeImage    = "image"
	EmbedTypeVideo    = "video"
	EmbedTypeGifVideo = "gifv"
	EmbedTypeArticle  = "article"
	EmbedTypeLink     = "link"
)
View Source
const (
	MessageTypeDefault = iota
	MessageTypeRecipientAdd
	MessageTypeRecipientRemove
	MessageTypeCall
	MessageTypeChannelNameChange
	MessageTypeChannelIconChange
	MessageTypeChannelPinnedMessage
	MessageTypeGuildMemberJoin
	MessageTypeUserPremiumGuildSubscription
	MessageTypeUserPremiumGuildSubscriptionTier1
	MessageTypeUserPremiumGuildSubscriptionTier2
	MessageTypeUserPremiumGuildSubscriptionTier3
	MessageTypeChannelFollowAdd
	MessageTypeGuildDiscoveryDisqualified = iota + 1
	MessageTypeGuildDiscoveryRequalified
	MessageTypeReply = iota + 4
	MessageTypeApplicationCommand
)
View Source
const (
	OpcodeDispatch = iota
	OpcodeHeartbeat
	OpcodeIdentify
	OpcodePresenceUpdate
	OpcodeVoiceStateUpdate
	OpcodeResume = iota + 1
	OpcodeReconnect
	OpcodeRequestGuildMembers
	OpcodeInvalidSession
	OpcodeHello
	OpcodeHeartbeatACK
)
View Source
const (
	EventNameMessageCreate = "MESSAGE_CREATE"
	EventNameMessageUpdate = "MESSAGE_UPDATE"
	EventNameReady         = "READY"
	EventNameResumed       = "RESUMED"
)
View Source
const (
	IntentGuilds = 1 << iota
	IntentGuildMembers
	IntentGuildBans
	IntentGuildEmojis
	IntentGuildIntegrations
	IntentGuildWebhooks
	IntentGuildInvites
	IntentGuildVoiceStates
	IntentGuildPresences
	IntentGuildMessages
	IntentGuildMessageReactions
	IntentGuildMessageTyping
	IntentDirectMessages
	IntentDirectMessageReactions
	IntentDirectMessageTyping
)
View Source
const (
	UserFlagDiscordEmployee = 1 << iota
	UserFlagPartneredServerOwner
	UserFlagHypeSquadEvents
	UserFlagBugHunterLevel1
	UserFlagHouseBravery
	UserFlagHouseBrilliance
	UserFlagHouseBalance
	UserFlagEarlySupporter
	UserFlagTeamUser
	UserFlagSystem
	UserFlagBugHunterLevel2
	UserFlagVerifiedBot
	UserFlagEarlyVerifiedBotDeveloper
)
View Source
const (
	PremiumTypeNone = iota
	PremiumTypeNitroClassic
	PremiumTypeNitro
)

Variables

View Source
var (
	ErrUnauthorized    = fmt.Errorf("invalid authorization, try using a new token")
	ErrForbidden       = fmt.Errorf("forbidden, you may not have permission to send in the channel (i.e. you aren't in the server or don't have send message permissions in the channel), your account might need verification, or your ip address may have been blocked")
	ErrTooManyRequests = fmt.Errorf("you are being rate limited, try waiting some time and trying again")
	ErrNotFound        = fmt.Errorf("not found, make sure your channel id is valid")
	ErrIntervalServer  = fmt.Errorf("remote server interval server error")
)

Functions

This section is empty.

Types

type Client

type Client struct {
	Token string
	User  User
}

func NewClient

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

func (Client) CurrentUser

func (client Client) CurrentUser() (User, error)

CurrentUser sends a http request to Discord and returns a User struct based on the response. This method should only be used if the user information was changed between when you created the client and now. Otherwise, this is also available in the User field of the Client struct.

func (Client) NewWSConn

func (client Client) NewWSConn(rtr *MessageRouter, fatalHandler func(err error)) (*WSConn, error)

func (Client) SendMessage

func (client Client) SendMessage(content, channelID string, typing time.Duration) error

type ClientState

type ClientState struct {
	HighestLastMessageID     string `json:"highest_last_message_id,omitempty"`
	ReadStateVersion         int    `json:"read_state_version,omitempty"`
	UserGuildSettingsVersion int    `json:"user_guild_settings_version,omitempty"`
}

type Data

type Data struct {
	Message
	Identify
	ClientState       ClientState `json:"client_state,omitempty"`
	HeartbeatInterval int         `json:"heartbeat_interval,omitempty"`
	SessionID         string      `json:"session_id,omitempty"`
	Sequence          int         `json:"seq,omitempty"` // For sending only
}

type Embed

type Embed struct {
	Title string `json:"title,omitempty"`

	// The type of embed. Always EmbedTypeRich for webhook embeds.
	Type        string `json:"type,omitempty"`
	Description string `json:"description,omitempty"`
	URL         string `json:"url,omitempty"`

	// The time at which the embed was sent.
	Time time.Time `json:"timestamp,omitempty"`

	// The color code of the embed.
	Color    int           `json:"color,omitempty"`
	Footer   EmbedFooter   `json:"footer,omitempty"`
	Provider EmbedProvider `json:"provider,omitempty"`
	Author   EmbedAuthor   `json:"author,omitempty"`
	Fields   []EmbedField  `json:"fields,omitempty"`
}

type EmbedAuthor

type EmbedAuthor struct {
	Name         string `json:"name,omitempty"`
	URL          string `json:"url,omitempty"`
	IconURL      string `json:"icon_url,omitempty"`
	ProxyIconURL string `json:"proxy_icon_url,omitempty"`
}

type EmbedField

type EmbedField struct {
	Name   string `json:"name"`
	Value  string `json:"value"`
	Inline bool   `json:"inline,omitempty"`
}

type EmbedFooter

type EmbedFooter struct {
	Text         string `json:"text"`
	IconURL      string `json:"icon_url,omitempty"`
	ProxyIconURL string `json:"proxy_icon_url,omitempty"`
}

type EmbedProvider

type EmbedProvider struct {
	Name string `json:"name,omitempty"`
	URL  string `json:"url,omitempty"`
}

type Event

type Event struct {
	Op        int    `json:"op"`
	Data      Data   `json:"d,omitempty"`
	Sequence  int    `json:"s,omitempty"`
	EventName string `json:"t,omitempty"`
}

type HandlerFunc

type HandlerFunc func(msg Message)

type Identify

type Identify struct {
	Token        string     `json:"token"`
	Properties   Properties `json:"properties"`
	Capabilities int        `json:"capabilities,omitempty"`
	Compress     bool       `json:"compress"`
	Presence     Presence   `json:"presence"`
}

type Message

type Message struct {
	// The ID of the message.
	ID string `json:"id,omitempty"`

	// The ID of the channel the message was sent in.
	ChannelID string `json:"channel_id,omitempty"`

	// The ID of the guild the message was sent in.
	GuildID string `json:"guild_id,omitempty"`

	// The author of the message. Not guaranteed to be a valid user.
	//
	// The author object follows the structure of the User object, but is only a
	// valid user in the case where the message is generated by a user or bot
	// user. If the message is generated by a webhook, the author object
	// corresponds to the webhook's ID, username, and avatar. You can tell if a
	// message is generated by a webhook by checking for the WebhookID on the
	// message object.
	Author User `json:"author,omitempty"`

	// The contents of the message.
	Content string `json:"content,omitempty"`

	// When the message was sent.
	Time time.Time `json:"timestamp,omitempty"`

	// When this message was edited (default value if never).
	EditedTime time.Time `json:"edited_timestamp,omitempty"`

	// Whether this is a TTS message.
	TTS bool `json:"tts,omitempty"`

	// Whether this message mentions everyone.
	MentionEveryone bool `json:"mention_everyone,omitempty"`

	// Users specifically mentions in the message.
	Mentions []User `json:"mentions"`

	// The type of message.
	Type int `json:"type,omitempty"`

	// Whether the message is pinned.
	Pinned bool `json:"pinned,omitempty"`

	// Any embedded content.
	Embeds []Embed `json:"embeds,omitempty"`

	// If the message is generated by a webhook, this is the webhook's ID.
	WebhookID string `json:"webhook_id,omitempty"`

	// The message which this message references. This field is only set for
	// messages with type MessageTypeReply.
	//
	// If the message is a reply but this field is not set, either the Discord
	// backend did not attempt to fetch the message that was being replied to,
	// or the referenced message was deleted.
	ReferencedMessage *Message `json:"referenced_message,omitempty"`
}

type MessageRoute

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

func (*MessageRoute) Author

func (rt *MessageRoute) Author(id string) *MessageRoute

func (*MessageRoute) Channel

func (rt *MessageRoute) Channel(id string) *MessageRoute

func (*MessageRoute) ContentContains

func (rt *MessageRoute) ContentContains(s string) *MessageRoute

func (*MessageRoute) ContentMatchesExp

func (rt *MessageRoute) ContentMatchesExp(exp *regexp.Regexp) *MessageRoute

func (*MessageRoute) EventType

func (rt *MessageRoute) EventType(et string) *MessageRoute

func (*MessageRoute) Handler

func (rt *MessageRoute) Handler(h func(msg Message))

func (*MessageRoute) HasEmbeds

func (rt *MessageRoute) HasEmbeds(b bool) *MessageRoute

func (*MessageRoute) Mentions

func (rt *MessageRoute) Mentions(id string) *MessageRoute

func (*MessageRoute) RespondsTo

func (rt *MessageRoute) RespondsTo(id string) *MessageRoute

type MessageRouter

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

func (*MessageRouter) Middleware

func (rtr *MessageRouter) Middleware(mw func(h HandlerFunc) HandlerFunc)

func (*MessageRouter) NewRoute

func (rtr *MessageRouter) NewRoute() *MessageRoute

type Presence

type Presence struct {
	Status     string   `json:"status,omitempty"`
	Since      int      `json:"since,omitempty"`
	Activities []string `json:"activities,omitempty"`
	AFK        bool     `json:"afk,omitempty"`
}

type Properties

type Properties struct {
	OS                     string `json:"os,omitempty"`
	Browser                string `json:"browser,omitempty"`
	Device                 string `json:"device,omitempty"`
	BrowserUserAgent       string `json:"browser_user_agent,omitempty"`
	BrowserVersion         string `json:"browser_version,omitempty"`
	OSVersion              string `json:"os_version,omitempty"`
	Referrer               string `json:"referrer,omitempty"`
	ReferringDomain        string `json:"referring_domain,omitempty"`
	ReferrerCurrent        string `json:"referrer_current,omitempty"`
	ReferringDomainCurrent string `json:"referring_domain_current,omitempty"`
	ReleaseChannel         string `json:"release_channel,omitempty"`
	ClientBuildNumber      int    `json:"client_build_number,omitempty"`
}

type User

type User struct {
	// The user's ID.
	ID       string `json:"id"`
	Username string `json:"username"`

	// The user's 4-digit Discord-tag.
	Discriminator string `json:"discriminator"`

	// Whether the user belongs to an OAuth2 application.
	Bot bool `json:"bot,omitempty"`

	// The user's avatar hash.
	Avatar string `json:"avatar"`

	// Whether the user is an official Discord system user (part of the urgent
	// message system).
	System bool `json:"system,omitempty"`

	// Whether the user has two factor authentication enabled on their account.
	MFA bool `json:"mfa_enabled,omitempty"`

	// The user's chosen language option.
	Locale        string `json:"locale,omitempty"`
	VerifiedEmail bool   `json:"verified,omitempty"`
	Email         string `json:"email,omitempty"`
	Flags         int    `json:"flags,omitempty"`

	// The type of Nitro subscription on a user's account.
	PremiumType int `json:"premium_type,omitempty"`
	PublicFlags int `json:"public_flags,omitempty"`
}

type WSConn

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

func (*WSConn) Close

func (c *WSConn) Close() error

type WSConnOpts

type WSConnOpts struct {
	MessageRouter *MessageRouter
	FatalHandler  func(err *websocket.CloseError)
}

Jump to

Keyboard shortcuts

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