discord

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

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

Go to latest
Published: Jan 7, 2016 License: MIT Imports: 10 Imported by: 0

README

discordapi

A GoLang API wrapper for the Discord REST API (unofficial) and preliminary websockets

v0.8.0 alpha

##About This is a simple low-level REST API Wrapper for Discord. I am not affiliated with or endorsed by Discord at all, this is meant as a way to learn Go better as a language. It may contain errors, bugs, and any other such oddities, but it seems to work for me :)

Later on, I will have better websocket support, but if you want a good one right now, then please use go-discord instead (or in addition to mine)!

Version system will be sporadic until 1.0, safe to ignore, other than alpha means preliminary, beta means set on paper, and stable means more or less set in stone.

##Usage

Please note that as-is, this example will only work if run with your account info. To get it to work with others, follow the comments instructions.

package main

import (
	"fmt"
	"strings"
	"github.com/Nerketur/discordapi"
)

func parseCmd(c discord.Discord, data discord.MESSAGE_CREATE) {
	//check that prefix is there
	cmdPrefix := "/gogogobot "
	if !strings.HasPrefix(data.Content, cmdPrefix) {
		return
	}
	if data.Author.ID != c.Me.ID {  //comment out before uncommenting below
	//if data.Author.Name != "Name" { //use this instead for checking names
	//if data.Author.ID != "UserID" { //use this instead to check for a User ID (string of numbers)
		//c.SendTextMsg("Sorry, you can't use this command", data.ChanID)
		return
	}
	doCmd := strings.Trim(strings.TrimPrefix(data.Content, cmdPrefix), " \n\r\t")
	switch doCmd {
	case "quit":
		c.SendTextMsg("Stopping bot!", data.ChanID)
		c.Stop()
	case "hello":
		c.SendTextMsg("Hello World!", data.ChanID)
	case "version":
		c.SendTextMsg("Running version: " + discord.Version(), data.ChanID)
	default:
		c.SendTextMsg(fmt.Sprintf("I don't know how to %s.", doCmd), data.ChanID)
	}
}

func callback(cl discord.Discord, event string, data interface{}) {
	fmt.Println("\tuser callback called:", event)
	if mc, ok := data.(discord.MESSAGE_CREATE); ok {
		parseCmd(cl, mc)
	}
	fmt.Println()
}


func main() {
	client, err := discord.Login("temp1@example.com", "12345")
	if err != nil {
		fmt.Println(err)
		return
	}
	if client.Client == nil {
		fmt.Println("Empty client!  Check your network connection.")
		return
	}
	fmt.Println("Attempting websocket connection...")
	call := discord.Callback(callback)
	err = client.WSConnect(&call) // required if websockets is desired
	if err != nil {
		fmt.Println("websocket error:", err)
	} else {
		fmt.Println("websocket connected!")
	}
	defer func() {
		err = client.Logout()
		if err != nil {
			fmt.Println(err)
		}
	}()
	//other code
}

##Disclaimer This is in ALPHA stage which means nothing is guaranteed to stay the same. Things will likely change, and there will be absolutely NO attempt to maintain backwards compatibility until version 1.0. This means things can and likely will break if this is used, upon upgrading to new versions. Do not use for time- or safety-critical tasks. You have been warned.

##Other libraries

Documentation

Index

Constants

