fix: objectToLower & objectToSnake types

This commit is contained in:
MARCROCK22 2024-04-25 17:06:53 -04:00
parent 6675757b61
commit c46e9515d6
4 changed files with 32 additions and 8 deletions

View File

@ -1,4 +1,4 @@
import { ApplicationCommandType, MessageFlags } from 'discord-api-types/v10'; import { type APIMessage, ApplicationCommandType, MessageFlags } from 'discord-api-types/v10';
import type { ContextMenuCommand, ReturnCache, WebhookMessage } from '../..'; import type { ContextMenuCommand, ReturnCache, WebhookMessage } from '../..';
import { import {
toSnakeCase, toSnakeCase,
@ -50,7 +50,7 @@ export class MenuCommandContext<
switch (this.interaction.data.type) { switch (this.interaction.data.type) {
case ApplicationCommandType.Message: { case ApplicationCommandType.Message: {
const data = this.interaction.data.resolved.messages[this.interaction.data.targetId as Lowercase<string>]; const data = this.interaction.data.resolved.messages[this.interaction.data.targetId as Lowercase<string>];
return new Message(this.client, toSnakeCase(data)) as never; return new Message(this.client, toSnakeCase(data) as APIMessage) as never;
} }
case ApplicationCommandType.User: { case ApplicationCommandType.User: {
const data = this.interaction.data.resolved.users[this.interaction.data.targetId as Lowercase<string>]; const data = this.interaction.data.resolved.users[this.interaction.data.targetId as Lowercase<string>];

View File

@ -10,7 +10,7 @@ import type {
RESTPostAPIGuildChannelJSONBody, RESTPostAPIGuildChannelJSONBody,
RESTPostAPIGuildsJSONBody, RESTPostAPIGuildsJSONBody,
} from 'discord-api-types/v10'; } from 'discord-api-types/v10';
import type { ObjectToLower } from '..'; import { toSnakeCase, type ObjectToLower } from '..';
import { resolveFiles } from '../../builders'; import { resolveFiles } from '../../builders';
import { import {
AnonymousGuild, AnonymousGuild,
@ -267,7 +267,7 @@ export class GuildShorter extends BaseShorter {
return this.client.proxy return this.client.proxy
.guilds(guildId) .guilds(guildId)
['auto-moderation'].rules(ruleId) ['auto-moderation'].rules(ruleId)
.patch({ body, reason }) .patch({ body: toSnakeCase(body), reason })
.then(rule => new AutoModerationRule(this.client, rule)); .then(rule => new AutoModerationRule(this.client, rule));
}, },
}; };

View File

@ -104,6 +104,18 @@ export type ObjectToLower<T> = Identify<{
? Identify<ObjectToLower<T[K][0]>[]> ? Identify<ObjectToLower<T[K][0]>[]>
: T[K] extends object : T[K] extends object
? Identify<ObjectToLower<T[K]>> ? Identify<ObjectToLower<T[K]>>
: AuxIsStrictlyUndefined<T[K]> extends true
? undefined
: ObjectToLowerUndefined<T[K]>;
}>;
export type ObjectToLowerUndefined<T> = T extends unknown[]
? ObjectToLower<T[0]>[]
: Identify<{
[K in keyof T as CamelCase<Exclude<K, symbol | number>>]?: T[K] extends unknown[]
? ObjectToLower<T[K][0]>[]
: T[K] extends object
? ObjectToLower<T[K]>
: T[K]; : T[K];
}>; }>;
@ -112,6 +124,18 @@ export type ObjectToSnake<T> = Identify<{
? Identify<ObjectToSnake<T[K][0]>[]> ? Identify<ObjectToSnake<T[K][0]>[]>
: T[K] extends object : T[K] extends object
? Identify<ObjectToSnake<T[K]>> ? Identify<ObjectToSnake<T[K]>>
: AuxIsStrictlyUndefined<T[K]> extends true
? undefined
: ObjectToSnakeUndefined<T[K]>;
}>;
export type ObjectToSnakeUndefined<T> = T extends unknown[]
? ObjectToSnake<T[0]>[]
: Identify<{
[K in keyof T as SnakeCase<Exclude<K, symbol | number>>]?: T[K] extends unknown[]
? ObjectToSnake<T[K][0]>[]
: T[K] extends object
? ObjectToSnake<T[K]>
: T[K]; : T[K];
}>; }>;

View File

@ -4,7 +4,7 @@ import type {
RESTPostAPIAutoModerationRuleJSONBody, RESTPostAPIAutoModerationRuleJSONBody,
} from 'discord-api-types/v10'; } from 'discord-api-types/v10';
import type { UsingClient } from '../commands'; import type { UsingClient } from '../commands';
import type { MethodContext, ObjectToLower } from '../common'; import { toCamelCase, type MethodContext, type ObjectToLower } from '../common';
import { DiscordBase } from './extra/DiscordBase'; import { DiscordBase } from './extra/DiscordBase';
export interface AutoModerationRule extends ObjectToLower<APIAutoModerationRule> {} export interface AutoModerationRule extends ObjectToLower<APIAutoModerationRule> {}
@ -41,7 +41,7 @@ export class AutoModerationRule extends DiscordBase<APIAutoModerationRule> {
delete: (ruleId: string, reason?: string) => client.guilds.moderation.delete(guildId, ruleId, reason), delete: (ruleId: string, reason?: string) => client.guilds.moderation.delete(guildId, ruleId, reason),
fetch: (ruleId: string) => client.guilds.moderation.fetch(guildId, ruleId), fetch: (ruleId: string) => client.guilds.moderation.fetch(guildId, ruleId),
edit: (ruleId: string, body: RESTPatchAPIAutoModerationRuleJSONBody, reason?: string) => edit: (ruleId: string, body: RESTPatchAPIAutoModerationRuleJSONBody, reason?: string) =>
client.guilds.moderation.edit(guildId, ruleId, body, reason), client.guilds.moderation.edit(guildId, ruleId, toCamelCase(body), reason),
}; };
} }
} }