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

Add bulk ban endpoint #342

Merged
merged 1 commit into from
Mar 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading