discordgo icon indicating copy to clipboard operation
discordgo copied to clipboard

REST methods cleanup

Open FedorLap2006 opened this issue 1 year ago • 0 comments

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

  • [x] ChannelEdit — will share same functional as ChannelEditComplex
  • [x] GuildMemberEdit — will share same functional as GuildMemberEditComplex
  • [x] GuildEmojiEditname and roles will be placed in a struct, to allow for partial edits
  • [x] GuildEmojiCreate — same as for GuildEmojiEdit
  • [ ] GuildMemberAddnick, roles, mute and deaf will be placed in a struct
  • [x] GuildMemberEdit — will share same functional as GuildMemberEditComplex
  • [x] GuildRoleEditname, color, hoist, perms, mention will be placed in a struct to allow for partial edits
  • [ ] GuildTemplateEditname and description will be placed in a struct to allow for partial edits

Deprecated functions

  • [x] ChannelEditComplex (renamed to ChannelEdit)
  • [x] GuildMemberEditComplex (renamed to GuildMemberEdit)

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

FedorLap2006 avatar Aug 04 '22 20:08 FedorLap2006