View Source
const (
	APIURL          = "https://discordapp.com/api"
	GatewayURL      = APIURL + "/gateway"
	AuthURL         = APIURL + "/auth"
	LoginURL        = AuthURL + "/login"  //post
	LogoutURL       = AuthURL + "/logout" //post
	RegisterURL     = AuthURL + "/register"
	VerifyURL       = AuthURL + "/verify"
	VerifyResendURL = VerifyURL + "/resend"
	ForgotURL       = AuthURL + "/forgot"
	ResetURL        = AuthURL + "/reset"

	InviteURL = APIURL + "/invite/%s" //invite ID (get forinfo, post to accept)

	GuildsURL            = APIURL + "/guilds" //get for list, post for new, patch for edit)
	GuildIDURL           = GuildsURL + "/%s"  //guild (server) ID
	GuildBansURL         = GuildIDURL + "/bans"
	GuildBanIDURL        = GuildBansURL + "/%s"
	GuildMembersURL      = GuildIDURL + "/members" // get (being removed)
	GuildMemberIDURL     = GuildMembersURL + "/%s"
	GuildRolesURL        = GuildIDURL + "/roles"    // get, patch
	GuildRoleIDURL       = GuildRolesURL + "/%s"    // get?, put?, patch
	GuildChansURL        = GuildIDURL + "/channels" // get
	GuildInvitesURL      = GuildIDURL + "/invites"
	GuildPruneURL        = GuildIDURL + "/prune"
	GuildEmbedURL        = GuildIDURL + "/embed"
	GuildIntegrationsURL = GuildIDURL + "/integrations"

	ChansURL      = APIURL + "/channels"       // chanID
	ChanIDURL     = ChansURL + "/%s"           // chanID
	ChanMsgsURL   = ChanIDURL + "/messages"    // chanID (get)
	MsgURL        = ChanMsgsURL + "/%s"        //channel ID, message ID (Patch edit, delete del)
	MsgAckURL     = MsgURL + "/ack"            //channel ID, message ID (Post)
	ChanInviteURL = ChanIDURL + "/invites"     // chanID
	ChanTypingURL = ChanIDURL + "/typing"      // chanID (post only)
	ChanPermsURL  = ChanIDURL + "/permissions" // chanID
	ChanPermIDURL = ChanPermsURL + "/%s"       // chanID, permID

	UsersURL         = APIURL + "/users"       //invite ID
	UserIDURL        = UsersURL + "/%s"        // user ID
	UserChansURL     = UserIDURL + "/channels" //(get chans)
	UserGuildsURL    = UserIDURL + "/guilds"   // get
	UserAvatarsURL   = UserIDURL + "/avatars"  // get
	UserAvatarIDURL  = UserAvatarsURL + "/%s"  // avatar ID
	MyURL            = UsersURL + "/@me"
	MySettingsURL    = MyURL + "/settings"    // get
	MyDevicesURL     = MyURL + "/devices"     // get
	MyConnectionsURL = MyURL + "/connections" // get
	MyChansURL       = MyURL + "/channels"
	MyGuildsURL      = MyURL + "/guilds"
	VoiceURL         = APIURL + "/voice"
	VoiceRegionsURL  = VoiceURL + "/regions"
	VoiceIceURL      = VoiceURL + "/ice"
	TutorialURL      = APIURL + "/tutorial"
	TutorialIndURL   = TutorialURL + "/indicators"
)

Variables

This section is empty.

Functions

func Version

func Version() string

func VersionString

func VersionString() string

Types

type Attachment

type Attachment struct {
	URL      string `json:"url"`              //URL of downloadable object
	ProxyURL string `json:"proxy_url"`        //URL of ?
	Size     int    `json:"size"`             //size in bytes
	ID       string `json:"id"`               //id of attachment
	Filename string `json:"filename"`         //filename
	Width    int    `json:"width,omitempty"`  //image width
	Height   int    `json:"height,omitempty"` //image height
}

type CHANNEL_CREATE

type CHANNEL_CREATE Channel

type CHANNEL_DELETE

type CHANNEL_DELETE Channel

type CHANNEL_UPDATE

type CHANNEL_UPDATE Channel

type Callback

type Callback func(c Discord, event string, data interface{})

type Channel

type Channel struct {
	GuildID     string     `json:"guild_id,omitempty"`
	Name        string     `json:"name,omitempty"`
	Permissions []PermOver `json:"permission_overwrites,omitempty"`
	Topic       *string    `json:"topic,omitempty"` // can be null
	Position    int        `json:"position,omitempty"`
	LastMsgID   *string    `json:"last_message_id"`     // can be null
	Recipient   *User      `json:"recipient,omitempty"` //only exists if private
	Type        string     `json:"type,omitempty"`      //only exists if not private (text|voice)
	ID          string     `json:"id"`
	Private     bool       `json:"is_private"`
}

type Connection

type Connection struct {
	Integrations []Integration `json:"integrations"`
	Revoked      bool          `json:"revoked"`
	Type         string        `json:"type"`
	ID           string        `json:"id"`
	Name         string        `json:"name"`
}

type Creds

type Creds struct {
	Email []string `json:"email"`
	Pass  []string `json:"password"`
	Token string   `json:"token,omitempty"`
}

type CredsError

type CredsError Creds

func (CredsError) Error

func (e CredsError) Error() string

type Discord

type Discord struct {
	Client    *http.Client
	Token     string
	LoggingIn bool

	Me *User
	// contains filtered or unexported fields
}

func Login

func Login(email, pass string) (Discord, error)

func (Discord) AckMsg

func (c Discord) AckMsg(msg Message) (err error)

func (*Discord) AddChan

func (c *Discord) AddChan(gIdx int, ch Channel)

func (*Discord) AddGuild

func (c *Discord) AddGuild(g Guild)

func (*Discord) AddGuildRole

func (c *Discord) AddGuildRole(gIdx int, r Role)

func (Discord) Cache

func (c Discord) Cache() *READY

func (Discord) Chan

func (c Discord) Chan(guildID, name string) (Channel, error)

func (Discord) ChanDelete

func (c Discord) ChanDelete(chanID string) (err error)

func (Discord) ChanDeletePerms

func (c Discord) ChanDeletePerms(chanID, permID string) (err error)

func (Discord) ChanEdit

func (c Discord) ChanEdit(chanID, name string, topic *string) (resp Channel, err error)

func (Discord) ChanID

func (c Discord) ChanID(guildID, name string) (string, error)

func (Discord) ChanInviteAllCreate

func (c Discord) ChanInviteAllCreate(chanID string, age, uses *uint, temp, xkcd *bool, code *string) (Invite, error)

{"max_age":1800,"max_uses":0,"temporary":false,"xkcdpass":true} defaults: 1 day, 0, false, false TODO Disallow validate if anything else is there

func (Discord) ChanInviteCreate

func (c Discord) ChanInviteCreate(chanID string) (Invite, error)

func (Discord) ChanInviteValidate

func (c Discord) ChanInviteValidate(chanID, code string) (Invite, error)

func (Discord) ChanInvites

func (c Discord) ChanInvites(chanID string) (resp []Invite, err error)

func (Discord) ChanReplacePerms

func (c Discord) ChanReplacePerms(chanID string, ur userOrRole, allow, deny Perm) (err error)

func (*Discord) ChannelParseWS

func (c *Discord) ChannelParseWS(event string, ch Channel)

func (*Discord) CreatePrivateChan

func (c *Discord) CreatePrivateChan(userID string) (resp Channel, err error)

* Pehaps not 100% POST compliant, but creates channel if it doesn't already exist * on a different URL

func (Discord) DelMsg

func (c Discord) DelMsg(msg Message) (err error)

func (Discord) Delete

func (c Discord) Delete(url string) error

func (Discord) DeletePrivateChan

func (c Discord) DeletePrivateChan(userID string) error

* Note that this does not remove message history; only removes the channel from * the list of private chats you have open. * The current implementation is to find it in our cache, then delete it using DeleteChannel(). * This could change in the future.

func (Discord) EditMsg

func (c Discord) EditMsg(msg Message, newMsg string, usrs []User) (Message, error)

func (Discord) EditTextMsg

func (c Discord) EditTextMsg(msg Message, newMsg string) (Message, error)

func (Discord) Gateway

func (c Discord) Gateway() (string, error)

func (Discord) Get

func (c Discord) Get(url string, resp interface{}) error

func (Discord) GetMsgs

func (c Discord) GetMsgs(chanID, before, after string, limit int) ([]Message, error)

func (Discord) GetMyGuilds

func (c Discord) GetMyGuilds() (resp []Guild, err error)

func (Discord) GetMyPrivateChans

func (c Discord) GetMyPrivateChans() (resp []Channel, err error)

func (Discord) Guild

func (c Discord) Guild(name string) (Guild, error)

func (Discord) GuildAddBan

func (c Discord) GuildAddBan(guildID, userID string, days int) (err error)

func (Discord) GuildAddNamedRole

func (c Discord) GuildAddNamedRole(guildID, name string) (resp Role, err error)

func (Discord) GuildAddRole

func (c Discord) GuildAddRole(guildID string) (resp Role, err error)

func (*Discord) GuildBanParseWS

func (c *Discord) GuildBanParseWS(event string, b WSBan)

func (Discord) GuildBans

func (c Discord) GuildBans(guildID string) (resp []User, err error)

func (Discord) GuildChanCreate

func (c Discord) GuildChanCreate(guildID, name, kind string) (resp Channel, err error)

func (Discord) GuildChannels

func (c Discord) GuildChannels(guildID string) (resp []Channel, err error)

func (Discord) GuildCreate

func (c Discord) GuildCreate(name, region string) (resp Guild, err error)

func (Discord) GuildDeleteRole

func (c Discord) GuildDeleteRole(guildID, roleID string) (err error)

func (Discord) GuildEdit

func (c Discord) GuildEdit(guildID, name, region string) (resp Guild, err error)

func (Discord) GuildEditRole

func (c Discord) GuildEditRole(guildID string, r Role) (resp Role, err error)

func (Discord) GuildEmbed

func (c Discord) GuildEmbed(guildID string) (resp EmbedInfo, err error)

func (Discord) GuildFindMember

func (c Discord) GuildFindMember(guildID, n string) ([]Member, error)

func (Discord) GuildID

func (c Discord) GuildID(name string) (string, error)

func (Discord) GuildIntegrations

func (c Discord) GuildIntegrations(guildID string) (resp []Integration, err error)

func (Discord) GuildInvitesList

func (c Discord) GuildInvitesList(guildID string) (resp []Invite, err error)

func (Discord) GuildLeave

func (c Discord) GuildLeave(guildID string) (err error)

func (Discord) GuildMemberEdit

func (c Discord) GuildMemberEdit(guildID, userID string, roleIDs []string) (err error)

func (Discord) GuildMemberKick

func (c Discord) GuildMemberKick(guildID, userID string) (err error)

func (*Discord) GuildMemberParseWS

func (c *Discord) GuildMemberParseWS(event string, m Member)

func (Discord) GuildMembers

func (c Discord) GuildMembers(guildID string) (resp []Member, err error)

now use cache instead

func (*Discord) GuildParseWS

func (c *Discord) GuildParseWS(event string, g Guild)

func (Discord) GuildPruneInfo

func (c Discord) GuildPruneInfo(guildID string, days int) (int, error)

func (Discord) GuildRemoveBan

func (c Discord) GuildRemoveBan(guildID, userID string) (err error)

func (*Discord) GuildRoleParseWS

func (c *Discord) GuildRoleParseWS(event string, r WSRole)

func (Discord) GuildRoles

func (c Discord) GuildRoles(guildID string) (resp []Role, err error)

func (Discord) Guilds

func (c Discord) Guilds() []Guild

func (Discord) InviteAccept

func (c Discord) InviteAccept(code string) (resp Invite, err error)

func (Discord) InviteInfo

func (c Discord) InviteInfo(code string) (resp Invite, err error)

validation of code returns full invite

func (Discord) InviteRevoke

func (c Discord) InviteRevoke(code string) (err error)

func (Discord) Logout

func (c Discord) Logout() (err error)

func (Discord) Patch

func (c Discord) Patch(url string, req, resp interface{}) error

func (Discord) Post

func (c Discord) Post(url string, req, resp interface{}) error

func (Discord) PrivateChan

func (c Discord) PrivateChan(name string) (Channel, error)

func (*Discord) PrivateChanDelete

func (c *Discord) PrivateChanDelete(chanID string) (err error)

func (Discord) PrivateChanFromID

func (c Discord) PrivateChanFromID(ID string) (Channel, error)

func (Discord) PrivateChanID

func (c Discord) PrivateChanID(name string) (string, error)

func (*Discord) PrivateChannelParseWS

func (c *Discord) PrivateChannelParseWS(event string, ch Channel)

func (Discord) Put

func (c Discord) Put(url string, req interface{}) error

func (*Discord) RemChanIdx

func (c *Discord) RemChanIdx(gIdx, idx int)

func (*Discord) RemGuildIdx

func (c *Discord) RemGuildIdx(idx int)

func (*Discord) RemGuildRoleIdx

func (c *Discord) RemGuildRoleIdx(gIdx, idx int)

func (Discord) SendMsg

func (c Discord) SendMsg(message, chanID string, usrs []User) (Message, error)

func (Discord) SendRawMsg

func (c Discord) SendRawMsg(message, chanID string, ids []string) (resp Message, err error)

TODO: for 0.7.1, add abiltity to change TTS TODO: for 0.7.1, change to use <@ID> only For now, this means SendTextMsg is a workaround

func (Discord) SendTextMsg

func (c Discord) SendTextMsg(message, chanID string) (Message, error)

func (Discord) SendTyping

func (c Discord) SendTyping(chanID string) (err error)

func (Discord) SetMaxRuntime

func (c Discord) SetMaxRuntime(amt time.Duration, expireMsg string)

func (Discord) SetUserSettings

func (c Discord) SetUserSettings(s Setting) (err error)

func (Discord) Stop

func (c Discord) Stop()

func (Discord) TutorialInfo

func (c Discord) TutorialInfo() (req Tutorial, err error)

func (Discord) UserConnections

func (c Discord) UserConnections() (req []Connection, err error)

func (Discord) UserSettings

func (c Discord) UserSettings() (req Setting, err error)

