From 936f1ce2b880b12d372044348fdd1739a346a7f6 Mon Sep 17 00:00:00 2001 From: James Eagle Date: Mon, 1 Mar 2021 12:46:27 +0000 Subject: [PATCH 01/25] Add missing field --- interactions.go | 1 + 1 file changed, 1 insertion(+) diff --git a/interactions.go b/interactions.go index d4ccbe817..d3d66cf4f 100644 --- a/interactions.go +++ b/interactions.go @@ -74,6 +74,7 @@ type Interaction struct { GuildID string `json:"guild_id"` ChannelID string `json:"channel_id"` Member *Member `json:"member"` + User *User `json:"user"` Token string `json:"token"` Version int `json:"version"` } From 7a06ed149d55a4bf19722a3dbb14d765975380a0 Mon Sep 17 00:00:00 2001 From: James Eagle Date: Mon, 1 Mar 2021 12:47:59 +0000 Subject: [PATCH 02/25] Helpers --- interactions.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/interactions.go b/interactions.go index d3d66cf4f..a81697e3c 100644 --- a/interactions.go +++ b/interactions.go @@ -79,6 +79,19 @@ type Interaction struct { Version int `json:"version"` } +// IsInGuild is a utility function for checking if the interaction is sent in a guild or in a direct message +func (i Interaction) IsInGuild() bool { + return i.Member != nil +} + +// GetUser is a utility function for getting the User struct +func (i Interaction) GetUser() *User { + if i.Member != nil { + return i.Member.User + } + return i.User +} + // ApplicationCommandInteractionData contains data received in an interaction event. type ApplicationCommandInteractionData struct { ID string `json:"id"` From 31b48f8d2865da5f88d66bcec44c907a9b2aed2f Mon Sep 17 00:00:00 2001 From: James Eagle Date: Tue, 2 Mar 2021 12:39:56 +0000 Subject: [PATCH 03/25] Renames --- interactions.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/interactions.go b/interactions.go index a81697e3c..475c430af 100644 --- a/interactions.go +++ b/interactions.go @@ -79,12 +79,12 @@ type Interaction struct { Version int `json:"version"` } -// IsInGuild is a utility function for checking if the interaction is sent in a guild or in a direct message -func (i Interaction) IsInGuild() bool { +// InGuild is a utility function for checking if the interaction is sent in a guild or in a direct message +func (i Interaction) InGuild() bool { return i.Member != nil } -// GetUser is a utility function for getting the User struct +// GetUser is a utility function for retrieving the User struct func (i Interaction) GetUser() *User { if i.Member != nil { return i.Member.User From c0febb7f5e8c1771fb5caeb54036225ff86c50e8 Mon Sep 17 00:00:00 2001 From: James Eagle Date: Tue, 2 Mar 2021 12:40:28 +0000 Subject: [PATCH 04/25] Use helper --- interactions.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interactions.go b/interactions.go index 475c430af..ae0571bef 100644 --- a/interactions.go +++ b/interactions.go @@ -86,7 +86,7 @@ func (i Interaction) InGuild() bool { // GetUser is a utility function for retrieving the User struct func (i Interaction) GetUser() *User { - if i.Member != nil { + if i.InGuild() { return i.Member.User } return i.User From 2502fce9986489accddf338e66d09a009211b7b7 Mon Sep 17 00:00:00 2001 From: James Eagle Date: Tue, 2 Mar 2021 12:45:18 +0000 Subject: [PATCH 05/25] Add withCounts query option to Guild() --- restapi.go | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/restapi.go b/restapi.go index 654579fcb..9ab20b37d 100644 --- a/restapi.go +++ b/restapi.go @@ -577,9 +577,20 @@ func memberPermissions(guild *Guild, channel *Channel, userID string, roles []st // ------------------------------------------------------------------------------------------------ // Guild returns a Guild structure of a specific Guild. -// guildID : The ID of a Guild -func (s *Session) Guild(guildID string) (st *Guild, err error) { - body, err := s.RequestWithBucketID("GET", EndpointGuild(guildID), nil, EndpointGuild(guildID)) +// guildID : The ID of a Guild +// withCounts : When true, will return approximate member and presence counts for the guild +// uses variadic for backwards compatibility +func (s *Session) Guild(guildID string, withCounts ...bool) (st *Guild, err error) { + + uri := EndpointGuild(guildID) + + if len(withCounts) > 0 && withCounts[0] { + queryParams := url.Values{} + queryParams.Set("with_counts", "true") + uri += "?" + queryParams.Encode() + } + + body, err := s.RequestWithBucketID("GET", uri, nil, EndpointGuild(guildID)) if err != nil { return } @@ -631,7 +642,7 @@ func (s *Session) GuildEdit(guildID string, g GuildParams) (st *Guild, err error } } - //Bounds checking for regions + // Bounds checking for regions if g.Region != "" { isValid := false regions, _ := s.VoiceRegions() From 89ea67286c91b62d16d123dd5a99f4625b2e4193 Mon Sep 17 00:00:00 2001 From: James Eagle Date: Tue, 2 Mar 2021 19:49:13 +0000 Subject: [PATCH 06/25] Move IconURL --- structs.go | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/structs.go b/structs.go index e10441e59..b4e9b516f 100644 --- a/structs.go +++ b/structs.go @@ -572,6 +572,19 @@ type Guild struct { Permissions int64 `json:"permissions,string"` } +// IconURL returns a URL to the guild's icon. +func (g Guild) IconURL() string { + if g.Icon == "" { + return "" + } + + if strings.HasPrefix(g.Icon, "a_") { + return EndpointGuildIconAnimated(g.ID, g.Icon) + } + + return EndpointGuildIcon(g.ID, g.Icon) +} + // A GuildPreview holds data related to a specific public Discord Guild, even if the user is not in the guild. type GuildPreview struct { // The ID of the guild. @@ -626,19 +639,6 @@ const ( SystemChannelFlagsSuppressPremium ) -// IconURL returns a URL to the guild's icon. -func (g *Guild) IconURL() string { - if g.Icon == "" { - return "" - } - - if strings.HasPrefix(g.Icon, "a_") { - return EndpointGuildIconAnimated(g.ID, g.Icon) - } - - return EndpointGuildIcon(g.ID, g.Icon) -} - // A UserGuild holds a brief version of a Guild type UserGuild struct { ID string `json:"id"` From 1a291a2dde15c9af36c99e6335609e95eba9965d Mon Sep 17 00:00:00 2001 From: James Eagle Date: Tue, 2 Mar 2021 19:51:41 +0000 Subject: [PATCH 07/25] Add IconURL to GuildPreview --- structs.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/structs.go b/structs.go index b4e9b516f..d2f541382 100644 --- a/structs.go +++ b/structs.go @@ -619,6 +619,19 @@ type GuildPreview struct { Description string `json:"description"` } +// IconURL returns a URL to the guild's icon. +func (g GuildPreview) IconURL() string { + if g.Icon == "" { + return "" + } + + if strings.HasPrefix(g.Icon, "a_") { + return EndpointGuildIconAnimated(g.ID, g.Icon) + } + + return EndpointGuildIcon(g.ID, g.Icon) +} + // MessageNotifications is the notification level for a guild // https://discord.com/developers/docs/resources/guild#guild-object-default-message-notification-level type MessageNotifications int From 148cba73416452782483cf8ab4cb4425f74f8928 Mon Sep 17 00:00:00 2001 From: James Eagle Date: Tue, 2 Mar 2021 19:52:14 +0000 Subject: [PATCH 08/25] Update comments --- structs.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/structs.go b/structs.go index d2f541382..5bf0503eb 100644 --- a/structs.go +++ b/structs.go @@ -609,10 +609,10 @@ type GuildPreview struct { // The list of enabled guild features Features []string `json:"features"` - // Approximate number of members in this guild, returned from the GET /guild/ endpoint when with_counts is true + // Approximate number of members in this guild ApproximateMemberCount int `json:"approximate_member_count"` - // Approximate number of non-offline members in this guild, returned from the GET /guild/ endpoint when with_counts is true + // Approximate number of non-offline members in this guild ApproximatePresenceCount int `json:"approximate_presence_count"` // the description for the guild From af5e12d21fcaa1618299eea133f6408e7ef1cd38 Mon Sep 17 00:00:00 2001 From: Carson Hoffman Date: Sat, 6 Mar 2021 12:06:38 -0500 Subject: [PATCH 09/25] Send `[]` rather than `null` on empty activities slice --- wsapi.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/wsapi.go b/wsapi.go index 29a4f6134..4bbc25423 100644 --- a/wsapi.go +++ b/wsapi.go @@ -383,6 +383,17 @@ func (s *Session) UpdateListeningStatus(name string) (err error) { // UpdateStatusComplex allows for sending the raw status update data untouched by discordgo. func (s *Session) UpdateStatusComplex(usd UpdateStatusData) (err error) { + // The comment does say "untouched by discordgo", but we might need to lie a bit here. + // The Discord documentation lists `activites` as being nullable, but in practice this + // doesn't seem to be the case. I had filed an issue about this at + // https://github.com/discord/discord-api-docs/issues/2559, but as of writing this + // haven't had any movement on it, so at this point I'm assuming this is an error, + // and am fixing this bug accordingly. Because sending `null` for `activities` instantly + // disconnects us, I think that disallowing it from being sent in `UpdateStatusComplex` + // isn't that big of an issue. + if usd.Activities == nil { + usd.Activities = make([]*Activity, 0) + } s.RLock() defer s.RUnlock() From ff7fed0977b2b0231a1f36c761883bd9195a5a0b Mon Sep 17 00:00:00 2001 From: Carson Hoffman Date: Sun, 14 Mar 2021 12:27:22 -0400 Subject: [PATCH 10/25] Add more robust file support for webhooks --- restapi.go | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++- webhook.go | 2 +- 2 files changed, 55 insertions(+), 2 deletions(-) diff --git a/restapi.go b/restapi.go index 9ab20b37d..1cc51f6ef 100644 --- a/restapi.go +++ b/restapi.go @@ -2185,7 +2185,60 @@ func (s *Session) WebhookExecute(webhookID, token string, wait bool, data *Webho uri += "?wait=true" } - response, err := s.RequestWithBucketID("POST", uri, data, EndpointWebhookToken("", "")) + var response []byte + if len(data.Files) > 0 { + body := &bytes.Buffer{} + bodywriter := multipart.NewWriter(body) + + var payload []byte + payload, err = json.Marshal(data) + if err != nil { + return + } + + var p io.Writer + + h := make(textproto.MIMEHeader) + h.Set("Content-Disposition", `form-data; name="payload_json"`) + h.Set("Content-Type", "application/json") + + p, err = bodywriter.CreatePart(h) + if err != nil { + return + } + + if _, err = p.Write(payload); err != nil { + return + } + + for i, file := range data.Files { + h := make(textproto.MIMEHeader) + h.Set("Content-Disposition", fmt.Sprintf(`form-data; name="file%d"; filename="%s"`, i, quoteEscaper.Replace(file.Name))) + contentType := file.ContentType + if contentType == "" { + contentType = "application/octet-stream" + } + h.Set("Content-Type", contentType) + + p, err = bodywriter.CreatePart(h) + if err != nil { + return + } + + if _, err = io.Copy(p, file.Reader); err != nil { + return + } + } + + err = bodywriter.Close() + if err != nil { + return + } + + response, err = s.request("POST", uri, bodywriter.FormDataContentType(), body.Bytes(), uri, 0) + } else { + response, err = s.RequestWithBucketID("POST", uri, data, uri) + } if !wait || err != nil { return } diff --git a/webhook.go b/webhook.go index b8b3abcde..1fc4c4f24 100644 --- a/webhook.go +++ b/webhook.go @@ -31,7 +31,7 @@ type WebhookParams struct { Username string `json:"username,omitempty"` AvatarURL string `json:"avatar_url,omitempty"` TTS bool `json:"tts,omitempty"` - File string `json:"file,omitempty"` + Files []*File `json:"-"` Embeds []*MessageEmbed `json:"embeds,omitempty"` AllowedMentions *MessageAllowedMentions `json:"allowed_mentions,omitempty"` } From b66089ec5e34b3a58e6a10b863f27d14449010f1 Mon Sep 17 00:00:00 2001 From: James Eagle Date: Tue, 2 Mar 2021 12:45:18 +0000 Subject: [PATCH 11/25] Add withCounts query option to Guild() --- restapi.go | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/restapi.go b/restapi.go index 887076fcb..5a19c6a60 100644 --- a/restapi.go +++ b/restapi.go @@ -461,9 +461,20 @@ func memberPermissions(guild *Guild, channel *Channel, userID string, roles []st // ------------------------------------------------------------------------------------------------ // Guild returns a Guild structure of a specific Guild. -// guildID : The ID of a Guild -func (s *Session) Guild(guildID string) (st *Guild, err error) { - body, err := s.RequestWithBucketID("GET", EndpointGuild(guildID), nil, EndpointGuild(guildID)) +// guildID : The ID of a Guild +// withCounts : When true, will return approximate member and presence counts for the guild +// uses variadic for backwards compatibility +func (s *Session) Guild(guildID string, withCounts ...bool) (st *Guild, err error) { + + uri := EndpointGuild(guildID) + + if len(withCounts) > 0 && withCounts[0] { + queryParams := url.Values{} + queryParams.Set("with_counts", "true") + uri += "?" + queryParams.Encode() + } + + body, err := s.RequestWithBucketID("GET", uri, nil, EndpointGuild(guildID)) if err != nil { return } @@ -515,7 +526,7 @@ func (s *Session) GuildEdit(guildID string, g GuildParams) (st *Guild, err error } } - //Bounds checking for regions + // Bounds checking for regions if g.Region != "" { isValid := false regions, _ := s.VoiceRegions() From 81587ccb4bfb39f32d5602af11d07c9b81e11cbf Mon Sep 17 00:00:00 2001 From: James Eagle Date: Tue, 2 Mar 2021 19:52:14 +0000 Subject: [PATCH 12/25] Update comments --- structs.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/structs.go b/structs.go index 88f9d6ec9..49263c453 100644 --- a/structs.go +++ b/structs.go @@ -757,10 +757,10 @@ type GuildPreview struct { // The list of enabled guild features Features []string `json:"features"` - // Approximate number of members in this guild, returned from the GET /guild/ endpoint when with_counts is true + // Approximate number of members in this guild ApproximateMemberCount int `json:"approximate_member_count"` - // Approximate number of non-offline members in this guild, returned from the GET /guild/ endpoint when with_counts is true + // Approximate number of non-offline members in this guild ApproximatePresenceCount int `json:"approximate_presence_count"` // the description for the guild From 892ad22b2522810f72c9e8f8423f821f424132d6 Mon Sep 17 00:00:00 2001 From: James Eagle Date: Tue, 29 Mar 2022 19:33:12 +0100 Subject: [PATCH 13/25] Split guild func --- restapi.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/restapi.go b/restapi.go index 5a19c6a60..28d55073d 100644 --- a/restapi.go +++ b/restapi.go @@ -462,9 +462,22 @@ func memberPermissions(guild *Guild, channel *Channel, userID string, roles []st // Guild returns a Guild structure of a specific Guild. // guildID : The ID of a Guild +func (s *Session) Guild(guildID string) (st *Guild, err error) { + + body, err := s.RequestWithBucketID("GET", EndpointGuild(guildID), nil, EndpointGuild(guildID)) + if err != nil { + return + } + + err = unmarshal(body, &st) + return +} + +// GuildWithCounts returns a Guild structure of a specific Guild. +// guildID : The ID of a Guild // withCounts : When true, will return approximate member and presence counts for the guild // uses variadic for backwards compatibility -func (s *Session) Guild(guildID string, withCounts ...bool) (st *Guild, err error) { +func (s *Session) GuildWithCounts(guildID string, withCounts ...bool) (st *Guild, err error) { uri := EndpointGuild(guildID) From 87a7eeb2f06747b3ff6be30814a23e4b082f3890 Mon Sep 17 00:00:00 2001 From: Jim Eagle Date: Tue, 29 Mar 2022 19:34:08 +0100 Subject: [PATCH 14/25] Update structs.go Co-authored-by: Fedor Lapshin --- structs.go | 1 + 1 file changed, 1 insertion(+) diff --git a/structs.go b/structs.go index 49263c453..d89774010 100644 --- a/structs.go +++ b/structs.go @@ -758,6 +758,7 @@ type GuildPreview struct { Features []string `json:"features"` // Approximate number of members in this guild + // NOTE: this field is only filled when using GuildWithCounts ApproximateMemberCount int `json:"approximate_member_count"` // Approximate number of non-offline members in this guild From c5614ec231e180bf6b3ea5f6b367fbb23ac38277 Mon Sep 17 00:00:00 2001 From: Jim Eagle Date: Tue, 29 Mar 2022 19:34:39 +0100 Subject: [PATCH 15/25] Update structs.go Co-authored-by: Fedor Lapshin --- structs.go | 1 + 1 file changed, 1 insertion(+) diff --git a/structs.go b/structs.go index d89774010..91814bb87 100644 --- a/structs.go +++ b/structs.go @@ -762,6 +762,7 @@ type GuildPreview struct { ApproximateMemberCount int `json:"approximate_member_count"` // Approximate number of non-offline members in this guild + // NOTE: this field is only filled when using GuildWithCounts ApproximatePresenceCount int `json:"approximate_presence_count"` // the description for the guild From 62884d2bf12e28328d5930de535e6a732447c30e Mon Sep 17 00:00:00 2001 From: James Eagle Date: Tue, 29 Mar 2022 19:56:35 +0100 Subject: [PATCH 16/25] Revert --- restapi.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/restapi.go b/restapi.go index 28d55073d..47f8086b0 100644 --- a/restapi.go +++ b/restapi.go @@ -461,9 +461,8 @@ func memberPermissions(guild *Guild, channel *Channel, userID string, roles []st // ------------------------------------------------------------------------------------------------ // 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) { - body, err := s.RequestWithBucketID("GET", EndpointGuild(guildID), nil, EndpointGuild(guildID)) if err != nil { return From 13c5393a4eaff8ef64702c90c7822d5af2bc639c Mon Sep 17 00:00:00 2001 From: James Eagle Date: Tue, 29 Mar 2022 19:58:48 +0100 Subject: [PATCH 17/25] Format yaml --- .github/release.yml | 2 +- .github/workflows/ci.yml | 2 +- .travis.yml | 24 ++++++++++++------------ mkdocs.yml | 12 ++++++------ 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/.github/release.yml b/.github/release.yml index 28153a303..95d044ab7 100644 --- a/.github/release.yml +++ b/.github/release.yml @@ -3,7 +3,7 @@ changelog: - title: "Breaking changes" labels: - breaking changes - + - title: "New features" labels: - feature diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 63e14622f..4afa9414f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -50,7 +50,7 @@ jobs: only-new-issues: true skip-pkg-cache: true skip-build-cache: true - + - name: GolangCI-Lint if: github.event.name != 'pull_request' # See https://github.com/golangci/golangci-lint-action/issues/362 run: | diff --git a/.travis.yml b/.travis.yml index 5d9cea3ee..ecd99c798 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,17 +1,17 @@ language: go go: - - 1.13.x - - 1.14.x - - 1.15.x - - 1.16.x + - 1.13.x + - 1.14.x + - 1.15.x + - 1.16.x env: - - GO111MODULE=on + - GO111MODULE=on install: - - go get github.com/bwmarrin/discordgo - - go get -v . - - go get -v golang.org/x/lint/golint + - go get github.com/bwmarrin/discordgo + - go get -v . + - go get -v golang.org/x/lint/golint script: - - diff <(gofmt -d .) <(echo -n) - - go vet -x ./... - - golint -set_exit_status ./... - - go test -v -race ./... + - diff <(gofmt -d .) <(echo -n) + - go vet -x ./... + - golint -set_exit_status ./... + - go test -v -race ./... diff --git a/mkdocs.yml b/mkdocs.yml index 3ee8eb378..b1dbc9078 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -7,11 +7,11 @@ dev_addr: 0.0.0.0:8000 theme: yeti markdown_extensions: - - smarty - - toc: - permalink: True - - sane_lists + - smarty + - toc: + permalink: True + - sane_lists pages: - - 'Home': 'index.md' - - 'Getting Started': 'GettingStarted.md' + - 'Home': 'index.md' + - 'Getting Started': 'GettingStarted.md' From 5e31dd8a607d9ac8a15d27f944522cbc628d62eb Mon Sep 17 00:00:00 2001 From: Jleagle Date: Wed, 30 Mar 2022 12:41:15 +0100 Subject: [PATCH 18/25] Add IconURL to GuildPreview --- structs.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/structs.go b/structs.go index 91814bb87..b20a49008 100644 --- a/structs.go +++ b/structs.go @@ -769,6 +769,19 @@ type GuildPreview struct { Description string `json:"description"` } +// IconURL returns a URL to the guild's icon. +func (g *GuildPreview) IconURL() string { + if g.Icon == "" { + return "" + } + + if strings.HasPrefix(g.Icon, "a_") { + return EndpointGuildIconAnimated(g.ID, g.Icon) + } + + return EndpointGuildIcon(g.ID, g.Icon) +} + // GuildScheduledEvent is a representation of a scheduled event in a guild. Only for retrieval of the data. // https://discord.com/developers/docs/resources/guild-scheduled-event#guild-scheduled-event type GuildScheduledEvent struct { From 470a785b4a16a86859845f27a8c5f77a0106f770 Mon Sep 17 00:00:00 2001 From: Jleagle Date: Wed, 30 Mar 2022 12:45:09 +0100 Subject: [PATCH 19/25] Revert --- restapi.go | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/restapi.go b/restapi.go index 2287d2360..ad6524bd2 100644 --- a/restapi.go +++ b/restapi.go @@ -462,19 +462,8 @@ func memberPermissions(guild *Guild, channel *Channel, userID string, roles []st // Guild returns a Guild structure of a specific Guild. // guildID : The ID of a Guild -// withCounts : When true, will return approximate member and presence counts for the guild -// uses variadic for backwards compatibility -func (s *Session) Guild(guildID string, withCounts ...bool) (st *Guild, err error) { - - uri := EndpointGuild(guildID) - - if len(withCounts) > 0 && withCounts[0] { - queryParams := url.Values{} - queryParams.Set("with_counts", "true") - uri += "?" + queryParams.Encode() - } - - body, err := s.RequestWithBucketID("GET", uri, nil, EndpointGuild(guildID)) +func (s *Session) Guild(guildID string) (st *Guild, err error) { + body, err := s.RequestWithBucketID("GET", EndpointGuild(guildID), nil, EndpointGuild(guildID)) if err != nil { return } From 936651cb106af7d04f8158271deb26e3455ad74b Mon Sep 17 00:00:00 2001 From: Jleagle Date: Wed, 30 Mar 2022 12:45:48 +0100 Subject: [PATCH 20/25] Revert space --- restapi.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/restapi.go b/restapi.go index ad6524bd2..47f8086b0 100644 --- a/restapi.go +++ b/restapi.go @@ -461,7 +461,7 @@ func memberPermissions(guild *Guild, channel *Channel, userID string, roles []st // ------------------------------------------------------------------------------------------------ // 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) { body, err := s.RequestWithBucketID("GET", EndpointGuild(guildID), nil, EndpointGuild(guildID)) if err != nil { From 3cf94749137082bb60f08391019f4d4b918b720c Mon Sep 17 00:00:00 2001 From: Jim Eagle Date: Wed, 30 Mar 2022 22:31:34 +0100 Subject: [PATCH 21/25] Update restapi.go Co-authored-by: Fedor Lapshin --- restapi.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/restapi.go b/restapi.go index 47f8086b0..44cb5c5d8 100644 --- a/restapi.go +++ b/restapi.go @@ -472,7 +472,7 @@ func (s *Session) Guild(guildID string) (st *Guild, err error) { return } -// GuildWithCounts returns a Guild structure of a specific Guild. +// GuildWithCounts returns a Guild structure of a specific Guild with approximate member and presence counts. // guildID : The ID of a Guild // withCounts : When true, will return approximate member and presence counts for the guild // uses variadic for backwards compatibility From 5ec53cc2eca850d7e278d5311a4b716ddd7fb76e Mon Sep 17 00:00:00 2001 From: Jleagle Date: Thu, 31 Mar 2022 13:02:50 +0100 Subject: [PATCH 22/25] Remove variadic --- restapi.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/restapi.go b/restapi.go index 44cb5c5d8..e640ab9ae 100644 --- a/restapi.go +++ b/restapi.go @@ -476,11 +476,11 @@ func (s *Session) Guild(guildID string) (st *Guild, err error) { // guildID : The ID of a Guild // withCounts : When true, will return approximate member and presence counts for the guild // uses variadic for backwards compatibility -func (s *Session) GuildWithCounts(guildID string, withCounts ...bool) (st *Guild, err error) { +func (s *Session) GuildWithCounts(guildID string, withCounts bool) (st *Guild, err error) { uri := EndpointGuild(guildID) - if len(withCounts) > 0 && withCounts[0] { + if withCounts { queryParams := url.Values{} queryParams.Set("with_counts", "true") uri += "?" + queryParams.Encode() From f6637e2b981819ea3ef2bdfb02c982b598a3432d Mon Sep 17 00:00:00 2001 From: Jleagle Date: Thu, 31 Mar 2022 13:41:06 +0100 Subject: [PATCH 23/25] Revert yamls --- .github/release.yml | 2 +- .github/workflows/ci.yml | 2 +- .travis.yml | 24 ++++++++++++------------ mkdocs.yml | 12 ++++++------ 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/.github/release.yml b/.github/release.yml index 95d044ab7..28153a303 100644 --- a/.github/release.yml +++ b/.github/release.yml @@ -3,7 +3,7 @@ changelog: - title: "Breaking changes" labels: - breaking changes - + - title: "New features" labels: - feature diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4afa9414f..63e14622f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -50,7 +50,7 @@ jobs: only-new-issues: true skip-pkg-cache: true skip-build-cache: true - + - name: GolangCI-Lint if: github.event.name != 'pull_request' # See https://github.com/golangci/golangci-lint-action/issues/362 run: | diff --git a/.travis.yml b/.travis.yml index ecd99c798..5d9cea3ee 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,17 +1,17 @@ language: go go: - - 1.13.x - - 1.14.x - - 1.15.x - - 1.16.x + - 1.13.x + - 1.14.x + - 1.15.x + - 1.16.x env: - - GO111MODULE=on + - GO111MODULE=on install: - - go get github.com/bwmarrin/discordgo - - go get -v . - - go get -v golang.org/x/lint/golint + - go get github.com/bwmarrin/discordgo + - go get -v . + - go get -v golang.org/x/lint/golint script: - - diff <(gofmt -d .) <(echo -n) - - go vet -x ./... - - golint -set_exit_status ./... - - go test -v -race ./... + - diff <(gofmt -d .) <(echo -n) + - go vet -x ./... + - golint -set_exit_status ./... + - go test -v -race ./... diff --git a/mkdocs.yml b/mkdocs.yml index b1dbc9078..3ee8eb378 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -7,11 +7,11 @@ dev_addr: 0.0.0.0:8000 theme: yeti markdown_extensions: - - smarty - - toc: - permalink: True - - sane_lists + - smarty + - toc: + permalink: True + - sane_lists pages: - - 'Home': 'index.md' - - 'Getting Started': 'GettingStarted.md' + - 'Home': 'index.md' + - 'Getting Started': 'GettingStarted.md' From 63d22bf177a088a45a59c2e553ad21174fe21723 Mon Sep 17 00:00:00 2001 From: Jleagle Date: Thu, 31 Mar 2022 19:54:32 +0100 Subject: [PATCH 24/25] Remove param --- restapi.go | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/restapi.go b/restapi.go index e640ab9ae..85ecd4c83 100644 --- a/restapi.go +++ b/restapi.go @@ -474,19 +474,12 @@ func (s *Session) Guild(guildID string) (st *Guild, err error) { // GuildWithCounts returns a Guild structure of a specific Guild with approximate member and presence counts. // guildID : The ID of a Guild -// withCounts : When true, will return approximate member and presence counts for the guild -// uses variadic for backwards compatibility -func (s *Session) GuildWithCounts(guildID string, withCounts bool) (st *Guild, err error) { +func (s *Session) GuildWithCounts(guildID string) (st *Guild, err error) { - uri := EndpointGuild(guildID) - - if withCounts { - queryParams := url.Values{} - queryParams.Set("with_counts", "true") - uri += "?" + queryParams.Encode() - } + queryParams := url.Values{} + queryParams.Set("with_counts", "true") - body, err := s.RequestWithBucketID("GET", uri, nil, EndpointGuild(guildID)) + body, err := s.RequestWithBucketID("GET", EndpointGuild(guildID)+"?"+queryParams.Encode(), nil, EndpointGuild(guildID)) if err != nil { return } From f43ea4d672dba7b0610b409ec0a1211a75233cc0 Mon Sep 17 00:00:00 2001 From: Jleagle Date: Thu, 31 Mar 2022 20:12:13 +0100 Subject: [PATCH 25/25] Hardcode string --- restapi.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/restapi.go b/restapi.go index 85ecd4c83..d8ff93137 100644 --- a/restapi.go +++ b/restapi.go @@ -476,10 +476,7 @@ func (s *Session) Guild(guildID string) (st *Guild, err error) { // guildID : The ID of a Guild func (s *Session) GuildWithCounts(guildID string) (st *Guild, err error) { - queryParams := url.Values{} - queryParams.Set("with_counts", "true") - - body, err := s.RequestWithBucketID("GET", EndpointGuild(guildID)+"?"+queryParams.Encode(), nil, EndpointGuild(guildID)) + body, err := s.RequestWithBucketID("GET", EndpointGuild(guildID)+"?with_counts=true", nil, EndpointGuild(guildID)) if err != nil { return }