Merge remote-tracking branch 'bwmarrin/develop' into stateperf
This commit is contained in:
commit
be8e0de5c6
7 changed files with 183 additions and 183 deletions
|
@ -57,7 +57,7 @@ func main() {
|
||||||
|
|
||||||
// This function will be called (due to above assignment) every time a new
|
// This function will be called (due to above assignment) every time a new
|
||||||
// message is created on any channel that the autenticated user has access to.
|
// message is created on any channel that the autenticated user has access to.
|
||||||
func messageCreate(s *discordgo.Session, m discordgo.Message) {
|
func messageCreate(s *discordgo.Session, m *discordgo.Message) {
|
||||||
|
|
||||||
// Print message to stdout.
|
// Print message to stdout.
|
||||||
fmt.Printf("%20s %20s %20s > %s\n", m.ChannelID, time.Now().Format(time.Stamp), m.Author.Username, m.Content)
|
fmt.Printf("%20s %20s %20s > %s\n", m.ChannelID, time.Now().Format(time.Stamp), m.Author.Username, m.Content)
|
||||||
|
|
|
@ -39,7 +39,7 @@ func main() {
|
||||||
|
|
||||||
// This function will be called (due to above assignment) every time a new
|
// This function will be called (due to above assignment) every time a new
|
||||||
// message is created on any channel that the autenticated user has access to.
|
// message is created on any channel that the autenticated user has access to.
|
||||||
func messageCreate(s *discordgo.Session, m discordgo.Message) {
|
func messageCreate(s *discordgo.Session, m *discordgo.Message) {
|
||||||
|
|
||||||
// Print message to stdout.
|
// Print message to stdout.
|
||||||
fmt.Printf("%20s %20s %20s > %s\n", m.ChannelID, time.Now().Format(time.Stamp), m.Author.Username, m.Content)
|
fmt.Printf("%20s %20s %20s > %s\n", m.ChannelID, time.Now().Format(time.Stamp), m.Author.Username, m.Content)
|
||||||
|
|
|
@ -17,15 +17,15 @@ import (
|
||||||
// A Message stores all data related to a specific Discord message.
|
// A Message stores all data related to a specific Discord message.
|
||||||
type Message struct {
|
type Message struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
Author User `json:"author"`
|
Author *User `json:"author"`
|
||||||
Content string `json:"content"`
|
Content string `json:"content"`
|
||||||
Attachments []Attachment `json:"attachments"`
|
Attachments []*Attachment `json:"attachments"`
|
||||||
Tts bool `json:"tts"`
|
Tts bool `json:"tts"`
|
||||||
Embeds []Embed `json:"embeds"`
|
Embeds []*Embed `json:"embeds"`
|
||||||
Timestamp string `json:"timestamp"`
|
Timestamp string `json:"timestamp"`
|
||||||
MentionEveryone bool `json:"mention_everyone"`
|
MentionEveryone bool `json:"mention_everyone"`
|
||||||
EditedTimestamp string `json:"edited_timestamp"`
|
EditedTimestamp string `json:"edited_timestamp"`
|
||||||
Mentions []User `json:"mentions"`
|
Mentions []*User `json:"mentions"`
|
||||||
ChannelID string `json:"channel_id"`
|
ChannelID string `json:"channel_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
60
restapi.go
60
restapi.go
|
@ -165,7 +165,7 @@ func (s *Session) User(userID string) (st User, err error) {
|
||||||
|
|
||||||
// UserUpdate updates a users settings.
|
// UserUpdate updates a users settings.
|
||||||
// userID : A user ID or "@me" which is a shortcut of current user ID
|
// userID : A user ID or "@me" which is a shortcut of current user ID
|
||||||
func (s *Session) UserUpdate(userID, email, password, username, avatar, newPassword string) (st User, err error) {
|
func (s *Session) UserUpdate(userID, email, password, username, avatar, newPassword string) (st *User, err error) {
|
||||||
|
|
||||||
// NOTE: Avatar must be either the hash/id of existing Avatar or
|
// NOTE: Avatar must be either the hash/id of existing Avatar or
|
||||||
// data:image/png;base64,BASE64_STRING_OF_NEW_AVATAR_PNG
|
// data:image/png;base64,BASE64_STRING_OF_NEW_AVATAR_PNG
|
||||||
|
@ -198,7 +198,7 @@ func (s *Session) UserAvatar(userID string) (st User, err error) {
|
||||||
// UserSettings returns the settings for a given user
|
// UserSettings returns the settings for a given user
|
||||||
// userID : A user ID or "@me" which is a shortcut of current user ID
|
// userID : A user ID or "@me" which is a shortcut of current user ID
|
||||||
// This seems to only return a result for "@me"
|
// This seems to only return a result for "@me"
|
||||||
func (s *Session) UserSettings(userID string) (st Settings, err error) {
|
func (s *Session) UserSettings(userID string) (st *Settings, err error) {
|
||||||
|
|
||||||
body, err := s.Request("GET", USER_SETTINGS(userID), nil)
|
body, err := s.Request("GET", USER_SETTINGS(userID), nil)
|
||||||
err = json.Unmarshal(body, &st)
|
err = json.Unmarshal(body, &st)
|
||||||
|
@ -208,7 +208,7 @@ func (s *Session) UserSettings(userID string) (st Settings, err error) {
|
||||||
// UserChannels returns an array of Channel structures for all private
|
// UserChannels returns an array of Channel structures for all private
|
||||||
// channels for a user
|
// channels for a user
|
||||||
// userID : A user ID or "@me" which is a shortcut of current user ID
|
// userID : A user ID or "@me" which is a shortcut of current user ID
|
||||||
func (s *Session) UserChannels(userID string) (st []Channel, err error) {
|
func (s *Session) UserChannels(userID string) (st []*Channel, err error) {
|
||||||
|
|
||||||
body, err := s.Request("GET", USER_CHANNELS(userID), nil)
|
body, err := s.Request("GET", USER_CHANNELS(userID), nil)
|
||||||
err = json.Unmarshal(body, &st)
|
err = json.Unmarshal(body, &st)
|
||||||
|
@ -218,7 +218,7 @@ func (s *Session) UserChannels(userID string) (st []Channel, err error) {
|
||||||
// UserChannelCreate creates a new User (Private) Channel with another User
|
// UserChannelCreate creates a new User (Private) Channel with another User
|
||||||
// userID : A user ID or "@me" which is a shortcut of current user ID
|
// userID : A user ID or "@me" which is a shortcut of current user ID
|
||||||
// recipientID : A user ID for the user to which this channel is opened with.
|
// recipientID : A user ID for the user to which this channel is opened with.
|
||||||
func (s *Session) UserChannelCreate(userID, recipientID string) (st Channel, err error) {
|
func (s *Session) UserChannelCreate(userID, recipientID string) (st *Channel, err error) {
|
||||||
|
|
||||||
data := struct {
|
data := struct {
|
||||||
RecipientID string `json:"recipient_id"`
|
RecipientID string `json:"recipient_id"`
|
||||||
|
@ -235,7 +235,7 @@ func (s *Session) UserChannelCreate(userID, recipientID string) (st Channel, err
|
||||||
|
|
||||||
// UserGuilds returns an array of Guild structures for all guilds for a given user
|
// UserGuilds returns an array of Guild structures for all guilds for a given user
|
||||||
// userID : A user ID or "@me" which is a shortcut of current user ID
|
// userID : A user ID or "@me" which is a shortcut of current user ID
|
||||||
func (s *Session) UserGuilds(userID string) (st []Guild, err error) {
|
func (s *Session) UserGuilds(userID string) (st []*Guild, err error) {
|
||||||
|
|
||||||
body, err := s.Request("GET", USER_GUILDS(userID), nil)
|
body, err := s.Request("GET", USER_GUILDS(userID), nil)
|
||||||
err = json.Unmarshal(body, &st)
|
err = json.Unmarshal(body, &st)
|
||||||
|
@ -248,7 +248,7 @@ func (s *Session) UserGuilds(userID string) (st []Guild, err error) {
|
||||||
|
|
||||||
// Guild returns a Guild structure of a specific Guild.
|
// Guild returns a Guild structure of a specific Guild.
|
||||||
// guildID : The ID of a Guild
|
// guildID : The ID of a Guild
|
||||||
func (s *Session) Guild(guildID string) (st Guild, err error) {
|
func (s *Session) Guild(guildID string) (st *Guild, err error) {
|
||||||
|
|
||||||
body, err := s.Request("GET", GUILD(guildID), nil)
|
body, err := s.Request("GET", GUILD(guildID), nil)
|
||||||
err = json.Unmarshal(body, &st)
|
err = json.Unmarshal(body, &st)
|
||||||
|
@ -257,7 +257,7 @@ func (s *Session) Guild(guildID string) (st Guild, err error) {
|
||||||
|
|
||||||
// GuildCreate creates a new Guild
|
// GuildCreate creates a new Guild
|
||||||
// name : A name for the Guild (2-100 characters)
|
// name : A name for the Guild (2-100 characters)
|
||||||
func (s *Session) GuildCreate(name string) (st Guild, err error) {
|
func (s *Session) GuildCreate(name string) (st *Guild, err error) {
|
||||||
|
|
||||||
data := struct {
|
data := struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
|
@ -271,7 +271,7 @@ func (s *Session) GuildCreate(name string) (st Guild, err error) {
|
||||||
// GuildEdit edits a new Guild
|
// GuildEdit edits a new Guild
|
||||||
// guildID : The ID of a Guild
|
// guildID : The ID of a Guild
|
||||||
// name : A name for the Guild (2-100 characters)
|
// name : A name for the Guild (2-100 characters)
|
||||||
func (s *Session) GuildEdit(guildID, name string) (st Guild, err error) {
|
func (s *Session) GuildEdit(guildID, name string) (st *Guild, err error) {
|
||||||
|
|
||||||
data := struct {
|
data := struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
|
@ -284,7 +284,7 @@ func (s *Session) GuildEdit(guildID, name string) (st Guild, err error) {
|
||||||
|
|
||||||
// GuildDelete deletes or leaves a Guild.
|
// GuildDelete deletes or leaves a Guild.
|
||||||
// guildID : The ID of a Guild
|
// guildID : The ID of a Guild
|
||||||
func (s *Session) GuildDelete(guildID string) (st Guild, err error) {
|
func (s *Session) GuildDelete(guildID string) (st *Guild, err error) {
|
||||||
|
|
||||||
body, err := s.Request("DELETE", GUILD(guildID), nil)
|
body, err := s.Request("DELETE", GUILD(guildID), nil)
|
||||||
err = json.Unmarshal(body, &st)
|
err = json.Unmarshal(body, &st)
|
||||||
|
@ -294,7 +294,7 @@ func (s *Session) GuildDelete(guildID string) (st Guild, err error) {
|
||||||
// GuildBans returns an array of User structures for all bans of a
|
// GuildBans returns an array of User structures for all bans of a
|
||||||
// given guild.
|
// given guild.
|
||||||
// guildID : The ID of a Guild.
|
// guildID : The ID of a Guild.
|
||||||
func (s *Session) GuildBans(guildID string) (st []User, err error) {
|
func (s *Session) GuildBans(guildID string) (st []*User, err error) {
|
||||||
|
|
||||||
body, err := s.Request("GET", GUILD_BANS(guildID), nil)
|
body, err := s.Request("GET", GUILD_BANS(guildID), nil)
|
||||||
err = json.Unmarshal(body, &st)
|
err = json.Unmarshal(body, &st)
|
||||||
|
@ -339,7 +339,7 @@ func (s *Session) GuildMemberDelete(guildID, userID string) (err error) {
|
||||||
// GuildChannels returns an array of Channel structures for all channels of a
|
// GuildChannels returns an array of Channel structures for all channels of a
|
||||||
// given guild.
|
// given guild.
|
||||||
// guildID : The ID of a Guild.
|
// guildID : The ID of a Guild.
|
||||||
func (s *Session) GuildChannels(guildID string) (st []Channel, err error) {
|
func (s *Session) GuildChannels(guildID string) (st []*Channel, err error) {
|
||||||
|
|
||||||
body, err := s.Request("GET", GUILD_CHANNELS(guildID), nil)
|
body, err := s.Request("GET", GUILD_CHANNELS(guildID), nil)
|
||||||
err = json.Unmarshal(body, &st)
|
err = json.Unmarshal(body, &st)
|
||||||
|
@ -351,7 +351,7 @@ func (s *Session) GuildChannels(guildID string) (st []Channel, err error) {
|
||||||
// guildID : The ID of a Guild.
|
// guildID : The ID of a Guild.
|
||||||
// name : Name of the channel (2-100 chars length)
|
// name : Name of the channel (2-100 chars length)
|
||||||
// ctype : Tpye of the channel (voice or text)
|
// ctype : Tpye of the channel (voice or text)
|
||||||
func (s *Session) GuildChannelCreate(guildID, name, ctype string) (st Channel, err error) {
|
func (s *Session) GuildChannelCreate(guildID, name, ctype string) (st *Channel, err error) {
|
||||||
|
|
||||||
data := struct {
|
data := struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
|
@ -365,7 +365,7 @@ func (s *Session) GuildChannelCreate(guildID, name, ctype string) (st Channel, e
|
||||||
|
|
||||||
// GuildInvites returns an array of Invite structures for the given guild
|
// GuildInvites returns an array of Invite structures for the given guild
|
||||||
// guildID : The ID of a Guild.
|
// guildID : The ID of a Guild.
|
||||||
func (s *Session) GuildInvites(guildID string) (st []Invite, err error) {
|
func (s *Session) GuildInvites(guildID string) (st []*Invite, err error) {
|
||||||
body, err := s.Request("GET", GUILD_INVITES(guildID), nil)
|
body, err := s.Request("GET", GUILD_INVITES(guildID), nil)
|
||||||
err = json.Unmarshal(body, &st)
|
err = json.Unmarshal(body, &st)
|
||||||
return
|
return
|
||||||
|
@ -375,7 +375,7 @@ func (s *Session) GuildInvites(guildID string) (st []Invite, err error) {
|
||||||
// guildID : The ID of a Guild.
|
// guildID : The ID of a Guild.
|
||||||
// i : An Invite struct with the values MaxAge, MaxUses, Temporary,
|
// i : An Invite struct with the values MaxAge, MaxUses, Temporary,
|
||||||
// and XkcdPass defined.
|
// and XkcdPass defined.
|
||||||
func (s *Session) GuildInviteCreate(guildID string, i Invite) (st Invite, err error) {
|
func (s *Session) GuildInviteCreate(guildID string, i Invite) (st *Invite, err error) {
|
||||||
|
|
||||||
data := struct {
|
data := struct {
|
||||||
MaxAge int `json:"max_age"`
|
MaxAge int `json:"max_age"`
|
||||||
|
@ -390,7 +390,7 @@ func (s *Session) GuildInviteCreate(guildID string, i Invite) (st Invite, err er
|
||||||
}
|
}
|
||||||
|
|
||||||
// GuildRoles returns all roles for a given guild.
|
// GuildRoles returns all roles for a given guild.
|
||||||
func (s *Session) GuildRoles(guildID string) (st []Role, err error) {
|
func (s *Session) GuildRoles(guildID string) (st []*Role, err error) {
|
||||||
|
|
||||||
body, err := s.Request("GET", GUILD_ROLES(guildID), nil)
|
body, err := s.Request("GET", GUILD_ROLES(guildID), nil)
|
||||||
err = json.Unmarshal(body, &st)
|
err = json.Unmarshal(body, &st)
|
||||||
|
@ -399,7 +399,7 @@ func (s *Session) GuildRoles(guildID string) (st []Role, err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// GuildRoleCreate returns a new Guild Role
|
// GuildRoleCreate returns a new Guild Role
|
||||||
func (s *Session) GuildRoleCreate(guildID string) (st Role, err error) {
|
func (s *Session) GuildRoleCreate(guildID string) (st *Role, err error) {
|
||||||
|
|
||||||
body, err := s.Request("POST", GUILD_ROLES(guildID), nil)
|
body, err := s.Request("POST", GUILD_ROLES(guildID), nil)
|
||||||
err = json.Unmarshal(body, &st)
|
err = json.Unmarshal(body, &st)
|
||||||
|
@ -408,7 +408,7 @@ func (s *Session) GuildRoleCreate(guildID string) (st Role, err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// GuildRoleEdit updates an existing Guild Role with new values
|
// GuildRoleEdit updates an existing Guild Role with new values
|
||||||
func (s *Session) GuildRoleEdit(guildID, roleID, name string, color int, hoist bool, perm int) (st Role, err error) {
|
func (s *Session) GuildRoleEdit(guildID, roleID, name string, color int, hoist bool, perm int) (st *Role, err error) {
|
||||||
|
|
||||||
data := struct {
|
data := struct {
|
||||||
Name string `json:"name"` // The color the role should have (as a decimal, not hex)
|
Name string `json:"name"` // The color the role should have (as a decimal, not hex)
|
||||||
|
@ -424,7 +424,7 @@ func (s *Session) GuildRoleEdit(guildID, roleID, name string, color int, hoist b
|
||||||
}
|
}
|
||||||
|
|
||||||
// GuildRoleReorder reoders guild roles
|
// GuildRoleReorder reoders guild roles
|
||||||
func (s *Session) GuildRoleReorder(guildID string, roles []Role) (st []Role, err error) {
|
func (s *Session) GuildRoleReorder(guildID string, roles []Role) (st []*Role, err error) {
|
||||||
|
|
||||||
body, err := s.Request("PATCH", GUILD_ROLES(guildID), roles)
|
body, err := s.Request("PATCH", GUILD_ROLES(guildID), roles)
|
||||||
err = json.Unmarshal(body, &st)
|
err = json.Unmarshal(body, &st)
|
||||||
|
@ -446,7 +446,7 @@ func (s *Session) GuildRoleDelete(guildID, roleID string) (err error) {
|
||||||
|
|
||||||
// Channel returns a Channel strucutre of a specific Channel.
|
// Channel returns a Channel strucutre of a specific Channel.
|
||||||
// channelID : The ID of the Channel you want returend.
|
// channelID : The ID of the Channel you want returend.
|
||||||
func (s *Session) Channel(channelID string) (st Channel, err error) {
|
func (s *Session) Channel(channelID string) (st *Channel, err error) {
|
||||||
body, err := s.Request("GET", CHANNEL(channelID), nil)
|
body, err := s.Request("GET", CHANNEL(channelID), nil)
|
||||||
err = json.Unmarshal(body, &st)
|
err = json.Unmarshal(body, &st)
|
||||||
return
|
return
|
||||||
|
@ -455,7 +455,7 @@ func (s *Session) Channel(channelID string) (st Channel, err error) {
|
||||||
// ChannelEdit edits the given channel
|
// ChannelEdit edits the given channel
|
||||||
// channelID : The ID of a Channel
|
// channelID : The ID of a Channel
|
||||||
// name : The new name to assign the channel.
|
// name : The new name to assign the channel.
|
||||||
func (s *Session) ChannelEdit(channelID, name string) (st Channel, err error) {
|
func (s *Session) ChannelEdit(channelID, name string) (st *Channel, err error) {
|
||||||
|
|
||||||
data := struct {
|
data := struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
|
@ -468,7 +468,7 @@ func (s *Session) ChannelEdit(channelID, name string) (st Channel, err error) {
|
||||||
|
|
||||||
// ChannelDelete deletes the given channel
|
// ChannelDelete deletes the given channel
|
||||||
// channelID : The ID of a Channel
|
// channelID : The ID of a Channel
|
||||||
func (s *Session) ChannelDelete(channelID string) (st Channel, err error) {
|
func (s *Session) ChannelDelete(channelID string) (st *Channel, err error) {
|
||||||
|
|
||||||
body, err := s.Request("DELETE", CHANNEL(channelID), nil)
|
body, err := s.Request("DELETE", CHANNEL(channelID), nil)
|
||||||
err = json.Unmarshal(body, &st)
|
err = json.Unmarshal(body, &st)
|
||||||
|
@ -530,7 +530,7 @@ func (s *Session) ChannelMessageAck(channelID, messageID string) (err error) {
|
||||||
// channelID : The ID of a Channel.
|
// channelID : The ID of a Channel.
|
||||||
// content : The message to send.
|
// content : The message to send.
|
||||||
// NOTE, mention and tts parameters may be added in 2.x branch.
|
// NOTE, mention and tts parameters may be added in 2.x branch.
|
||||||
func (s *Session) ChannelMessageSend(channelID string, content string) (st Message, err error) {
|
func (s *Session) ChannelMessageSend(channelID string, content string) (st *Message, err error) {
|
||||||
|
|
||||||
// TODO: nonce string ?
|
// TODO: nonce string ?
|
||||||
data := struct {
|
data := struct {
|
||||||
|
@ -548,7 +548,7 @@ func (s *Session) ChannelMessageSend(channelID string, content string) (st Messa
|
||||||
// the given content.
|
// the given content.
|
||||||
// channeld : The ID of a Channel
|
// channeld : The ID of a Channel
|
||||||
// messageID : the ID of a Message
|
// messageID : the ID of a Message
|
||||||
func (s *Session) ChannelMessageEdit(channelID, messageID, content string) (st Message, err error) {
|
func (s *Session) ChannelMessageEdit(channelID, messageID, content string) (st *Message, err error) {
|
||||||
|
|
||||||
data := struct {
|
data := struct {
|
||||||
Content string `json:"content"`
|
Content string `json:"content"`
|
||||||
|
@ -568,7 +568,7 @@ func (s *Session) ChannelMessageDelete(channelID, messageID string) (err error)
|
||||||
|
|
||||||
// ChannelInvites returns an array of Invite structures for the given channel
|
// ChannelInvites returns an array of Invite structures for the given channel
|
||||||
// channelID : The ID of a Channel
|
// channelID : The ID of a Channel
|
||||||
func (s *Session) ChannelInvites(channelID string) (st []Invite, err error) {
|
func (s *Session) ChannelInvites(channelID string) (st []*Invite, err error) {
|
||||||
body, err := s.Request("GET", CHANNEL_INVITES(channelID), nil)
|
body, err := s.Request("GET", CHANNEL_INVITES(channelID), nil)
|
||||||
err = json.Unmarshal(body, &st)
|
err = json.Unmarshal(body, &st)
|
||||||
return
|
return
|
||||||
|
@ -578,7 +578,7 @@ func (s *Session) ChannelInvites(channelID string) (st []Invite, err error) {
|
||||||
// channelID : The ID of a Channel
|
// channelID : The ID of a Channel
|
||||||
// i : An Invite struct with the values MaxAge, MaxUses, Temporary,
|
// i : An Invite struct with the values MaxAge, MaxUses, Temporary,
|
||||||
// and XkcdPass defined.
|
// and XkcdPass defined.
|
||||||
func (s *Session) ChannelInviteCreate(channelID string, i Invite) (st Invite, err error) {
|
func (s *Session) ChannelInviteCreate(channelID string, i Invite) (st *Invite, err error) {
|
||||||
|
|
||||||
data := struct {
|
data := struct {
|
||||||
MaxAge int `json:"max_age"`
|
MaxAge int `json:"max_age"`
|
||||||
|
@ -622,7 +622,7 @@ func (s *Session) ChannelPermissionDelete(channelID, targetID string) (err error
|
||||||
|
|
||||||
// Invite returns an Invite structure of the given invite
|
// Invite returns an Invite structure of the given invite
|
||||||
// inviteID : The invite code (or maybe xkcdpass?)
|
// inviteID : The invite code (or maybe xkcdpass?)
|
||||||
func (s *Session) Invite(inviteID string) (st Invite, err error) {
|
func (s *Session) Invite(inviteID string) (st *Invite, err error) {
|
||||||
body, err := s.Request("GET", INVITE(inviteID), nil)
|
body, err := s.Request("GET", INVITE(inviteID), nil)
|
||||||
err = json.Unmarshal(body, &st)
|
err = json.Unmarshal(body, &st)
|
||||||
return
|
return
|
||||||
|
@ -630,7 +630,7 @@ func (s *Session) Invite(inviteID string) (st Invite, err error) {
|
||||||
|
|
||||||
// InviteDelete deletes an existing invite
|
// InviteDelete deletes an existing invite
|
||||||
// inviteID : the code (or maybe xkcdpass?) of an invite
|
// inviteID : the code (or maybe xkcdpass?) of an invite
|
||||||
func (s *Session) InviteDelete(inviteID string) (st Invite, err error) {
|
func (s *Session) InviteDelete(inviteID string) (st *Invite, err error) {
|
||||||
|
|
||||||
body, err := s.Request("DELETE", INVITE(inviteID), nil)
|
body, err := s.Request("DELETE", INVITE(inviteID), nil)
|
||||||
err = json.Unmarshal(body, &st)
|
err = json.Unmarshal(body, &st)
|
||||||
|
@ -639,7 +639,7 @@ func (s *Session) InviteDelete(inviteID string) (st Invite, err error) {
|
||||||
|
|
||||||
// InviteAccept accepts an Invite to a Guild or Channel
|
// InviteAccept accepts an Invite to a Guild or Channel
|
||||||
// inviteID : The invite code (or maybe xkcdpass?)
|
// inviteID : The invite code (or maybe xkcdpass?)
|
||||||
func (s *Session) InviteAccept(inviteID string) (st Invite, err error) {
|
func (s *Session) InviteAccept(inviteID string) (st *Invite, err error) {
|
||||||
body, err := s.Request("POST", INVITE(inviteID), nil)
|
body, err := s.Request("POST", INVITE(inviteID), nil)
|
||||||
err = json.Unmarshal(body, &st)
|
err = json.Unmarshal(body, &st)
|
||||||
return
|
return
|
||||||
|
@ -650,7 +650,7 @@ func (s *Session) InviteAccept(inviteID string) (st Invite, err error) {
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
// VoiceRegions returns the voice server regions
|
// VoiceRegions returns the voice server regions
|
||||||
func (s *Session) VoiceRegions() (st []VoiceRegion, err error) {
|
func (s *Session) VoiceRegions() (st []*VoiceRegion, err error) {
|
||||||
|
|
||||||
body, err := s.Request("GET", VOICE_REGIONS, nil)
|
body, err := s.Request("GET", VOICE_REGIONS, nil)
|
||||||
err = json.Unmarshal(body, &st)
|
err = json.Unmarshal(body, &st)
|
||||||
|
@ -658,7 +658,7 @@ func (s *Session) VoiceRegions() (st []VoiceRegion, err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// VoiceICE returns the voice server ICE information
|
// VoiceICE returns the voice server ICE information
|
||||||
func (s *Session) VoiceICE() (st VoiceICE, err error) {
|
func (s *Session) VoiceICE() (st *VoiceICE, err error) {
|
||||||
|
|
||||||
body, err := s.Request("GET", VOICE_ICE, nil)
|
body, err := s.Request("GET", VOICE_ICE, nil)
|
||||||
err = json.Unmarshal(body, &st)
|
err = json.Unmarshal(body, &st)
|
||||||
|
|
40
state.go
40
state.go
|
@ -20,8 +20,8 @@ var nilError error = errors.New("State not instantiated, please use discordgo.Ne
|
||||||
func NewState() *State {
|
func NewState() *State {
|
||||||
return &State{
|
return &State{
|
||||||
Ready: Ready{
|
Ready: Ready{
|
||||||
PrivateChannels: []Channel{},
|
PrivateChannels: []*Channel{},
|
||||||
Guilds: []Guild{},
|
Guilds: []*Guild{},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -47,16 +47,16 @@ func (s *State) GuildAdd(guild *Guild) error {
|
||||||
if g.ID == guild.ID {
|
if g.ID == guild.ID {
|
||||||
// This could be a little faster ;)
|
// This could be a little faster ;)
|
||||||
for _, m := range guild.Members {
|
for _, m := range guild.Members {
|
||||||
s.MemberAdd(&m)
|
s.MemberAdd(m)
|
||||||
}
|
}
|
||||||
for _, c := range guild.Channels {
|
for _, c := range guild.Channels {
|
||||||
s.ChannelAdd(&c)
|
s.ChannelAdd(c)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
s.Guilds = append(s.Guilds, *guild)
|
s.Guilds = append(s.Guilds, guild)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,7 +87,7 @@ func (s *State) Guild(guildID string) (*Guild, error) {
|
||||||
|
|
||||||
for _, g := range s.Guilds {
|
for _, g := range s.Guilds {
|
||||||
if g.ID == guildID {
|
if g.ID == guildID {
|
||||||
return &g, nil
|
return g, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,12 +110,12 @@ func (s *State) MemberAdd(member *Member) error {
|
||||||
|
|
||||||
for i, m := range guild.Members {
|
for i, m := range guild.Members {
|
||||||
if m.User.ID == member.User.ID {
|
if m.User.ID == member.User.ID {
|
||||||
guild.Members[i] = *member
|
guild.Members[i] = member
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
guild.Members = append(guild.Members, *member)
|
guild.Members = append(guild.Members, member)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -153,7 +153,7 @@ func (s *State) Member(guildID, userID string) (*Member, error) {
|
||||||
|
|
||||||
for _, m := range guild.Members {
|
for _, m := range guild.Members {
|
||||||
if m.User.ID == userID {
|
if m.User.ID == userID {
|
||||||
return &m, nil
|
return m, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -172,12 +172,12 @@ func (s *State) ChannelAdd(channel *Channel) error {
|
||||||
if channel.IsPrivate {
|
if channel.IsPrivate {
|
||||||
for i, c := range s.PrivateChannels {
|
for i, c := range s.PrivateChannels {
|
||||||
if c.ID == channel.ID {
|
if c.ID == channel.ID {
|
||||||
s.PrivateChannels[i] = *channel
|
s.PrivateChannels[i] = channel
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
s.PrivateChannels = append(s.PrivateChannels, *channel)
|
s.PrivateChannels = append(s.PrivateChannels, channel)
|
||||||
} else {
|
} else {
|
||||||
guild, err := s.Guild(channel.GuildID)
|
guild, err := s.Guild(channel.GuildID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -186,12 +186,12 @@ func (s *State) ChannelAdd(channel *Channel) error {
|
||||||
|
|
||||||
for i, c := range guild.Channels {
|
for i, c := range guild.Channels {
|
||||||
if c.ID == channel.ID {
|
if c.ID == channel.ID {
|
||||||
guild.Channels[i] = *channel
|
guild.Channels[i] = channel
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
guild.Channels = append(guild.Channels, *channel)
|
guild.Channels = append(guild.Channels, channel)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -240,7 +240,7 @@ func (s *State) GuildChannel(guildID, channelID string) (*Channel, error) {
|
||||||
|
|
||||||
for _, c := range guild.Channels {
|
for _, c := range guild.Channels {
|
||||||
if c.ID == channelID {
|
if c.ID == channelID {
|
||||||
return &c, nil
|
return c, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -255,7 +255,7 @@ func (s *State) PrivateChannel(channelID string) (*Channel, error) {
|
||||||
|
|
||||||
for _, c := range s.PrivateChannels {
|
for _, c := range s.PrivateChannels {
|
||||||
if c.ID == channelID {
|
if c.ID == channelID {
|
||||||
return &c, nil
|
return c, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -296,7 +296,7 @@ func (s *State) Emoji(guildID, emojiID string) (*Emoji, error) {
|
||||||
|
|
||||||
for _, e := range guild.Emojis {
|
for _, e := range guild.Emojis {
|
||||||
if e.ID == emojiID {
|
if e.ID == emojiID {
|
||||||
return &e, nil
|
return e, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -316,19 +316,19 @@ func (s *State) EmojiAdd(guildID string, emoji *Emoji) error {
|
||||||
|
|
||||||
for i, e := range guild.Emojis {
|
for i, e := range guild.Emojis {
|
||||||
if e.ID == emoji.ID {
|
if e.ID == emoji.ID {
|
||||||
guild.Emojis[i] = *emoji
|
guild.Emojis[i] = emoji
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
guild.Emojis = append(guild.Emojis, *emoji)
|
guild.Emojis = append(guild.Emojis, emoji)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// EmojisAdd adds multiple emojis to the world state.
|
// EmojisAdd adds multiple emojis to the world state.
|
||||||
func (s *State) EmojisAdd(guildID string, emojis []Emoji) error {
|
func (s *State) EmojisAdd(guildID string, emojis []*Emoji) error {
|
||||||
for _, e := range emojis {
|
for _, e := range emojis {
|
||||||
if err := s.EmojiAdd(guildID, &e); err != nil {
|
if err := s.EmojiAdd(guildID, e); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
102
structs.go
102
structs.go
|
@ -29,33 +29,33 @@ type Session struct {
|
||||||
Debug bool // Debug for printing JSON request/responses
|
Debug bool // Debug for printing JSON request/responses
|
||||||
|
|
||||||
// Settable Callback functions for Websocket Events
|
// Settable Callback functions for Websocket Events
|
||||||
OnEvent func(*Session, Event) // should Event be *Event?
|
OnEvent func(*Session, *Event)
|
||||||
OnReady func(*Session, Ready)
|
OnReady func(*Session, *Ready)
|
||||||
OnTypingStart func(*Session, TypingStart)
|
OnTypingStart func(*Session, *TypingStart)
|
||||||
OnMessageCreate func(*Session, Message)
|
OnMessageCreate func(*Session, *Message)
|
||||||
OnMessageUpdate func(*Session, Message)
|
OnMessageUpdate func(*Session, *Message)
|
||||||
OnMessageDelete func(*Session, MessageDelete)
|
OnMessageDelete func(*Session, *MessageDelete)
|
||||||
OnMessageAck func(*Session, MessageAck)
|
OnMessageAck func(*Session, *MessageAck)
|
||||||
OnUserUpdate func(*Session, User)
|
OnUserUpdate func(*Session, *User)
|
||||||
OnPresenceUpdate func(*Session, PresenceUpdate)
|
OnPresenceUpdate func(*Session, *PresenceUpdate)
|
||||||
OnVoiceStateUpdate func(*Session, VoiceState)
|
OnVoiceStateUpdate func(*Session, *VoiceState)
|
||||||
OnChannelCreate func(*Session, Channel)
|
OnChannelCreate func(*Session, *Channel)
|
||||||
OnChannelUpdate func(*Session, Channel)
|
OnChannelUpdate func(*Session, *Channel)
|
||||||
OnChannelDelete func(*Session, Channel)
|
OnChannelDelete func(*Session, *Channel)
|
||||||
OnGuildCreate func(*Session, Guild)
|
OnGuildCreate func(*Session, *Guild)
|
||||||
OnGuildUpdate func(*Session, Guild)
|
OnGuildUpdate func(*Session, *Guild)
|
||||||
OnGuildDelete func(*Session, Guild)
|
OnGuildDelete func(*Session, *Guild)
|
||||||
OnGuildMemberAdd func(*Session, Member)
|
OnGuildMemberAdd func(*Session, *Member)
|
||||||
OnGuildMemberRemove func(*Session, Member)
|
OnGuildMemberRemove func(*Session, *Member)
|
||||||
OnGuildMemberDelete func(*Session, Member) // which is it?
|
OnGuildMemberDelete func(*Session, *Member) // which is it?
|
||||||
OnGuildMemberUpdate func(*Session, Member)
|
OnGuildMemberUpdate func(*Session, *Member)
|
||||||
OnGuildRoleCreate func(*Session, GuildRole)
|
OnGuildRoleCreate func(*Session, *GuildRole)
|
||||||
OnGuildRoleUpdate func(*Session, GuildRole)
|
OnGuildRoleUpdate func(*Session, *GuildRole)
|
||||||
OnGuildRoleDelete func(*Session, GuildRoleDelete)
|
OnGuildRoleDelete func(*Session, *GuildRoleDelete)
|
||||||
OnGuildIntegrationsUpdate func(*Session, GuildIntegrationsUpdate)
|
OnGuildIntegrationsUpdate func(*Session, *GuildIntegrationsUpdate)
|
||||||
OnGuildBanAdd func(*Session, GuildBan)
|
OnGuildBanAdd func(*Session, *GuildBan)
|
||||||
OnGuildBanRemove func(*Session, GuildBan)
|
OnGuildBanRemove func(*Session, *GuildBan)
|
||||||
OnGuildEmojisUpdate func(*Session, GuildEmojisUpdate)
|
OnGuildEmojisUpdate func(*Session, *GuildEmojisUpdate)
|
||||||
OnUserSettingsUpdate func(*Session, map[string]interface{}) // TODO: Find better way?
|
OnUserSettingsUpdate func(*Session, map[string]interface{}) // TODO: Find better way?
|
||||||
|
|
||||||
// Exposed but should not be modified by User.
|
// Exposed but should not be modified by User.
|
||||||
|
@ -110,7 +110,7 @@ type VoiceRegion struct {
|
||||||
// A VoiceICE stores data for voice ICE servers.
|
// A VoiceICE stores data for voice ICE servers.
|
||||||
type VoiceICE struct {
|
type VoiceICE struct {
|
||||||
TTL string `json:"ttl"`
|
TTL string `json:"ttl"`
|
||||||
Servers []ICEServer `json:"servers"`
|
Servers []*ICEServer `json:"servers"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// A ICEServer stores data for a specific voice ICE server.
|
// A ICEServer stores data for a specific voice ICE server.
|
||||||
|
@ -124,15 +124,15 @@ type ICEServer struct {
|
||||||
type Invite struct {
|
type Invite struct {
|
||||||
MaxAge int `json:"max_age"`
|
MaxAge int `json:"max_age"`
|
||||||
Code string `json:"code"`
|
Code string `json:"code"`
|
||||||
Guild Guild `json:"guild"`
|
Guild *Guild `json:"guild"`
|
||||||
Revoked bool `json:"revoked"`
|
Revoked bool `json:"revoked"`
|
||||||
CreatedAt string `json:"created_at"` // TODO make timestamp
|
CreatedAt string `json:"created_at"` // TODO make timestamp
|
||||||
Temporary bool `json:"temporary"`
|
Temporary bool `json:"temporary"`
|
||||||
Uses int `json:"uses"`
|
Uses int `json:"uses"`
|
||||||
MaxUses int `json:"max_uses"`
|
MaxUses int `json:"max_uses"`
|
||||||
Inviter User `json:"inviter"`
|
Inviter *User `json:"inviter"`
|
||||||
XkcdPass bool `json:"xkcdpass"`
|
XkcdPass bool `json:"xkcdpass"`
|
||||||
Channel Channel `json:"channel"`
|
Channel *Channel `json:"channel"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// A Channel holds all data related to an individual Discord channel.
|
// A Channel holds all data related to an individual Discord channel.
|
||||||
|
@ -143,10 +143,10 @@ type Channel struct {
|
||||||
Topic string `json:"topic"`
|
Topic string `json:"topic"`
|
||||||
Position int `json:"position"`
|
Position int `json:"position"`
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
PermissionOverwrites []PermissionOverwrite `json:"permission_overwrites"`
|
PermissionOverwrites []*PermissionOverwrite `json:"permission_overwrites"`
|
||||||
IsPrivate bool `json:"is_private"`
|
IsPrivate bool `json:"is_private"`
|
||||||
LastMessageID string `json:"last_message_id"`
|
LastMessageID string `json:"last_message_id"`
|
||||||
Recipient User `json:"recipient"`
|
Recipient *User `json:"recipient"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// A PermissionOverwrite holds permission overwrite data for a Channel
|
// A PermissionOverwrite holds permission overwrite data for a Channel
|
||||||
|
@ -179,12 +179,12 @@ type Guild struct {
|
||||||
OwnerID string `json:"owner_id"`
|
OwnerID string `json:"owner_id"`
|
||||||
Large bool `json:"large"` // ??
|
Large bool `json:"large"` // ??
|
||||||
JoinedAt string `json:"joined_at"` // make this a timestamp
|
JoinedAt string `json:"joined_at"` // make this a timestamp
|
||||||
Roles []Role `json:"roles"`
|
Roles []*Role `json:"roles"`
|
||||||
Emojis []Emoji `json:"emojis"`
|
Emojis []*Emoji `json:"emojis"`
|
||||||
Members []Member `json:"members"`
|
Members []*Member `json:"members"`
|
||||||
Presences []Presence `json:"presences"`
|
Presences []*Presence `json:"presences"`
|
||||||
Channels []Channel `json:"channels"`
|
Channels []*Channel `json:"channels"`
|
||||||
VoiceStates []VoiceState `json:"voice_states"`
|
VoiceStates []*VoiceState `json:"voice_states"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// A Role stores information about Discord guild member roles.
|
// A Role stores information about Discord guild member roles.
|
||||||
|
@ -212,9 +212,9 @@ type VoiceState struct {
|
||||||
|
|
||||||
// A Presence stores the online, offline, or idle and game status of Guild members.
|
// A Presence stores the online, offline, or idle and game status of Guild members.
|
||||||
type Presence struct {
|
type Presence struct {
|
||||||
User User `json:"user"`
|
User *User `json:"user"`
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
Game Game `json:"game"`
|
Game *Game `json:"game"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Game struct {
|
type Game struct {
|
||||||
|
@ -227,7 +227,7 @@ type Member struct {
|
||||||
JoinedAt string `json:"joined_at"`
|
JoinedAt string `json:"joined_at"`
|
||||||
Deaf bool `json:"deaf"`
|
Deaf bool `json:"deaf"`
|
||||||
Mute bool `json:"mute"`
|
Mute bool `json:"mute"`
|
||||||
User User `json:"user"`
|
User *User `json:"user"`
|
||||||
Roles []string `json:"roles"`
|
Roles []string `json:"roles"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -277,10 +277,10 @@ type Ready struct {
|
||||||
Version int `json:"v"`
|
Version int `json:"v"`
|
||||||
SessionID string `json:"session_id"`
|
SessionID string `json:"session_id"`
|
||||||
HeartbeatInterval time.Duration `json:"heartbeat_interval"`
|
HeartbeatInterval time.Duration `json:"heartbeat_interval"`
|
||||||
User User `json:"user"`
|
User *User `json:"user"`
|
||||||
ReadState []ReadState
|
ReadState []*ReadState
|
||||||
PrivateChannels []Channel `json:"private_channels"`
|
PrivateChannels []*Channel `json:"private_channels"`
|
||||||
Guilds []Guild `json:"guilds"`
|
Guilds []*Guild `json:"guilds"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// A ReadState stores data on the read state of channels.
|
// A ReadState stores data on the read state of channels.
|
||||||
|
@ -299,11 +299,11 @@ type TypingStart struct {
|
||||||
|
|
||||||
// A PresenceUpdate stores data for the pressence update websocket event.
|
// A PresenceUpdate stores data for the pressence update websocket event.
|
||||||
type PresenceUpdate struct {
|
type PresenceUpdate struct {
|
||||||
User User `json:"user"`
|
User *User `json:"user"`
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
Roles []string `json:"roles"`
|
Roles []string `json:"roles"`
|
||||||
GuildID string `json:"guild_id"`
|
GuildID string `json:"guild_id"`
|
||||||
Game Game `json:"game"`
|
Game *Game `json:"game"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// A MessageAck stores data for the message ack websocket event.
|
// A MessageAck stores data for the message ack websocket event.
|
||||||
|
@ -326,7 +326,7 @@ type GuildIntegrationsUpdate struct {
|
||||||
|
|
||||||
// A GuildRole stores data for guild role websocket events.
|
// A GuildRole stores data for guild role websocket events.
|
||||||
type GuildRole struct {
|
type GuildRole struct {
|
||||||
Role Role `json:"role"`
|
Role *Role `json:"role"`
|
||||||
GuildID string `json:"guild_id"`
|
GuildID string `json:"guild_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -338,14 +338,14 @@ type GuildRoleDelete struct {
|
||||||
|
|
||||||
// A GuildBan stores data for a guild ban.
|
// A GuildBan stores data for a guild ban.
|
||||||
type GuildBan struct {
|
type GuildBan struct {
|
||||||
User User `json:"user"`
|
User *User `json:"user"`
|
||||||
GuildID string `json:"guild_id"`
|
GuildID string `json:"guild_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// A GuildEmojisUpdate stores data for a guild emoji update event.
|
// A GuildEmojisUpdate stores data for a guild emoji update event.
|
||||||
type GuildEmojisUpdate struct {
|
type GuildEmojisUpdate struct {
|
||||||
GuildID string `json:"guild_id"`
|
GuildID string `json:"guild_id"`
|
||||||
Emojis []Emoji `json:"emojis"`
|
Emojis []*Emoji `json:"emojis"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// A State contains the current known state.
|
// A State contains the current known state.
|
||||||
|
|
80
wsapi.go
80
wsapi.go
|
@ -136,7 +136,7 @@ func (s *Session) Listen() (err error) {
|
||||||
// Not sure how needed this is and where it would be best to call it.
|
// Not sure how needed this is and where it would be best to call it.
|
||||||
// somewhere.
|
// somewhere.
|
||||||
|
|
||||||
func unmarshalEvent(event Event, i interface{}) (err error) {
|
func unmarshalEvent(event *Event, i interface{}) (err error) {
|
||||||
if err = json.Unmarshal(event.RawData, i); err != nil {
|
if err = json.Unmarshal(event.RawData, i); err != nil {
|
||||||
fmt.Println(event.Type, err)
|
fmt.Println(event.Type, err)
|
||||||
printJSON(event.RawData) // TODO: Better error loggingEvent.
|
printJSON(event.RawData) // TODO: Better error loggingEvent.
|
||||||
|
@ -155,7 +155,7 @@ func (s *Session) event(messageType int, message []byte) (err error) {
|
||||||
printJSON(message)
|
printJSON(message)
|
||||||
}
|
}
|
||||||
|
|
||||||
var e Event
|
var e *Event
|
||||||
if err = json.Unmarshal(message, &e); err != nil {
|
if err = json.Unmarshal(message, &e); err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
return
|
return
|
||||||
|
@ -164,10 +164,10 @@ func (s *Session) event(messageType int, message []byte) (err error) {
|
||||||
switch e.Type {
|
switch e.Type {
|
||||||
|
|
||||||
case "READY":
|
case "READY":
|
||||||
var st Ready
|
var st *Ready
|
||||||
if err = unmarshalEvent(e, &st); err == nil {
|
if err = unmarshalEvent(e, &st); err == nil {
|
||||||
if s.StateEnabled {
|
if s.StateEnabled {
|
||||||
s.State.OnReady(&st)
|
s.State.OnReady(st)
|
||||||
}
|
}
|
||||||
if s.OnReady != nil {
|
if s.OnReady != nil {
|
||||||
s.OnReady(s, st)
|
s.OnReady(s, st)
|
||||||
|
@ -177,21 +177,21 @@ func (s *Session) event(messageType int, message []byte) (err error) {
|
||||||
return
|
return
|
||||||
case "VOICE_SERVER_UPDATE":
|
case "VOICE_SERVER_UPDATE":
|
||||||
// TEMP CODE FOR TESTING VOICE
|
// TEMP CODE FOR TESTING VOICE
|
||||||
var st VoiceServerUpdate
|
var st *VoiceServerUpdate
|
||||||
if err = unmarshalEvent(e, &st); err == nil {
|
if err = unmarshalEvent(e, &st); err == nil {
|
||||||
s.onVoiceServerUpdate(st)
|
s.onVoiceServerUpdate(st)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
case "VOICE_STATE_UPDATE":
|
case "VOICE_STATE_UPDATE":
|
||||||
// TEMP CODE FOR TESTING VOICE
|
// TEMP CODE FOR TESTING VOICE
|
||||||
var st VoiceState
|
var st *VoiceState
|
||||||
if err = unmarshalEvent(e, &st); err == nil {
|
if err = unmarshalEvent(e, &st); err == nil {
|
||||||
s.onVoiceStateUpdate(st)
|
s.onVoiceStateUpdate(st)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
case "USER_UPDATE":
|
case "USER_UPDATE":
|
||||||
if s.OnUserUpdate != nil {
|
if s.OnUserUpdate != nil {
|
||||||
var st User
|
var st *User
|
||||||
if err = unmarshalEvent(e, &st); err == nil {
|
if err = unmarshalEvent(e, &st); err == nil {
|
||||||
s.OnUserUpdate(s, st)
|
s.OnUserUpdate(s, st)
|
||||||
}
|
}
|
||||||
|
@ -199,7 +199,7 @@ func (s *Session) event(messageType int, message []byte) (err error) {
|
||||||
}
|
}
|
||||||
case "PRESENCE_UPDATE":
|
case "PRESENCE_UPDATE":
|
||||||
if s.OnPresenceUpdate != nil {
|
if s.OnPresenceUpdate != nil {
|
||||||
var st PresenceUpdate
|
var st *PresenceUpdate
|
||||||
if err = unmarshalEvent(e, &st); err == nil {
|
if err = unmarshalEvent(e, &st); err == nil {
|
||||||
s.OnPresenceUpdate(s, st)
|
s.OnPresenceUpdate(s, st)
|
||||||
}
|
}
|
||||||
|
@ -207,7 +207,7 @@ func (s *Session) event(messageType int, message []byte) (err error) {
|
||||||
}
|
}
|
||||||
case "TYPING_START":
|
case "TYPING_START":
|
||||||
if s.OnTypingStart != nil {
|
if s.OnTypingStart != nil {
|
||||||
var st TypingStart
|
var st *TypingStart
|
||||||
if err = unmarshalEvent(e, &st); err == nil {
|
if err = unmarshalEvent(e, &st); err == nil {
|
||||||
s.OnTypingStart(s, st)
|
s.OnTypingStart(s, st)
|
||||||
}
|
}
|
||||||
|
@ -220,7 +220,7 @@ func (s *Session) event(messageType int, message []byte) (err error) {
|
||||||
*/
|
*/
|
||||||
case "MESSAGE_CREATE":
|
case "MESSAGE_CREATE":
|
||||||
if s.OnMessageCreate != nil {
|
if s.OnMessageCreate != nil {
|
||||||
var st Message
|
var st *Message
|
||||||
if err = unmarshalEvent(e, &st); err == nil {
|
if err = unmarshalEvent(e, &st); err == nil {
|
||||||
s.OnMessageCreate(s, st)
|
s.OnMessageCreate(s, st)
|
||||||
}
|
}
|
||||||
|
@ -228,7 +228,7 @@ func (s *Session) event(messageType int, message []byte) (err error) {
|
||||||
}
|
}
|
||||||
case "MESSAGE_UPDATE":
|
case "MESSAGE_UPDATE":
|
||||||
if s.OnMessageUpdate != nil {
|
if s.OnMessageUpdate != nil {
|
||||||
var st Message
|
var st *Message
|
||||||
if err = unmarshalEvent(e, &st); err == nil {
|
if err = unmarshalEvent(e, &st); err == nil {
|
||||||
s.OnMessageUpdate(s, st)
|
s.OnMessageUpdate(s, st)
|
||||||
}
|
}
|
||||||
|
@ -236,7 +236,7 @@ func (s *Session) event(messageType int, message []byte) (err error) {
|
||||||
}
|
}
|
||||||
case "MESSAGE_DELETE":
|
case "MESSAGE_DELETE":
|
||||||
if s.OnMessageDelete != nil {
|
if s.OnMessageDelete != nil {
|
||||||
var st MessageDelete
|
var st *MessageDelete
|
||||||
if err = unmarshalEvent(e, &st); err == nil {
|
if err = unmarshalEvent(e, &st); err == nil {
|
||||||
s.OnMessageDelete(s, st)
|
s.OnMessageDelete(s, st)
|
||||||
}
|
}
|
||||||
|
@ -244,7 +244,7 @@ func (s *Session) event(messageType int, message []byte) (err error) {
|
||||||
}
|
}
|
||||||
case "MESSAGE_ACK":
|
case "MESSAGE_ACK":
|
||||||
if s.OnMessageAck != nil {
|
if s.OnMessageAck != nil {
|
||||||
var st MessageAck
|
var st *MessageAck
|
||||||
if err = unmarshalEvent(e, &st); err == nil {
|
if err = unmarshalEvent(e, &st); err == nil {
|
||||||
s.OnMessageAck(s, st)
|
s.OnMessageAck(s, st)
|
||||||
}
|
}
|
||||||
|
@ -254,10 +254,10 @@ func (s *Session) event(messageType int, message []byte) (err error) {
|
||||||
if !s.StateEnabled && s.OnChannelCreate == nil {
|
if !s.StateEnabled && s.OnChannelCreate == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var st Channel
|
var st *Channel
|
||||||
if err = unmarshalEvent(e, &st); err == nil {
|
if err = unmarshalEvent(e, &st); err == nil {
|
||||||
if s.StateEnabled {
|
if s.StateEnabled {
|
||||||
s.State.ChannelAdd(&st)
|
s.State.ChannelAdd(st)
|
||||||
}
|
}
|
||||||
if s.OnChannelCreate != nil {
|
if s.OnChannelCreate != nil {
|
||||||
s.OnChannelCreate(s, st)
|
s.OnChannelCreate(s, st)
|
||||||
|
@ -268,10 +268,10 @@ func (s *Session) event(messageType int, message []byte) (err error) {
|
||||||
if !s.StateEnabled && s.OnChannelUpdate == nil {
|
if !s.StateEnabled && s.OnChannelUpdate == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var st Channel
|
var st *Channel
|
||||||
if err = unmarshalEvent(e, &st); err == nil {
|
if err = unmarshalEvent(e, &st); err == nil {
|
||||||
if s.StateEnabled {
|
if s.StateEnabled {
|
||||||
s.State.ChannelAdd(&st)
|
s.State.ChannelAdd(st)
|
||||||
}
|
}
|
||||||
if s.OnChannelUpdate != nil {
|
if s.OnChannelUpdate != nil {
|
||||||
s.OnChannelUpdate(s, st)
|
s.OnChannelUpdate(s, st)
|
||||||
|
@ -282,10 +282,10 @@ func (s *Session) event(messageType int, message []byte) (err error) {
|
||||||
if !s.StateEnabled && s.OnChannelDelete == nil {
|
if !s.StateEnabled && s.OnChannelDelete == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var st Channel
|
var st *Channel
|
||||||
if err = unmarshalEvent(e, &st); err == nil {
|
if err = unmarshalEvent(e, &st); err == nil {
|
||||||
if s.StateEnabled {
|
if s.StateEnabled {
|
||||||
s.State.ChannelRemove(&st)
|
s.State.ChannelRemove(st)
|
||||||
}
|
}
|
||||||
if s.OnChannelDelete != nil {
|
if s.OnChannelDelete != nil {
|
||||||
s.OnChannelDelete(s, st)
|
s.OnChannelDelete(s, st)
|
||||||
|
@ -296,10 +296,10 @@ func (s *Session) event(messageType int, message []byte) (err error) {
|
||||||
if !s.StateEnabled && s.OnGuildCreate == nil {
|
if !s.StateEnabled && s.OnGuildCreate == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var st Guild
|
var st *Guild
|
||||||
if err = unmarshalEvent(e, &st); err == nil {
|
if err = unmarshalEvent(e, &st); err == nil {
|
||||||
if s.StateEnabled {
|
if s.StateEnabled {
|
||||||
s.State.GuildAdd(&st)
|
s.State.GuildAdd(st)
|
||||||
}
|
}
|
||||||
if s.OnGuildCreate != nil {
|
if s.OnGuildCreate != nil {
|
||||||
s.OnGuildCreate(s, st)
|
s.OnGuildCreate(s, st)
|
||||||
|
@ -310,10 +310,10 @@ func (s *Session) event(messageType int, message []byte) (err error) {
|
||||||
if !s.StateEnabled && s.OnGuildUpdate == nil {
|
if !s.StateEnabled && s.OnGuildUpdate == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var st Guild
|
var st *Guild
|
||||||
if err = unmarshalEvent(e, &st); err == nil {
|
if err = unmarshalEvent(e, &st); err == nil {
|
||||||
if s.StateEnabled {
|
if s.StateEnabled {
|
||||||
s.State.GuildAdd(&st)
|
s.State.GuildAdd(st)
|
||||||
}
|
}
|
||||||
if s.OnGuildCreate != nil {
|
if s.OnGuildCreate != nil {
|
||||||
s.OnGuildUpdate(s, st)
|
s.OnGuildUpdate(s, st)
|
||||||
|
@ -324,10 +324,10 @@ func (s *Session) event(messageType int, message []byte) (err error) {
|
||||||
if !s.StateEnabled && s.OnGuildDelete == nil {
|
if !s.StateEnabled && s.OnGuildDelete == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var st Guild
|
var st *Guild
|
||||||
if err = unmarshalEvent(e, &st); err == nil {
|
if err = unmarshalEvent(e, &st); err == nil {
|
||||||
if s.StateEnabled {
|
if s.StateEnabled {
|
||||||
s.State.GuildRemove(&st)
|
s.State.GuildRemove(st)
|
||||||
}
|
}
|
||||||
if s.OnGuildDelete != nil {
|
if s.OnGuildDelete != nil {
|
||||||
s.OnGuildDelete(s, st)
|
s.OnGuildDelete(s, st)
|
||||||
|
@ -338,10 +338,10 @@ func (s *Session) event(messageType int, message []byte) (err error) {
|
||||||
if !s.StateEnabled && s.OnGuildMemberAdd == nil {
|
if !s.StateEnabled && s.OnGuildMemberAdd == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var st Member
|
var st *Member
|
||||||
if err = unmarshalEvent(e, &st); err == nil {
|
if err = unmarshalEvent(e, &st); err == nil {
|
||||||
if s.StateEnabled {
|
if s.StateEnabled {
|
||||||
s.State.MemberAdd(&st)
|
s.State.MemberAdd(st)
|
||||||
}
|
}
|
||||||
if s.OnGuildMemberAdd != nil {
|
if s.OnGuildMemberAdd != nil {
|
||||||
s.OnGuildMemberAdd(s, st)
|
s.OnGuildMemberAdd(s, st)
|
||||||
|
@ -349,13 +349,13 @@ func (s *Session) event(messageType int, message []byte) (err error) {
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
case "GUILD_MEMBER_REMOVE":
|
case "GUILD_MEMBER_REMOVE":
|
||||||
var st Member
|
|
||||||
if !s.StateEnabled && s.OnGuildMemberRemove == nil {
|
if !s.StateEnabled && s.OnGuildMemberRemove == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
var st *Member
|
||||||
if err = unmarshalEvent(e, &st); err == nil {
|
if err = unmarshalEvent(e, &st); err == nil {
|
||||||
if s.StateEnabled {
|
if s.StateEnabled {
|
||||||
s.State.MemberRemove(&st)
|
s.State.MemberRemove(st)
|
||||||
}
|
}
|
||||||
if s.OnGuildMemberRemove != nil {
|
if s.OnGuildMemberRemove != nil {
|
||||||
s.OnGuildMemberRemove(s, st)
|
s.OnGuildMemberRemove(s, st)
|
||||||
|
@ -366,10 +366,10 @@ func (s *Session) event(messageType int, message []byte) (err error) {
|
||||||
if !s.StateEnabled && s.OnGuildMemberUpdate == nil {
|
if !s.StateEnabled && s.OnGuildMemberUpdate == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var st Member
|
var st *Member
|
||||||
if err = unmarshalEvent(e, &st); err == nil {
|
if err = unmarshalEvent(e, &st); err == nil {
|
||||||
if s.StateEnabled {
|
if s.StateEnabled {
|
||||||
s.State.MemberAdd(&st)
|
s.State.MemberAdd(st)
|
||||||
}
|
}
|
||||||
if s.OnGuildMemberUpdate != nil {
|
if s.OnGuildMemberUpdate != nil {
|
||||||
s.OnGuildMemberUpdate(s, st)
|
s.OnGuildMemberUpdate(s, st)
|
||||||
|
@ -378,7 +378,7 @@ func (s *Session) event(messageType int, message []byte) (err error) {
|
||||||
return
|
return
|
||||||
case "GUILD_ROLE_CREATE":
|
case "GUILD_ROLE_CREATE":
|
||||||
if s.OnGuildRoleCreate != nil {
|
if s.OnGuildRoleCreate != nil {
|
||||||
var st GuildRole
|
var st *GuildRole
|
||||||
if err = unmarshalEvent(e, &st); err == nil {
|
if err = unmarshalEvent(e, &st); err == nil {
|
||||||
s.OnGuildRoleCreate(s, st)
|
s.OnGuildRoleCreate(s, st)
|
||||||
}
|
}
|
||||||
|
@ -386,7 +386,7 @@ func (s *Session) event(messageType int, message []byte) (err error) {
|
||||||
}
|
}
|
||||||
case "GUILD_ROLE_UPDATE":
|
case "GUILD_ROLE_UPDATE":
|
||||||
if s.OnGuildRoleUpdate != nil {
|
if s.OnGuildRoleUpdate != nil {
|
||||||
var st GuildRole
|
var st *GuildRole
|
||||||
if err = unmarshalEvent(e, &st); err == nil {
|
if err = unmarshalEvent(e, &st); err == nil {
|
||||||
s.OnGuildRoleUpdate(s, st)
|
s.OnGuildRoleUpdate(s, st)
|
||||||
}
|
}
|
||||||
|
@ -394,7 +394,7 @@ func (s *Session) event(messageType int, message []byte) (err error) {
|
||||||
}
|
}
|
||||||
case "GUILD_ROLE_DELETE":
|
case "GUILD_ROLE_DELETE":
|
||||||
if s.OnGuildRoleDelete != nil {
|
if s.OnGuildRoleDelete != nil {
|
||||||
var st GuildRoleDelete
|
var st *GuildRoleDelete
|
||||||
if err = unmarshalEvent(e, &st); err == nil {
|
if err = unmarshalEvent(e, &st); err == nil {
|
||||||
s.OnGuildRoleDelete(s, st)
|
s.OnGuildRoleDelete(s, st)
|
||||||
}
|
}
|
||||||
|
@ -402,7 +402,7 @@ func (s *Session) event(messageType int, message []byte) (err error) {
|
||||||
}
|
}
|
||||||
case "GUILD_INTEGRATIONS_UPDATE":
|
case "GUILD_INTEGRATIONS_UPDATE":
|
||||||
if s.OnGuildIntegrationsUpdate != nil {
|
if s.OnGuildIntegrationsUpdate != nil {
|
||||||
var st GuildIntegrationsUpdate
|
var st *GuildIntegrationsUpdate
|
||||||
if err = unmarshalEvent(e, &st); err == nil {
|
if err = unmarshalEvent(e, &st); err == nil {
|
||||||
s.OnGuildIntegrationsUpdate(s, st)
|
s.OnGuildIntegrationsUpdate(s, st)
|
||||||
}
|
}
|
||||||
|
@ -410,7 +410,7 @@ func (s *Session) event(messageType int, message []byte) (err error) {
|
||||||
}
|
}
|
||||||
case "GUILD_BAN_ADD":
|
case "GUILD_BAN_ADD":
|
||||||
if s.OnGuildBanAdd != nil {
|
if s.OnGuildBanAdd != nil {
|
||||||
var st GuildBan
|
var st *GuildBan
|
||||||
if err = unmarshalEvent(e, &st); err == nil {
|
if err = unmarshalEvent(e, &st); err == nil {
|
||||||
s.OnGuildBanAdd(s, st)
|
s.OnGuildBanAdd(s, st)
|
||||||
}
|
}
|
||||||
|
@ -418,7 +418,7 @@ func (s *Session) event(messageType int, message []byte) (err error) {
|
||||||
}
|
}
|
||||||
case "GUILD_BAN_REMOVE":
|
case "GUILD_BAN_REMOVE":
|
||||||
if s.OnGuildBanRemove != nil {
|
if s.OnGuildBanRemove != nil {
|
||||||
var st GuildBan
|
var st *GuildBan
|
||||||
if err = unmarshalEvent(e, &st); err == nil {
|
if err = unmarshalEvent(e, &st); err == nil {
|
||||||
s.OnGuildBanRemove(s, st)
|
s.OnGuildBanRemove(s, st)
|
||||||
}
|
}
|
||||||
|
@ -428,7 +428,7 @@ func (s *Session) event(messageType int, message []byte) (err error) {
|
||||||
if !s.StateEnabled && s.OnGuildEmojisUpdate == nil {
|
if !s.StateEnabled && s.OnGuildEmojisUpdate == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var st GuildEmojisUpdate
|
var st *GuildEmojisUpdate
|
||||||
if err = unmarshalEvent(e, &st); err == nil {
|
if err = unmarshalEvent(e, &st); err == nil {
|
||||||
if s.StateEnabled {
|
if s.StateEnabled {
|
||||||
s.State.EmojisAdd(st.GuildID, st.Emojis)
|
s.State.EmojisAdd(st.GuildID, st.Emojis)
|
||||||
|
@ -555,7 +555,7 @@ func (s *Session) VoiceChannelJoin(guildID, channelID string) (err error) {
|
||||||
// websocket. This comes immediately after the call to VoiceChannelJoin
|
// websocket. This comes immediately after the call to VoiceChannelJoin
|
||||||
// for the authenticated session user. This block is experimental
|
// for the authenticated session user. This block is experimental
|
||||||
// code and will be chaned in the future.
|
// code and will be chaned in the future.
|
||||||
func (s *Session) onVoiceStateUpdate(st VoiceState) {
|
func (s *Session) onVoiceStateUpdate(st *VoiceState) {
|
||||||
|
|
||||||
// Need to have this happen at login and store it in the Session
|
// Need to have this happen at login and store it in the Session
|
||||||
self, err := s.User("@me") // TODO: move to Login/New
|
self, err := s.User("@me") // TODO: move to Login/New
|
||||||
|
@ -576,7 +576,7 @@ func (s *Session) onVoiceStateUpdate(st VoiceState) {
|
||||||
|
|
||||||
// onVoiceServerUpdate handles the Voice Server Update data websocket event.
|
// onVoiceServerUpdate handles the Voice Server Update data websocket event.
|
||||||
// This will later be exposed but is only for experimental use now.
|
// This will later be exposed but is only for experimental use now.
|
||||||
func (s *Session) onVoiceServerUpdate(st VoiceServerUpdate) {
|
func (s *Session) onVoiceServerUpdate(st *VoiceServerUpdate) {
|
||||||
|
|
||||||
// Store all the values. They are used later.
|
// Store all the values. They are used later.
|
||||||
// GuildID is probably not needed and may be dropped.
|
// GuildID is probably not needed and may be dropped.
|
||||||
|
|
Loading…
Reference in a new issue