Skip to content

Commit

Permalink
Add bulk ban endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
mlnrDev committed Mar 18, 2024
1 parent 1cd20b5 commit 0db840e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
14 changes: 14 additions & 0 deletions discord/ban.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package discord

import "github.com/disgoorg/snowflake/v2"

// Ban represents a banned User from a Guild (https://discord.com/developers/docs/resources/guild#ban-object)
type Ban struct {
Reason *string `json:"reason,omitempty"`
Expand All @@ -10,3 +12,15 @@ type Ban struct {
type AddBan struct {
DeleteMessageSeconds int `json:"delete_message_seconds,omitempty"`
}

// BulkBan is used to bulk ban Users
type BulkBan struct {
UserIDs []snowflake.ID `json:"user_ids"`
DeleteMessageSeconds int `json:"delete_message_seconds,omitempty"`
}

// BulkBanResult is the result of a BulkBan request
type BulkBanResult struct {
BannedUsers []snowflake.ID `json:"banned_users"`
FailedUsers []snowflake.ID `json:"failed_users"`
}
6 changes: 6 additions & 0 deletions rest/guilds.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type Guilds interface {
GetBan(guildID snowflake.ID, userID snowflake.ID, opts ...RequestOpt) (*discord.Ban, error)
AddBan(guildID snowflake.ID, userID snowflake.ID, deleteMessageDuration time.Duration, opts ...RequestOpt) error
DeleteBan(guildID snowflake.ID, userID snowflake.ID, opts ...RequestOpt) error
BulkBan(guildID snowflake.ID, ban discord.BulkBan, opts ...RequestOpt) (*discord.BulkBanResult, error)

GetIntegrations(guildID snowflake.ID, opts ...RequestOpt) ([]discord.Integration, error)
DeleteIntegration(guildID snowflake.ID, integrationID snowflake.ID, opts ...RequestOpt) error
Expand Down Expand Up @@ -210,6 +211,11 @@ func (s *guildImpl) DeleteBan(guildID snowflake.ID, userID snowflake.ID, opts ..
return s.client.Do(DeleteBan.Compile(nil, guildID, userID), nil, nil, opts...)
}

func (s *guildImpl) BulkBan(guildID snowflake.ID, ban discord.BulkBan, opts ...RequestOpt) (result *discord.BulkBanResult, err error) {
err = s.client.Do(BulkBan.Compile(nil, guildID), ban, &result, opts...)
return
}

func (s *guildImpl) GetIntegrations(guildID snowflake.ID, opts ...RequestOpt) (integrations []discord.Integration, err error) {
err = s.client.Do(GetIntegrations.Compile(nil, guildID), nil, &integrations, opts...)
return
Expand Down
1 change: 1 addition & 0 deletions rest/rest_endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ var (
GetBan = NewEndpoint(http.MethodGet, "/guilds/{guild.id}/bans/{user.id}")
AddBan = NewEndpoint(http.MethodPut, "/guilds/{guild.id}/bans/{user.id}")
DeleteBan = NewEndpoint(http.MethodDelete, "/guilds/{guild.id}/bans/{user.id}")
BulkBan = NewEndpoint(http.MethodPost, "/guilds/{guild.id}/bulk-ban")

GetMember = NewEndpoint(http.MethodGet, "/guilds/{guild.id}/members/{user.id}")
GetMembers = NewEndpoint(http.MethodGet, "/guilds/{guild.id}/members")
Expand Down

0 comments on commit 0db840e

Please sign in to comment.