func (Discord) VoiceIce

func (c Discord) VoiceIce() (resp Ice, err error)

func (Discord) VoiceRegions

func (c Discord) VoiceRegions() (resp []Region, err error)

func (Discord) WSConnect

func (c Discord) WSConnect(call *Callback) (err error)

func (Discord) WSInit

func (c Discord) WSInit(con *websocket.Conn, msgChan chan WSMsg)

func (*Discord) WSProcess

func (c *Discord) WSProcess(con *websocket.Conn, msgSend, msgRead chan WSMsg, CB *Callback)

type Embed

type Embed struct {
	Desc     *string    `json:"description"`
	Author   *Entity    `json:"author,omitempty"`
	URL      string     `json:"url"`
	Title    *string    `json:"title"`
	Provider *Entity    `json:"provider,omitempty"`
	Type     string     `json:"type"`
	Thumb    *Thumbnail `json:"thumbnail,omitempty"`
	Video    *Video     `json:"video,omitempty"`
}

type EmbedInfo

type EmbedInfo struct {
	ChanID  *string `json:"channel_id"`
	Enabled bool    `json:"enabled"`
}

type EncodingFromError

type EncodingFromError string

func (EncodingFromError) Error

func (e EncodingFromError) Error() string

type EncodingToError

type EncodingToError string

func (EncodingToError) Error

func (e EncodingToError) Error() string

type Entity

type Entity struct {
	URL  *string `json:"url"` //can be null
	Name string  `json:"name"`
}

type GUILD_BAN_ADD

type GUILD_BAN_ADD WSBan

type GUILD_BAN_REMOVE

type GUILD_BAN_REMOVE WSBan

type GUILD_CREATE

type GUILD_CREATE Guild

type GUILD_DELETE

type GUILD_DELETE Guild

type GUILD_INTEGRATIONS_UPDATE

type GUILD_INTEGRATIONS_UPDATE struct {
	GuildID string `json:"guild_id"`
}

type GUILD_MEMBER_ADD

type GUILD_MEMBER_ADD Member

type GUILD_MEMBER_REMOVE

type GUILD_MEMBER_REMOVE Member

type GUILD_MEMBER_UPDATE

type GUILD_MEMBER_UPDATE Member

type GUILD_ROLE_CREATE

type GUILD_ROLE_CREATE struct {
	GuildID string `json:"guild_id"`
	Role    Role   `json:"role"`
}

func (GUILD_ROLE_CREATE) GetGuildID

func (m GUILD_ROLE_CREATE) GetGuildID() string

func (GUILD_ROLE_CREATE) GetRole

func (m GUILD_ROLE_CREATE) GetRole() Role

func (GUILD_ROLE_CREATE) GetRoleID

func (m GUILD_ROLE_CREATE) GetRoleID() string

type GUILD_ROLE_DELETE

type GUILD_ROLE_DELETE struct {
	GuildID string `json:"guild_id"`
	RoleID  string `json:"role_id"`
}

func (GUILD_ROLE_DELETE) GetGuildID

func (m GUILD_ROLE_DELETE) GetGuildID() string

func (GUILD_ROLE_DELETE) GetRole

func (m GUILD_ROLE_DELETE) GetRole() Role

func (GUILD_ROLE_DELETE) GetRoleID

func (m GUILD_ROLE_DELETE) GetRoleID() string

type GUILD_ROLE_UPDATE

type GUILD_ROLE_UPDATE struct {
	GuildID string `json:"guild_id"`
	Role    Role   `json:"role"`
}

func (GUILD_ROLE_UPDATE) GetGuildID

func (m GUILD_ROLE_UPDATE) GetGuildID() string

func (GUILD_ROLE_UPDATE) GetRole

func (m GUILD_ROLE_UPDATE) GetRole() Role

func (GUILD_ROLE_UPDATE) GetRoleID

func (m GUILD_ROLE_UPDATE) GetRoleID() string

type GUILD_UPDATE

type GUILD_UPDATE Guild

type Game

type Game struct {
	Name string `json:"name"`
}

func (*Game) UnmarshalJSON

func (m *Game) UnmarshalJSON(raw []byte) (err error)

type Guild

type Guild struct {
	VoiceStates []WSVoiceState `json:"voice_states"` //only READY
	Roles       []Role         `json:"roles"`
	Region      string         `json:"region"`
	Presences   []WSPres       `json:"presences"` // only READY
	OwnerID     string         `json:"owner_id"`
	Name        string         `json:"name"`
	//Large        bool           `json:"large"` //only READY
	Members      []Member  `json:"members"` //only READY
	JoinedAt     time.Time `json:"joined_at"`
	ID           string    `json:"id"`
	Icon         *string   `json:"icon"`
	Channels     []Channel `json:"channels"` // only READY
	AfkTimeout   uint64    `json:"afk_timeout"`
	AfkChannelID *string   `json:"afk_channel_id"`
	Unavailable  *bool     `json:"unavailable,omitempty"` // if present, state changed
}

func (*Guild) AddMember

func (g *Guild) AddMember(m Member)

func (*Guild) RemMember

func (g *Guild) RemMember(m Member)

func (*Guild) RemMemberIdx

func (g *Guild) RemMemberIdx(idx int)

type HTTPError

type HTTPError http.Response

func (HTTPError) Error

func (e HTTPError) Error() string

type Heartbeat

type Heartbeat time.Time //op 1

type IDNotFoundError

type IDNotFoundError string

func (IDNotFoundError) Error

func (c IDNotFoundError) Error() string

type INIT

type INIT struct {
	Token       string      `json:"token"`
	Version     int         `json:"v"`
	Properties  *Properties `json:"properties,omitempty"`
	LargeThresh int         `json:"large_threshold,omitempty"`
	Compress    bool        `json:"compress,omitempty"`
}

type Ice

type Ice struct {
	TTL     string   `json:"ttl"`
	Servers []Server `json:"servers"`
}

type Integration

type Integration string

type InvalidTypeError

type InvalidTypeError string

func (InvalidTypeError) Error

func (e InvalidTypeError) Error() string

type Invite

type Invite struct {
	MaxAge int    `json:"max_age"`
	Code   string `json:"code"`
	Guild  struct {
		ID   string `json:"id"`
		Name string `json:"name"`
	} `json:"guild"`
	Revoked   bool      `json:"revoked"`
	CreatedAt time.Time `json:"created_at"`
	Temporary bool      `json:"temporary"`
	Uses      int       `json:"uses"`
	MaxUses   int       `json:"max_uses"`
	Inviter   User      `json:"inviter"`
	XKCDpass  *string   `json:"xkcdpass"`
	Chan      Channel   `json:"channel"`
}

type MESSAGE_ACK

type MESSAGE_ACK struct {
	MessageID string `json:"message_id"`
	ChannelID string `json:"channel_id"`
}

type MESSAGE_CREATE

type MESSAGE_CREATE Message

func (*MESSAGE_CREATE) UnmarshalJSON

func (m *MESSAGE_CREATE) UnmarshalJSON(raw []byte) (err error)

type MESSAGE_DELETE

type MESSAGE_DELETE Message

type MESSAGE_UPDATE

type MESSAGE_UPDATE Message

type Member

type Member struct {
	GuildID string    `json:"guild_id,omitempty"`
	Joined  time.Time `json:"joined_at"`
	Deaf    bool      `json:"deaf"`
	User    User      `json:"user"`
	Roles   []string  `json:"roles"`
	Mute    bool      `json:"mute"`
}

type Message

type Message struct {
	Nonce       int64        `json:"nonce,string,omitempty"` //only used when sending messages
	Attachments []Attachment `json:"attachments"`
	Tts         bool         `json:"tts"`
	Embeds      []Embed      `json:"embeds"`
	Timestamp   time.Time    `json:"timestamp"`
	MentionAll  bool         `json:"mention_everyone"`
	ID          string       `json:"id"`
	EditedTime  *time.Time   `json:"edited_timestamp"` //can be null (not worth seperate struct member)
	Author      User         `json:"author"`
	Content     string       `json:"content"`
	ChanID      string       `json:"channel_id"`
	//including json tag magic to have it look for both, and ignore whichever one doesn't exist.
	Mentions []User `json:"mentions,omitempty"` // Users (only receved)
}

type MessageSend

type MessageSend struct {
	Content  string   `json:"content"`
	Mentions []string `json:"mentions,omitempty"` //deprecatd
	Nonce    int64    `json:"nonce,string"`
	Tts      bool     `json:"tts"`
}

Only reason not to remove this is its used evey time we create a message. Theoretically, we could use Message instead, and have the other fields of the struct set to omit from the json if empty, but that would just make everything annoying to read, so this stays seperate for now.

type NameNotFoundError

type NameNotFoundError string

func (NameNotFoundError) Error

func (c NameNotFoundError) Error() string

type PRESENCE_UPDATE

type PRESENCE_UPDATE map[string]interface{}

type Perm

type Perm struct {
	CreateInstantInvite bool
	KickMembers         bool
	BanMembers          bool
	ManageRoles         bool
	ManageChannels      bool
	ManageGuild         bool

	// Text
	ReadMessages       bool
	SendMessages       bool
	SendTssMessages    bool
	ManageMessages     bool
	EmbedLinks         bool
	AttachFiles        bool
	ReadMessageHistory bool
	MentionEveryone    bool

	// Voice
	Connect       bool
	Speak         bool
	MuteMembers   bool
	DeafenMembers bool
	MoveMembers   bool
	UseVad        bool
}

func FromInt

func FromInt(mask int) (p Perm)

func (*Perm) FromInt

func (p *Perm) FromInt(mask int)

func (Perm) MarshalJSON

func (p Perm) MarshalJSON() ([]byte, error)

func (Perm) ToInt

func (p Perm) ToInt() int

func (*Perm) UnmarshalJSON

func (p *Perm) UnmarshalJSON(raw []byte) error

type PermOver

type PermOver struct {
	Deny  Perm   `json:"deny"`
	Type  string `json:"type"`
	ID    string `json:"id"`
	Allow Perm   `json:"allow"`
}

type PermissionsError

type PermissionsError string

func (PermissionsError) Error

func (e PermissionsError) Error() string

type PostError

type PostError string

func (PostError) Error

func (e PostError) Error() string

type PrivateChannel

type PrivateChannel struct {
	LastMsgID *string `json:"last_message_id"`     // can be null
	Recipient *User   `json:"recipient,omitempty"` //only exists if private
	ID        string  `json:"id"`
	Private   bool    `json:"is_private"`
}

type Properties

type Properties struct {
	OS              string `json:"$os"`
	Browser         string `json:"$browser"`
	Device          string `json:"$device"`
	Referrer        string `json:"$referrer"`
	ReferringDomain string `json:"$referring_domain"`
}

type READY

type READY struct {
	Version   int    `json:"v"`
	User      User   `json:"user"`
	SessionId string `json:"session_id"`
	//SessionId         int        `json:"session_id"`//testing error
	ReadState         []State   `json:"read_state"`
	PrivateChannels   []Channel `json:"private_channels"`
	HeartbeatInterval uint64    `json:"heartbeat_interval"`
	Guilds            []Guild   `json:"guilds"`
}

TODO add compression

type RateLimitError

type RateLimitError struct {
	Message    string
	RetryAfter string
}

func (RateLimitError) Error

func (e RateLimitError) Error() string

type ReadError

type ReadError string

func (ReadError) Error

func (e ReadError) Error() string

type Region

type Region struct {
	Hostname string `json:"sample_hostname"`
	Port     uint   `json:"sample_port"`
	ID       string `json:"id"`
	Name     string `json:"name"`
}

type Role

type Role struct {
	Managed     bool   `json:"managed,omitempty"`
	Name        string `json:"name"`
	Color       int    `json:"color"`
	Hoist       bool   `json:"hoist"`
	Position    int    `json:"position,omitempty"`
	ID          string `json:"id,omitempty"`
	Permissions Perm   `json:"permissions"`
}

func (Role) GetID

func (x Role) GetID() string

func (Role) Type

func (x Role) Type() string

type Server

type Server struct {
	URL      string `json:"url"`
	Username string `json:"username,omitempty"`
	Cred     string `json:"credential,omitempty"`
}

type Setting

type Setting struct {
	RenderEmbeds      *bool    `json:"render_embeds,omitempty"`
	InlineEmbedMedia  *bool    `json:"inline_embed_media,omitempty"`
	EnableTTSCmd      *bool    `json:"enable_tts_command,omitempty"`
	MsgDispCompact    *bool    `json:"message_display_compact,omitempty"`
	Locale            string   `json:"locale,omitempty"`
	ShowCurrentGame   *bool    `json:"show_current_game,omitempty"`
	Theme             string   `json:"theme,omitempty"` // emptystring should not be sent
	MutedChanIDs      []string `json:"muted_channels,omitempty"`
	InlineAttachMedia *bool    `json:"inline_attachment_media,omitempty"`
}

type State

type State struct {
	MentionCount  int    `json:"mention_count"`
	LastMessageId string `json:"last_message_id,omitempty"`
	ID            string `json:"id"`
}

type TYPING_START

