diff --git a/src/api/Routes/channels.ts b/src/api/Routes/channels.ts index eb23529a..52df39c2 100644 --- a/src/api/Routes/channels.ts +++ b/src/api/Routes/channels.ts @@ -61,19 +61,15 @@ import type { RestArguments } from '../api'; export interface ChannelRoutes { channels(id: string): { - //. get(args?: RestArguments): Promise; - //. patch( args: RestArguments, ): Promise; - //. delete(args?: RestArguments): Promise; users: (id: '@me') => { threads: { archived: { private: { - //. get( args?: RestArguments, ): Promise; @@ -82,33 +78,26 @@ export interface ChannelRoutes { }; }; 'thread-members': { - //. get( args?: RestArguments, ): Promise; ( id: '@me', ): { - //. put(args?: RestArguments): Promise; - //. delete(args?: RestArguments): Promise; }; ( id: string, ): { - //. get( args?: RestArguments, ): Promise; - //. put(args?: RestArguments): Promise; - //. delete(args?: RestArguments): Promise; }; }; threads: { - //. post( args: RestArguments< ProxyRequestMethod.Post, @@ -117,13 +106,11 @@ export interface ChannelRoutes { ): Promise; archived: { public: { - //. get( args?: RestArguments, ): Promise; }; private: { - //. get( args?: RestArguments, ): Promise; @@ -131,58 +118,45 @@ export interface ChannelRoutes { }; }; recipients: (id: string) => { - //. put( args?: RestArguments, ): Promise; - //. delete(args?: RestArguments): Promise; }; pins: { - //. get(args?: RestArguments): Promise; ( id: string, ): { - //. put(args?: RestArguments): Promise; - //. delete(args?: RestArguments): Promise; }; }; followers: { - //. post( args: RestArguments, ): Promise; }; permissions: (id: string) => { - //. put( args?: RestArguments, ): Promise; - //. delete(args?: RestArguments): Promise; }; invites: { - //. get(args?: RestArguments): Promise; - //. post( args: RestArguments, ): Promise; }; messages: { - //. get( args?: RestArguments, ): Promise; - //. post( args: RestArguments, ): Promise; 'bulk-delete': { - //. post( args: RestArguments, ): Promise; @@ -190,44 +164,34 @@ export interface ChannelRoutes { ( id: string, ): { - //. get(args?: RestArguments): Promise; - //. patch( args: RestArguments, ): Promise; - //. delete(args?: RestArguments): Promise; threads: { - //. post( args: RestArguments, ): Promise; }; crosspost: { - //. post(args: RestArguments): Promise; }; reactions: { - //. delete( args?: RestArguments, ): Promise; ( emoji: string, ): { - //. get( args?: RestArguments, ): Promise; - //. delete(args?: RestArguments): Promise; ( id: '@me', ): { - //. put(args?: RestArguments): Promise; - //. delete( args?: RestArguments, ): Promise; @@ -235,7 +199,6 @@ export interface ChannelRoutes { ( id: string, ): { - //. delete( args?: RestArguments, ): Promise; @@ -245,13 +208,10 @@ export interface ChannelRoutes { }; }; typing: { - //. post(args?: RestArguments): Promise; }; webhooks: { - //. get(args?: RestArguments): Promise; - //. post( args: RestArguments, ): Promise; diff --git a/src/api/Routes/guilds.ts b/src/api/Routes/guilds.ts index 49fece89..28d8a4b2 100644 --- a/src/api/Routes/guilds.ts +++ b/src/api/Routes/guilds.ts @@ -118,12 +118,9 @@ import type { RawFile } from '../shared'; export interface GuildRoutes { guilds: { - //. post(args: RestArguments): Promise; templates(code: string): { - //. get(args?: RestArguments): Promise; - //. post( args: RestArguments, ): Promise; @@ -131,71 +128,54 @@ export interface GuildRoutes { ( id: string, ): { - //. get(args?: RestArguments): Promise; - //. patch(args: RestArguments): Promise; - //. delete(args?: RestArguments): Promise; webhooks: { - //. get(args?: RestArguments): Promise; }; preview: { - //. get(args?: RestArguments): Promise; }; 'audit-logs': { - //. get(args?: RestArguments): Promise; }; 'auto-moderation': { rules: { - //. get(args?: RestArguments): Promise; - //. post( args: RestArguments, ): Promise; ( id: string, ): { - //. get(args?: RestArguments): Promise; - //. patch( args: RestArguments, ): Promise; - //. delete(args?: RestArguments): Promise; }; }; }; channels: { - //. get(args?: RestArguments): Promise; - //. post( args: RestArguments, ): Promise; - //. patch( args: RestArguments, ): Promise; }; members: { - //. get( args?: RestArguments, ): Promise; search: { - //. get( args: RestArguments, ): Promise; }; '@me': { - //. patch( args: RestArguments, ): Promise; @@ -203,133 +183,102 @@ export interface GuildRoutes { ( id: string, ): { - //. get(args?: RestArguments): Promise; - //. put( args?: RestArguments, ): Promise; - //. - //. patch( args: RestArguments, ): Promise; - //. delete(args?: RestArguments): Promise; roles(id: string): { - //. put(args?: RestArguments): Promise; - //. delete(args?: RestArguments): Promise; }; }; }; threads: { active: { - //. get( args?: RestArguments, ): Promise }>>; }; }; roles: { - //. get(args?: RestArguments): Promise; - //. post( args: RestArguments, ): Promise; - //. patch( args: RestArguments, ): Promise; ( id: string, ): { - //. patch( args: RestArguments, ): Promise; - //. delete(args?: RestArguments): Promise; }; }; bans: { - //. get(args?: RestArguments): Promise; ( userId: string, ): { - //. get(args?: RestArguments): Promise; - //. put( args?: RestArguments, ): Promise; - //. delete(args?: RestArguments): Promise; }; }; mfa: { - //. post( args: RestArguments, ): Promise; }; prune: { - //. get( args: RestArguments, ): Promise; - //. post( args: RestArguments, ): Promise; }; regions: { - //. get(args?: RestArguments): Promise; }; invites: { - //. get(args?: RestArguments): Promise; }; widget: { - //. get(args?: RestArguments): Promise; - //. patch( args: RestArguments, ): Promise; }; 'widget.json': { - //. get(args?: RestArguments): Promise; }; 'widget.png': { - //. get( args?: RestArguments, ): Promise; }; integrations: { - //. get(args?: RestArguments): Promise; ( id: string, ): { - //. delete(args?: RestArguments): Promise; }; }; 'vanity-url': { - //. get(args?: RestArguments): Promise; }; 'welcome-screen': { - //. get(args?: RestArguments): Promise; - //. patch( args: RestArguments, ): Promise; @@ -338,28 +287,22 @@ export interface GuildRoutes { // get(args:RestArguments); // } emojis: { - //. get(args?: RestArguments): Promise; - //. post( args: RestArguments, ): Promise; ( id: string, ): { - //. get(args?: RestArguments): Promise; - //. patch( args: RestArguments, ): Promise; - //. delete(args?: RestArguments): Promise; }; }; 'voice-states': { '@me': { - //. patch( args: RestArguments, ): Promise; @@ -367,16 +310,13 @@ export interface GuildRoutes { ( id: string, ): { - //. patch( args: RestArguments, ): Promise; }; }; stickers: { - //. get(args?: RestArguments): Promise; - //. post( args: RestArguments< ProxyRequestMethod.Post, @@ -388,40 +328,31 @@ export interface GuildRoutes { ( id: string, ): { - //. get(args?: RestArguments): Promise; - //. patch( args: RestArguments, ): Promise; - //. delete(args?: RestArguments): Promise; }; }; 'scheduled-events': { - //. get( args?: RestArguments, ): Promise; - //. post( args: RestArguments, ): Promise; ( id: string, ): { - //. get( args?: RestArguments, ): Promise; - //. patch( args: RestArguments, ): Promise; - //. delete(args?: RestArguments): Promise; users: { - //. get( args?: RestArguments, ): Promise; @@ -429,22 +360,17 @@ export interface GuildRoutes { }; }; templates: { - //. get(args?: RestArguments): Promise; - //. post( args: RestArguments, ): Promise; ( code: string, ): { - //. put(args?: RestArguments): Promise; - //. patch( args: RestArguments, ): Promise; - //. delete(args?: RestArguments): Promise; }; }; diff --git a/src/cache/resources/messages.ts b/src/cache/resources/messages.ts index 68eb28ab..f4f9a577 100644 --- a/src/cache/resources/messages.ts +++ b/src/cache/resources/messages.ts @@ -14,16 +14,17 @@ export class Messages extends GuildRelatedResource { override parse(data: any, _key: string, _channel_id: string) { const { author, member, ...rest } = data; - rest.user_id = author.id; + if (author?.id) rest.user_id = author.id; return rest; } override get(id: string): ReturnCache { return fakePromise(super.get(id) as APIMessageResource).then(rawMessage => { - const user = this.cache.users - ? (this.cache.adapter.get(this.cache.users.hashId(rawMessage.user_id)) as APIUser | undefined) - : undefined; + const user = + this.cache.users && rawMessage.user_id + ? (this.cache.adapter.get(this.cache.users.hashId(rawMessage.user_id)) as APIUser | undefined) + : undefined; return user ? new Message(this.client, { ...rawMessage, author: user }) : undefined; }); } @@ -33,9 +34,10 @@ export class Messages extends GuildRelatedResource { messages => messages .map(rawMessage => { - const user = this.cache.users - ? (this.cache.adapter.get(this.cache.users.hashId(rawMessage.user_id)) as APIUser | undefined) - : undefined; + const user = + this.cache.users && rawMessage.user_id + ? (this.cache.adapter.get(this.cache.users.hashId(rawMessage.user_id)) as APIUser | undefined) + : undefined; return user ? new Message(this.client, { ...rawMessage, author: user }) : undefined; }) .filter(Boolean) as Message[], @@ -44,8 +46,10 @@ export class Messages extends GuildRelatedResource { override values(guild: string): ReturnCache { return fakePromise(super.values(guild) as APIMessageResource[]).then(messages => { - const hashes: string[] = this.cache.users ? messages.map(x => this.cache.users!.hashId(x.user_id)) : []; - return fakePromise(this.cache.adapter.get(hashes) as APIUser[]).then(users => { + const hashes: (string | undefined)[] = this.cache.users + ? messages.map(x => (x.user_id ? this.cache.users!.hashId(x.user_id) : undefined)) + : []; + return fakePromise(this.cache.adapter.get(hashes.filter(Boolean) as string[]) as APIUser[]).then(users => { return messages .map(message => { const user = users.find(user => user.id === message.user_id); @@ -57,4 +61,4 @@ export class Messages extends GuildRelatedResource { } } -export type APIMessageResource = Omit & { user_id: string }; +export type APIMessageResource = Omit & { user_id?: string }; diff --git a/src/structures/Interaction.ts b/src/structures/Interaction.ts index 3cdb14aa..bb279a06 100644 --- a/src/structures/Interaction.ts +++ b/src/structures/Interaction.ts @@ -38,7 +38,7 @@ import { } from 'discord-api-types/v10'; import { mix } from 'ts-mixer'; import type { RawFile } from '../api'; -import { ActionRow, Embed, Modal, resolveAttachment, resolveFiles } from '../builders'; +import { ActionRow, Embed, Modal, PollBuilder, resolveAttachment, resolveFiles } from '../builders'; import { OptionResolver, type ContextOptionsResolved, type UsingClient } from '../commands'; import type { ObjectToLower, OmitInsert, ToClass, When } from '../common'; import type { @@ -132,7 +132,7 @@ export class BaseInteraction< components: body.data?.components?.map(x => (x instanceof ActionRow ? x.toJSON() : x)) ?? undefined, embeds: body.data?.embeds?.map(x => (x instanceof Embed ? x.toJSON() : x)) ?? undefined, attachments: body.data?.attachments?.map((x, i) => ({ id: i, ...resolveAttachment(x) })) ?? undefined, - poll: poll ? ('toJSON' in poll ? poll.toJSON() : poll) : undefined, + poll: poll ? (poll instanceof PollBuilder ? poll.toJSON() : poll) : undefined, }, }; } @@ -170,8 +170,7 @@ export class BaseInteraction< ...body, components: body.components?.map(x => (x instanceof ActionRow ? x.toJSON() : x)) ?? undefined, embeds: body?.embeds?.map(x => (x instanceof Embed ? x.toJSON() : x)) ?? undefined, - poll: poll ? ('toJSON' in poll ? poll.toJSON() : poll) : undefined, - // attachments: body.attachments?.map((x, i) => ({ id: i, ...resolveAttachment(x) })) ?? undefined, + poll: poll ? (poll instanceof PollBuilder ? poll.toJSON() : poll) : undefined, } as T; } diff --git a/src/structures/channels.ts b/src/structures/channels.ts index 58d71ce3..04e0fd50 100644 --- a/src/structures/channels.ts +++ b/src/structures/channels.ts @@ -25,7 +25,7 @@ import { type ThreadAutoArchiveDuration, } from 'discord-api-types/v10'; import { mix } from 'ts-mixer'; -import { Embed, resolveAttachment } from '../builders'; +import { ActionRow, Embed, PollBuilder, resolveAttachment } from '../builders'; import type { UsingClient } from '../commands'; import type { EmojiResolvable, @@ -254,10 +254,10 @@ export class MessagesMethods extends DiscordBase { const poll = (body as MessageCreateBodyRequest).poll; return { ...body, - components: body.components?.map(x => ('toJSON' in x ? x.toJSON() : x)) ?? undefined, + components: body.components?.map(x => (x instanceof ActionRow ? x.toJSON() : x)) ?? undefined, embeds: body.embeds?.map(x => (x instanceof Embed ? x.toJSON() : x)) ?? undefined, attachments: body.attachments?.map((x, i) => ({ id: i, ...resolveAttachment(x) })) ?? undefined, - poll: poll ? ('toJSON' in poll ? poll.toJSON() : poll) : undefined, + poll: poll ? (poll instanceof PollBuilder ? poll.toJSON() : poll) : undefined, } as T; } }