mirror of
https://github.com/tiramisulabs/seyfert.git
synced 2025-07-02 04:56:07 +00:00
fix: objectToLower & objectToSnake types
This commit is contained in:
parent
6675757b61
commit
c46e9515d6
@ -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 {
|
||||
toSnakeCase,
|
||||
@ -50,7 +50,7 @@ export class MenuCommandContext<
|
||||
switch (this.interaction.data.type) {
|
||||
case ApplicationCommandType.Message: {
|
||||
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: {
|
||||
const data = this.interaction.data.resolved.users[this.interaction.data.targetId as Lowercase<string>];
|
||||
|
@ -10,7 +10,7 @@ import type {
|
||||
RESTPostAPIGuildChannelJSONBody,
|
||||
RESTPostAPIGuildsJSONBody,
|
||||
} from 'discord-api-types/v10';
|
||||
import type { ObjectToLower } from '..';
|
||||
import { toSnakeCase, type ObjectToLower } from '..';
|
||||
import { resolveFiles } from '../../builders';
|
||||
import {
|
||||
AnonymousGuild,
|
||||
@ -267,7 +267,7 @@ export class GuildShorter extends BaseShorter {
|
||||
return this.client.proxy
|
||||
.guilds(guildId)
|
||||
['auto-moderation'].rules(ruleId)
|
||||
.patch({ body, reason })
|
||||
.patch({ body: toSnakeCase(body), reason })
|
||||
.then(rule => new AutoModerationRule(this.client, rule));
|
||||
},
|
||||
};
|
||||
|
@ -104,17 +104,41 @@ export type ObjectToLower<T> = Identify<{
|
||||
? Identify<ObjectToLower<T[K][0]>[]>
|
||||
: T[K] extends object
|
||||
? Identify<ObjectToLower<T[K]>>
|
||||
: 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];
|
||||
}>;
|
||||
|
||||
export type ObjectToSnake<T> = Identify<{
|
||||
[K in keyof T as SnakeCase<Exclude<K, symbol | number>>]: T[K] extends unknown[]
|
||||
? Identify<ObjectToSnake<T[K][0]>[]>
|
||||
: T[K] extends object
|
||||
? Identify<ObjectToSnake<T[K]>>
|
||||
: 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];
|
||||
}>;
|
||||
|
||||
export type UnionToTuple<U, A extends any[] = []> = (U extends void ? void : (arg: () => U) => never) extends (
|
||||
arg: infer I,
|
||||
) => void
|
||||
|
@ -4,7 +4,7 @@ import type {
|
||||
RESTPostAPIAutoModerationRuleJSONBody,
|
||||
} from 'discord-api-types/v10';
|
||||
import type { UsingClient } from '../commands';
|
||||
import type { MethodContext, ObjectToLower } from '../common';
|
||||
import { toCamelCase, type MethodContext, type ObjectToLower } from '../common';
|
||||
import { DiscordBase } from './extra/DiscordBase';
|
||||
|
||||
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),
|
||||
fetch: (ruleId: string) => client.guilds.moderation.fetch(guildId, ruleId),
|
||||
edit: (ruleId: string, body: RESTPatchAPIAutoModerationRuleJSONBody, reason?: string) =>
|
||||
client.guilds.moderation.edit(guildId, ruleId, body, reason),
|
||||
client.guilds.moderation.edit(guildId, ruleId, toCamelCase(body), reason),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user