type TYPING_START struct {
	ChanID string `json:"channel_id"`
	//ChanID    int    `json:"channel_id"`  //check error
	Timestamp uint64 `json:"timestamp"`
	UserID    string `json:"user_id"`
}

type Thumbnail

type Thumbnail struct {
	URL    string `json:"url"`
	Width  int    `json:"width"`
	Proxy  string `json:"proxy_url"`
	Height int    `json:"height"`
}

type TokenError

type TokenError string

func (TokenError) Error

func (e TokenError) Error() string

type Tutorial

type Tutorial struct {
	Confirmed  []string `json:"indicators_confirmed"`
	Suppressed bool     `json:"indicators_suppressed"`
}

type USER_SETTINGS_UPDATE

type USER_SETTINGS_UPDATE Setting

type UnknownError

type UnknownError string

func (UnknownError) Error

func (e UnknownError) Error() string

type User

type User struct {
	Verified      bool    `json:"verified,omitempty"` //only for WS
	Username      string  `json:"username"`
	Email         string  `json:"email,omitempty"` //only for WS
	Discriminator string  `json:"-"`               //4 digits
	ID            string  `json:"id"`
	Avatar        *string `json:"avatar"` // hex string (can be null)
}

func (User) GetID

func (x User) GetID() string

func (User) Type

func (x User) Type() string

func (*User) UnmarshalJSON

func (u *User) UnmarshalJSON(raw []byte) (err error)

type VOICE_STATE_UPDATE

type VOICE_STATE_UPDATE WSVoiceState

type Video

type Video struct {
	URL    string `json:"url"`
	Width  int    `json:"width"`
	Height int    `json:"height"`
}

type WSBan

type WSBan struct {
	GuildID string `json:"guild_id"`
	User    User   `json:"user"`
}

* means unparsed + means implemented with cache x means not planning to implement - means eventual new event = means not fully impemented ? means possible new event

    +CHANNEL_CREATE
    ?CHANNEL_CREATE (private)
    +CHANNEL_DELETE
    ?CHANNEL_DELETE (private)
    +CHANNEL_UPDATE
    +GUILD_CREATE
    -GUILD_CREATE (unavailable)
    +GUILD_DELETE
    -GUILD_DELETE (unavailable)
    +GUILD_UPDATE
    =GUILD_BAN_ADD
    =GUILD_BAN_REMOVE
    +GUILD_MEMBER_ADD
    +GUILD_MEMBER_REMOVE
    +GUILD_MEMBER_UPDATE
    +GUILD_ROLE_CREATE
    +GUILD_ROLE_DELETE
    +GUILD_ROLE_UPDATE
    GUILD_INTEGRATIONS_UPDATE
    MESSAGE_CREATE
    MESSAGE_DELETE
    MESSAGE_UPDATE
    MESSAGE_UPDATE (embeds only)
    +PRESENCE_UPDATE
    +READY
    xTYPING_START //pointless for bots?
    USER_SETTINGS_UPDATE //unsure if this is really needed
    VOICE_STATE_UPDATE
	xMESSAGE_ACK //unimportant,clients only
    OP 7

type WSMsg

type WSMsg struct {
	Type string      `json:"t,omitempty"`
	Seq  int         `json:"s,omitempty"`
	Op   int         `json:"op"`
	Data interface{} `json:"d"` //deferred until we know what it is.
	// contains filtered or unexported fields
}

func (*WSMsg) UnmarshalJSON

func (m *WSMsg) UnmarshalJSON(raw []byte) (err error)

type WSPres

type WSPres struct {
	User    User     `json:"user"`
	Status  string   `json:"status"`
	Roles   []string `json:"roles,omitempty"`
	GuildID string   `json:"guild_id,omitempty"`
	Game    *Game    `json:"game"`
}

func (WSPres) Playing

func (p WSPres) Playing() *string

type WSRole

type WSRole interface {
	GetGuildID() string
	GetRoleID() string
	GetRole() Role
}

type WSVoiceState

type WSVoiceState struct {
	UserID    string  `json:"user_id"`
	Token     string  `json:"token"`
	Suppress  bool    `json:"suppress"`
	SessionID string  `json:"session_id"`
	SelfMute  *bool   `json:"self_mute"`
	SelfDeaf  *bool   `json:"self_deaf"`
	Mute      bool    `json:"mute"`
	Deaf      bool    `json:"deaf"`
	ChannelID *string `json:"channel_id"`
	GuildID   string  `json:"guild_id"`
}

Jump to

Keyboard shortcuts

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