discord

package
v0.0.0-...-b2921d1 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2020 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Token is the string used for authenticating against Discord's websocket
	Token string
	// Prefix is the value to prefix commands so they are recognised
	Prefix string
)

Functions

func StartBot

func StartBot()

StartBot gets the environment variables needed for the Discord gateway, creates the new session type and starts the initial websocket connection to Discord's gateway

func StartSubscriber

func StartSubscriber()

StartSubscriber subscribes to the discord message_create event on the queue and waits for a response, also subscribes to the internal send_response event which then sends the payload to Discord's API

Types

type APIEmbedPayload

type APIEmbedPayload struct {
	APIURL  string
	Payload []byte
}

APIEmbedPayload is a payload for sending an embed based message over Discord's API

func (*APIEmbedPayload) Prepare

func (p *APIEmbedPayload) Prepare(embed map[string]interface{}, channel string) error

Prepare is a helper command for formatting the message to an APIEmbedPayload type

type APIPayload

type APIPayload struct {
	APIURL  string
	Payload []byte
}

APIPayload is a payload for sending a text based message over Discord's API

func (*APIPayload) Prepare

func (p *APIPayload) Prepare(content, channel string) error

Prepare is a helper command for formatting the message to an APIPayload type

type Heartbeat

type Heartbeat struct {
	OPCode int `json:"op"`
	Data   int `json:"d"`
}

Heartbeat is the type used to send a heartbeat back over the Discord websocket

type Message

type Message struct {
	ID              string      `json:"id,omitempty"`               // id of the message
	ChannelID       string      `json:"channel_id,omitempty"`       // id of the channel the message was sent in
	GuildID         string      `json:"guild_id,omitempty"`         // (?) id of the guild the message was sent in
	Content         string      `json:"content,omitempty"`          // contents of the message
	SentAt          Timestamp   `json:"timestamp,omitempty"`        // ISO8601 timestamp when this message was sent
	EditedAt        Timestamp   `json:"edited_timestamp,omitempty"` // (?) ISO8601 timestamp when this message was edited (or null if never)
	TTS             bool        `json:"tts,omitempty"`              // boolean whether this was a TTS message
	MentionEveryone bool        `json:"mention_everyone,omitempty"` // boolean whether this message mentions everyone
	MentionedRoles  []string    `json:"mention_roles,omitempty"`    // array of role object ids - roles specifically mentioned in this message
	Pinned          bool        `json:"pinned,omitempty"`           // boolean whether this message is pinned
	WebhookID       string      `json:"webhook_id,omitempty"`       // (?) snowflake if the message is generated by a webhook, this is the webhook's id
	Type            int         `json:"type,omitempty"`             // integer type of message
	Embed           interface{} `json:"embed,omitempty"`            // array of embed objects any embedded content

}

Message is Discord's message structure

type Payload

type Payload struct {
	OPCode   int             `json:"op"`
	Data     json.RawMessage `json:"d"`
	Sequence int             `json:"s,omitempty"`
	Event    string          `json:"t,omitempty"`
}

Payload is a simple structure used to receive and send events over the websocket

type Session

type Session struct {
	Ctx      context.Context
	URL      string
	Conn     *websocket.Conn
	Interval time.Duration
	Sequence int
	ID       string
	Token    string
	Prefix   string
}

Session is the type which holds Discord's current session

func (*Session) Connect

func (s *Session) Connect()

Connect dials Discord's websocket and creates a connection within the session

type Timestamp

type Timestamp string

Timestamp stores a timestamp, as sent by the Discord API.

func (Timestamp) Parse

func (t Timestamp) Parse() (time.Time, error)

Parse parses a timestamp string into a time.Time object. The only time this can fail is if Discord changes their timestamp format.

Jump to

Keyboard shortcuts

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