From bd8db0e38c333893f265270ceffdee124e296b77 Mon Sep 17 00:00:00 2001 From: H01001000 Date: Wed, 21 Dec 2022 16:28:30 +0800 Subject: [PATCH] fix: guild ban --- packages/rest/src/helpers/guilds/getBan.ts | 18 ++++++------------ packages/rest/src/helpers/guilds/getBans.ts | 20 ++++++++++++-------- 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/packages/rest/src/helpers/guilds/getBan.ts b/packages/rest/src/helpers/guilds/getBan.ts index 173531f8a..40b0fc51c 100644 --- a/packages/rest/src/helpers/guilds/getBan.ts +++ b/packages/rest/src/helpers/guilds/getBan.ts @@ -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 { +): Promise> { const result = await rest.runMethod( - '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) } } diff --git a/packages/rest/src/helpers/guilds/getBans.ts b/packages/rest/src/helpers/guilds/getBans.ts index b45a3f65c..6ecc0f4a1 100644 --- a/packages/rest/src/helpers/guilds/getBans.ts +++ b/packages/rest/src/helpers/guilds/getBans.ts @@ -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> { +): Promise>> { const results = await rest.runMethod( - '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]>((result) => { + const user = TRANSFORMERS.user(result.user) return [ user.id, { - reason: result.reason ?? undefined, + reason: result.reason, user } ]