Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REST methods cleanup #1217

Merged
merged 15 commits into from Aug 17, 2022
Merged

REST methods cleanup #1217

merged 15 commits into from Aug 17, 2022

Conversation

FedorLap2006
Copy link
Collaborator

@FedorLap2006 FedorLap2006 commented Aug 4, 2022

We have been thinking on how to improve developer experience with the library and clean up some stuff.

One of the aspects that came to our attention is REST methods. Currently we don't have a consistent naming and signature style.

This PR addresses this problem.
It refactors REST methods to use structs where possible and removes some of the unnecessary helper methods.

This only affects older functions , functions that came after v0.24.0 already are following this design.

Here's how the usage will change:

// Change role name.
- s.GuildRoleEdit(guildID, roleID, "new name", 0xFFFFFF, true, 0x0, true)
+ s.GuildRoleEdit(guildID, roleID, &discordgo.RoleData {
+    Name: "new name",
+ })

// Change member's roles and nickname.
- s.GuildMemberEdit(guildID, memberID, roles)
- s.GuildMemberNickname(guildID, memberID, "new nickname")
+ s.GuildMemberEdit(guildID, memberID, &discordgo.GuildMemberParams { ... })

// Add member to the server with the given nickname and roles.
- s.GuildMemberAdd(token, guildID, userID, "member", []string{...}, false, false)
+ s.GuildMemberAdd(token, guildID, userID, &discordgo.GuildMemberParams {
+     Name: "member",
+     Roles: &[]string{...},
+ })

Breaking changes

  • ChannelEdit — will share same functional as ChannelEditComplex
  • GuildMemberEdit — will share same functional as GuildMemberEditComplex
  • GuildEmojiEditname and roles will be placed in a struct, to allow for partial edits
  • GuildEmojiCreate — same as for GuildEmojiEdit
  • GuildMemberAddaccessToken, nick, roles, mute and deaf will be placed in a struct
  • GuildRoleEditname, color, hoist, perms, mention will be placed in a struct to allow for partial edits
  • GuildTemplateCreatename and description will be placed in a struct to allow for partial edits
  • GuildTemplateEdit — same as for GuildTemplateCreate
  • GuildEmbedEditenabled and channel_id will be places in a struct to allow for partial edits

Deprecated functions

  • ChannelEditComplex (renamed to ChannelEdit)
  • GuildMemberEditComplex (renamed to GuildMemberEdit)

🚧 The changes are still work in progress, therefore the list of functions might change.

Refactor GuildRoleEdit to accept parameters using a Params struct.
Therefore also allow partial edits.
Make GuildRoleCreate accept a struct with initial parameters for a role
Move funcitonality of ChannelEditComplex to ChannelEdit
* Make fields omitempty
* Make `Enabled` field a pointer
Refactor GuildEmbedEdit to accept parameters through GuildEmbed struct
Move functionality fo GuildMemberEditComplex to GuildMemberEdit
Refactor GuildEmojiCreate to take parameters using EmojiParams struct.
Refactor GuildEmojiEdit to take parameters using EmojiParams struct.
@FedorLap2006 FedorLap2006 added feature Feature implementation feedback Additional feedback is required high priority Issue or PR with high priority of merge breaking changes Contains breaking changes. Should be reflected in the changelog labels Aug 4, 2022
@FedorLap2006 FedorLap2006 added this to the v0.26.0 milestone Aug 4, 2022
@FedorLap2006 FedorLap2006 self-assigned this Aug 4, 2022
Refactor GuildMemberAdd to take parameters using GuildMemberAddParams struct.
Refactor GuildTemplateEdit to take parameters using GuildTemplateParams struct.
Refactor GuildTemplateCreate to take parameters using GuildTemplateParams struct.
@FedorLap2006 FedorLap2006 marked this pull request as ready for review August 12, 2022 22:34
@FedorLap2006 FedorLap2006 removed the feedback Additional feedback is required label Aug 13, 2022
Refactor methods with Params struct to use pointers
restapi.go Outdated Show resolved Hide resolved
restapi.go Outdated Show resolved Hide resolved
restapi.go Outdated Show resolved Hide resolved
restapi.go Outdated Show resolved Hide resolved
restapi.go Outdated Show resolved Hide resolved
@FedorLap2006 FedorLap2006 merged commit 576ecf0 into master Aug 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking changes Contains breaking changes. Should be reflected in the changelog feature Feature implementation high priority Issue or PR with high priority of merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant