Stop trying to fight Discord's Int's as Strings and just use strings.

This commit is contained in:
Bruce Marriner 2015-11-14 21:02:35 -06:00
parent f87340f1e8
commit 05ff822438
5 changed files with 61 additions and 83 deletions

View file

@ -1,22 +1,22 @@
package discordgo package discordgo
type Channel struct { type Channel struct {
GuildId int `json:"guild_id,string,omitempty"` Id string `json:"id"`
Id int `json:"id,string"` GuildId string `json:"guild_idomitempty"`
Name string `json:"name"` Name string `json:"name"`
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 int `json:"last_message_id,string"` LastMessageId string `json:"last_message_id"`
Recipient User `json:"recipient"` Recipient User `json:"recipient"`
Session *Session Session *Session
} }
type PermissionOverwrite struct { type PermissionOverwrite struct {
Id string `json:"id"`
Type string `json:"type"` Type string `json:"type"`
Id int `json:"id,string"`
Deny int `json:"deny"` Deny int `json:"deny"`
Allow int `json:"allow"` Allow int `json:"allow"`
} }

View file

@ -1,15 +1,15 @@
package discordgo package discordgo
type Guild struct { type Guild struct {
Id int `json:"id,string"` Id string `json:"id"`
Name string `json:"name"` Name string `json:"name"`
Icon string `json:"icon"` Icon string `json:"icon"`
Region string `json:"region"` Region string `json:"region"`
AfkTimeout int `json:"afk_timeout"` AfkTimeout int `json:"afk_timeout"`
AfkChannelId int `json:"afk_channel_id,string"` AfkChannelId string `json:"afk_channel_id"`
EmbedChannelId int `json:"embed_channel_id,string"` EmbedChannelId string `json:"embed_channel_id"`
EmbedEnabled bool `json:"embed_enabled"` EmbedEnabled bool `json:"embed_enabled"`
OwnerId int `json:"owner_id,string"` 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"`
@ -20,7 +20,7 @@ type Guild struct {
} }
type Role struct { type Role struct {
Id int `json:"id,string"` Id string `json:"id"`
Name string `json:"name"` Name string `json:"name"`
Managed bool `json:"managed"` Managed bool `json:"managed"`
Color int `json:"color"` Color int `json:"color"`
@ -30,14 +30,14 @@ type Role struct {
} }
type VoiceState struct { type VoiceState struct {
UserId int `json:"user_id,string"` UserId string `json:"user_id"`
Suppress bool `json:"suppress"` Suppress bool `json:"suppress"`
SessionId string `json:"session_id"` SessionId string `json:"session_id"`
SelfMute bool `json:"self_mute"` SelfMute bool `json:"self_mute"`
SelfDeaf bool `json:"self_deaf"` SelfDeaf bool `json:"self_deaf"`
Mute bool `json:"mute"` Mute bool `json:"mute"`
Deaf bool `json:"deaf"` Deaf bool `json:"deaf"`
ChannelId int `json:"channel_id,string"` ChannelId string `json:"channel_id"`
} }
type Presence struct { type Presence struct {
@ -48,7 +48,7 @@ type Presence struct {
// TODO: Member vs User? // TODO: Member vs User?
type Member struct { type Member struct {
GuildId int `json:"guild_id,string"` GuildId string `json:"guild_id"`
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"`

View file

@ -15,7 +15,6 @@ import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
sv "strconv"
"time" "time"
) )
@ -39,8 +38,8 @@ const (
REGISTER = AUTH + "register" REGISTER = AUTH + "register"
VOICE = API + "/voice/" VOICE = API + "/voice/"
REGIONS = API + VOICE + "regions" REGIONS = VOICE + "regions"
ICE = API + VOICE + "ice" ICE = VOICE + "ice"
TUTORIAL = API + "tutorial/" TUTORIAL = API + "tutorial/"
TUTORIAL_INDICATORS = TUTORIAL + "indicators" TUTORIAL_INDICATORS = TUTORIAL + "indicators"
@ -62,24 +61,24 @@ var (
USER_DEVICES = func(userId string) string { return USERS + userId + "/devices" } USER_DEVICES = func(userId string) string { return USERS + userId + "/devices" }
USER_CONNECTIONS = func(userId string) string { return USERS + userId + "/connections" } USER_CONNECTIONS = func(userId string) string { return USERS + userId + "/connections" }
GUILD = func(guildId int) string { return GUILDS + sv.Itoa(guildId) } GUILD = func(guildId string) string { return GUILDS + guildId }
GUILD_CHANNELS = func(guildId int) string { return GUILDS + sv.Itoa(guildId) + "/channels" } GUILD_CHANNELS = func(guildId string) string { return GUILDS + guildId + "/channels" }
GUILD_MEMBERS = func(guildId int) string { return GUILDS + sv.Itoa(guildId) + "/members" } GUILD_MEMBERS = func(guildId string) string { return GUILDS + guildId + "/members" }
GUILD_INTEGRATIONS = func(guildId int) string { return GUILDS + sv.Itoa(guildId) + "/integrations" } GUILD_INTEGRATIONS = func(guildId string) string { return GUILDS + guildId + "/integrations" }
GUILD_BANS = func(guildId int) string { return GUILDS + sv.Itoa(guildId) + "/bans" } GUILD_BANS = func(guildId string) string { return GUILDS + guildId + "/bans" }
GUILD_ROLES = func(guildId int) string { return GUILDS + sv.Itoa(guildId) + "/roles" } GUILD_ROLES = func(guildId string) string { return GUILDS + guildId + "/roles" }
GUILD_INVITES = func(guildId int) string { return GUILDS + sv.Itoa(guildId) + "/invites" } GUILD_INVITES = func(guildId string) string { return GUILDS + guildId + "/invites" }
GUILD_EMBED = func(guildId int) string { return GUILDS + sv.Itoa(guildId) + "/embed" } GUILD_EMBED = func(guildId string) string { return GUILDS + guildId + "/embed" }
GUILD_PRUNE = func(guildId int) string { return GUILDS + sv.Itoa(guildId) + "/prune" } GUILD_PRUNE = func(guildId string) string { return GUILDS + guildId + "/prune" }
GUILD_ICON = func(guildId int, hash string) string { return GUILDS + sv.Itoa(guildId) + "/icons/" + hash + ".jpg" } GUILD_ICON = func(guildId, hash string) string { return GUILDS + guildId + "/icons/" + hash + ".jpg" }
CHANNEL = func(channelId int) string { return CHANNELS + sv.Itoa(channelId) } CHANNEL = func(channelId string) string { return CHANNELS + channelId }
CHANNEL_MESSAGES = func(channelId int) string { return CHANNELS + sv.Itoa(channelId) + "/messages" } CHANNEL_MESSAGES = func(channelId string) string { return CHANNELS + channelId + "/messages" }
CHANNEL_PERMISSIONS = func(channelId int) string { return CHANNELS + sv.Itoa(channelId) + "/permissions" } CHANNEL_PERMISSIONS = func(channelId string) string { return CHANNELS + channelId + "/permissions" }
CHANNEL_INVITES = func(channelId int) string { return CHANNELS + sv.Itoa(channelId) + "/invites" } CHANNEL_INVITES = func(channelId string) string { return CHANNELS + channelId + "/invites" }
CHANNEL_TYPING = func(channelId int) string { return CHANNELS + sv.Itoa(channelId) + "/typing" } CHANNEL_TYPING = func(channelId string) string { return CHANNELS + channelId + "/typing" }
INTEGRATIONS_JOIN = func(intId int) string { return API + "integrations/" + sv.Itoa(intId) + "/join" } INTEGRATIONS_JOIN = func(intId string) string { return API + "integrations/" + intId + "/join" }
) )
// Request makes a (GET/POST/?) Requests to Discord REST API. // Request makes a (GET/POST/?) Requests to Discord REST API.
@ -225,7 +224,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 the Guild you want returend. // guildId : The ID of the Guild you want returend.
func (s *Session) Guild(guildId int) (st []Guild, err error) { func (s *Session) Guild(guildId string) (st []Guild, err error) {
body, err := s.Request("GET", GUILD(guildId), ``) body, err := s.Request("GET", GUILD(guildId), ``)
err = json.Unmarshal(body, &st) err = json.Unmarshal(body, &st)
@ -235,7 +234,7 @@ func (s *Session) Guild(guildId int) (st []Guild, err error) {
// GuildMembers returns an array of Member structures for all members of a // GuildMembers returns an array of Member structures for all members of a
// given guild. // given guild.
// guildId : The ID of a Guild. // guildId : The ID of a Guild.
func (s *Session) GuildMembers(guildId int) (st []Member, err error) { func (s *Session) GuildMembers(guildId string) (st []Member, err error) {
body, err := s.Request("GET", GUILD_MEMBERS(guildId), ``) body, err := s.Request("GET", GUILD_MEMBERS(guildId), ``)
err = json.Unmarshal(body, &st) err = json.Unmarshal(body, &st)
@ -245,7 +244,7 @@ func (s *Session) GuildMembers(guildId int) (st []Member, 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 int) (st []Channel, err error) { func (s *Session) GuildChannels(guildId string) (st []Channel, err error) {
body, err := s.Request("GET", GUILD_CHANNELS(guildId), ``) body, err := s.Request("GET", GUILD_CHANNELS(guildId), ``)
err = json.Unmarshal(body, &st) err = json.Unmarshal(body, &st)
@ -259,7 +258,7 @@ func (s *Session) GuildChannels(guildId int) (st []Channel, 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 int) (st Channel, err error) { func (s *Session) Channel(channelId string) (st Channel, err error) {
body, err := s.Request("GET", CHANNEL(channelId), ``) body, err := s.Request("GET", CHANNEL(channelId), ``)
err = json.Unmarshal(body, &st) err = json.Unmarshal(body, &st)
return return
@ -271,7 +270,7 @@ func (s *Session) Channel(channelId int) (st Channel, err error) {
// limit : The number messages that can be returned. // limit : The number messages that can be returned.
// beforeId : If provided all messages returned will be before given ID. // beforeId : If provided all messages returned will be before given ID.
// afterId : If provided all messages returned will be after given ID. // afterId : If provided all messages returned will be after given ID.
func (s *Session) ChannelMessages(channelId int, limit int, beforeId int, afterId int) (st []Message, err error) { func (s *Session) ChannelMessages(channelId string, limit int, beforeId int, afterId int) (st []Message, err error) {
var urlStr string = "" var urlStr string = ""
@ -303,7 +302,7 @@ func (s *Session) ChannelMessages(channelId int, limit int, beforeId int, afterI
// ChannelMessageSend sends a message to the given channel. // ChannelMessageSend sends a message to the given channel.
// channelId : The ID of a Channel. // channelId : The ID of a Channel.
// content : The message to send. // content : The message to send.
func (s *Session) ChannelMessageSend(channelId int, content string) (st Message, err error) { func (s *Session) ChannelMessageSend(channelId string, content string) (st Message, err error) {
response, err := s.Request("POST", CHANNEL_MESSAGES(channelId), fmt.Sprintf(`{"content":"%s"}`, content)) response, err := s.Request("POST", CHANNEL_MESSAGES(channelId), fmt.Sprintf(`{"content":"%s"}`, content))
err = json.Unmarshal(response, &st) err = json.Unmarshal(response, &st)

View file

@ -1,7 +1,7 @@
package discordgo package discordgo
type User struct { type User struct {
Id int `json:"id,string"` Id string `json:"id"`
Email string `json:"email"` Email string `json:"email"`
Username string `json:"username"` Username string `json:"username"`
Avatar string `json:"Avatar"` Avatar string `json:"Avatar"`
@ -19,30 +19,21 @@ type User struct {
// field correctly. Need to research this more. // field correctly. Need to research this more.
type PrivateChannel struct { type PrivateChannel struct {
Id int `json:"id,string"` Id string `json:"id"`
IsPrivate bool `json:"is_private"` IsPrivate bool `json:"is_private"`
LastMessageId int `json:"last_message_id,string"` LastMessageId string `json:"last_message_id"`
Recipient User `json:"recipient"` Recipient User `json:"recipient"`
} // merge with channel? } // merge with channel?
type Settings struct { type Settings struct {
RenderEmbeds bool `json:"render_embeds"` RenderEmbeds bool `json:"render_embeds"`
InlineEmbedMedia bool `json:"inline_embed_media"` InlineEmbedMedia bool `json:"inline_embed_media"`
EnableTtsCommand bool `json:"enable_tts_command"` EnableTtsCommand bool `json:"enable_tts_command"`
MessageDisplayCompact bool `json:"message_display_compact"` MessageDisplayCompact bool `json:"message_display_compact"`
Locale string `json:"locale"` Locale string `json:"locale"`
ShowCurrentGame bool `json:"show_current_game"` ShowCurrentGame bool `json:"show_current_game"`
Theme string `json:"theme"` Theme string `json:"theme"`
//MutedChannels []string `json:"muted_channels"` // TODO, see below MutedChannels []string `json:"muted_channels"`
MutedChannels []int `json:"muted_channels,string"` // TODO, see below
// MutedChannels []MutedChannel `json:"muted_channels"`
} }
type MutedChannel struct {
mc int `json:",string"`
}
// MutedChannels should be an array of ints...
// need to find a way to make that happen
// PM function to PM a user. // PM function to PM a user.

View file

@ -44,48 +44,36 @@ type Ready struct {
// of all my channels when first connecting. I think :) // of all my channels when first connecting. I think :)
type ReadState struct { type ReadState struct {
MentionCount int MentionCount int
LastMessageID int `json:"last_message_id,string"` LastMessageId string `json:"last_message_id"`
ID int `json:"id,string"` Id string `json:"id"`
} }
type TypingStart struct { type TypingStart struct {
UserId int `json:"user_id,string"` UserId string `json:"user_id"`
ChannelId int `json:"channel_id,string"` ChannelId string `json:"channel_id"`
Timestamp int `json:"timestamp"` Timestamp int `json:"timestamp"`
} }
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"` // TODO: Should be ints, see below Roles []string `json:"roles"`
GuildId int `json:"guild_id,string"` GuildId string `json:"guild_id"`
GameId int `json:"game_id"` GameId int `json:"game_id"`
} }
//Roles []string `json:"roles"` // TODO: Should be ints, see below
// Above "Roles" should be an array of ints
// TODO: Figure out how to make it be one.
/*
{
"roles": [
"89544728336416768",
"110429733396676608"
],
}
*/
type MessageAck struct { type MessageAck struct {
MessageId int `json:"message_id,string"` MessageId string `json:"message_id"`
ChannelId int `json:"channel_id,string"` ChannelId string `json:"channel_id"`
} }
type MessageDelete struct { type MessageDelete struct {
Id int `json:"id,string"` Id string `json:"id"`
ChannelId int `json:"channel_id,string"` ChannelId string `json:"channel_id"`
} // so much like MessageAck.. } // so much like MessageAck..
type GuildIntegrationsUpdate struct { type GuildIntegrationsUpdate struct {
GuildId int `json:"guild_id,string"` GuildId string `json:"guild_id"`
} }
type GuildRoleUpdate struct { type GuildRoleUpdate struct {