mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-03 01:10:07 +00:00
fix: guild ban
This commit is contained in:
@@ -1,12 +1,7 @@
|
||||
import { routes } from '@discordeno/constant'
|
||||
import type { BigString, DiscordBan } from '@discordeno/types'
|
||||
import TRANSFORMERS from '@discordeno/transformer'
|
||||
import type { BigString, Camelize, DiscordBan } from '@discordeno/types'
|
||||
import type { RestManager } from '../../restManager.js'
|
||||
import type { User } from '../../transformers/member.js'
|
||||
|
||||
export interface Ban {
|
||||
reason?: string
|
||||
user: User
|
||||
}
|
||||
|
||||
// TODO: Move `Ban` into its own transformer file.
|
||||
|
||||
@@ -16,7 +11,7 @@ export interface Ban {
|
||||
* @param rest - The rest manager to use to make the request.
|
||||
* @param guildId - The ID of the guild to get the ban from.
|
||||
* @param userId - The ID of the user to get the ban for.
|
||||
* @returns An instance of {@link Ban}.
|
||||
* @returns An instance of {@link DiscordBan}.
|
||||
*
|
||||
* @remarks
|
||||
* Requires the `BAN_MEMBERS` permission.
|
||||
@@ -27,15 +22,14 @@ export async function getBan (
|
||||
rest: RestManager,
|
||||
guildId: BigString,
|
||||
userId: BigString
|
||||
): Promise<Ban> {
|
||||
): Promise<Camelize<DiscordBan>> {
|
||||
const result = await rest.runMethod<DiscordBan>(
|
||||
|
||||
'GET',
|
||||
routes.GUILD_BAN(guildId, userId)
|
||||
)
|
||||
|
||||
return {
|
||||
reason: result.reason ?? undefined,
|
||||
user: rest.transformers.user(rest, result.user)
|
||||
reason: result.reason,
|
||||
user: TRANSFORMERS.user(result.user)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,13 @@
|
||||
import { routes } from '@discordeno/constant'
|
||||
import type { BigString, DiscordBan, GetBans } from '@discordeno/types'
|
||||
import TRANSFORMERS from '@discordeno/transformer'
|
||||
import type {
|
||||
BigString,
|
||||
Camelize,
|
||||
DiscordBan,
|
||||
GetBans
|
||||
} from '@discordeno/types'
|
||||
import { Collection } from '@discordeno/utils'
|
||||
import type { RestManager } from '../../restManager.js'
|
||||
import type { Ban } from './getBan.js'
|
||||
|
||||
/**
|
||||
* Gets the list of bans for a guild.
|
||||
@@ -10,7 +15,7 @@ import type { Ban } from './getBan.js'
|
||||
* @param rest - The rest manager to use to make the request.
|
||||
* @param guildId - The ID of the guild to get the list of bans for.
|
||||
* @param options - The parameters for the fetching of the list of bans.
|
||||
* @returns A collection of {@link Ban} objects assorted by user ID.
|
||||
* @returns A collection of {@link DiscordBan} objects assorted by user ID.
|
||||
*
|
||||
* @remarks
|
||||
* Requires the `BAN_MEMBERS` permission.
|
||||
@@ -23,20 +28,19 @@ export async function getBans (
|
||||
rest: RestManager,
|
||||
guildId: BigString,
|
||||
options?: GetBans
|
||||
): Promise<Collection<bigint, Ban>> {
|
||||
): Promise<Collection<string, Camelize<DiscordBan>>> {
|
||||
const results = await rest.runMethod<DiscordBan[]>(
|
||||
|
||||
'GET',
|
||||
routes.GUILD_BANS(guildId, options)
|
||||
)
|
||||
|
||||
return new Collection(
|
||||
results.map<[bigint, Ban]>((result) => {
|
||||
const user = rest.transformers.user(rest, result.user)
|
||||
results.map<[string, Camelize<DiscordBan>]>((result) => {
|
||||
const user = TRANSFORMERS.user(result.user)
|
||||
return [
|
||||
user.id,
|
||||
{
|
||||
reason: result.reason ?? undefined,
|
||||
reason: result.reason,
|
||||
user
|
||||
}
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user