UsingClient, __parseCommandLocales

This commit is contained in:
MARCROCK22 2024-03-22 13:34:31 -04:00
parent 51b8fd216c
commit b072e33fd6
23 changed files with 74 additions and 81 deletions

View File

@ -2,8 +2,7 @@ import type { APIAttachment, RESTAPIAttachment } from 'discord-api-types/v10';
import { randomBytes } from 'node:crypto'; import { randomBytes } from 'node:crypto';
import { readFile, stat } from 'node:fs/promises'; import { readFile, stat } from 'node:fs/promises';
import path from 'node:path'; import path from 'node:path';
import { throwError, type RawFile } from '..'; import { type UsingClient, throwError, type RawFile } from '..';
import type { BaseClient } from '../client/base';
import type { ImageResolvable, ObjectToLower } from '../common'; import type { ImageResolvable, ObjectToLower } from '../common';
import { Base } from '../structures/extra/Base'; import { Base } from '../structures/extra/Base';
@ -27,7 +26,7 @@ export interface AttachmentData {
export interface Attachment extends ObjectToLower<APIAttachment> {} export interface Attachment extends ObjectToLower<APIAttachment> {}
export class Attachment extends Base { export class Attachment extends Base {
constructor( constructor(
client: BaseClient, client: UsingClient,
public data: APIAttachment, public data: APIAttachment,
) { ) {
super(client); super(client);

7
src/cache/index.ts vendored
View File

@ -22,8 +22,7 @@ import { Stickers } from './resources/stickers';
import { Threads } from './resources/threads'; import { Threads } from './resources/threads';
import { VoiceStates } from './resources/voice-states'; import { VoiceStates } from './resources/voice-states';
import type { BaseClient } from '../client/base'; import type { InternalOptions, UsingClient } from '../commands';
import type { InternalOptions } from '../commands';
import { ChannelType, GatewayIntentBits } from '../common'; import { ChannelType, GatewayIntentBits } from '../common';
import { Overwrites } from './resources/overwrites'; import { Overwrites } from './resources/overwrites';
@ -103,7 +102,7 @@ export class Cache {
public intents: number, public intents: number,
public adapter: Adapter, public adapter: Adapter,
readonly disabledCache: (NonGuildBased | GuildBased | GuildRelated)[] = [], readonly disabledCache: (NonGuildBased | GuildBased | GuildRelated)[] = [],
client?: BaseClient, client?: UsingClient,
) { ) {
// non-guild based // non-guild based
if (!this.disabledCache.includes('users')) { if (!this.disabledCache.includes('users')) {
@ -149,7 +148,7 @@ export class Cache {
} }
/** @internal */ /** @internal */
__setClient(client: BaseClient) { __setClient(client: UsingClient) {
this.users?.__setClient(client); this.users?.__setClient(client);
this.guilds?.__setClient(client); this.guilds?.__setClient(client);

View File

@ -1,4 +1,5 @@
import type { BaseClient } from '../../../client/base'; import type { BaseClient } from '../../../client/base';
import type { UsingClient } from '../../../commands';
import { fakePromise, type GatewayIntentBits } from '../../../common'; import { fakePromise, type GatewayIntentBits } from '../../../common';
import type { Cache, ReturnCache } from '../../index'; import type { Cache, ReturnCache } from '../../index';
@ -8,7 +9,7 @@ export class BaseResource<T = any> {
constructor( constructor(
protected cache: Cache, protected cache: Cache,
client?: BaseClient, client?: UsingClient,
) { ) {
if (client) { if (client) {
this.client = client; this.client = client;
@ -16,7 +17,7 @@ export class BaseResource<T = any> {
} }
/** @internal */ /** @internal */
__setClient(client: BaseClient) { __setClient(client: UsingClient) {
this.client = client; this.client = client;
} }

View File

@ -1,4 +1,5 @@
import type { BaseClient } from '../../../client/base'; import type { BaseClient } from '../../../client/base';
import type { UsingClient } from '../../../commands';
import { fakePromise, type GatewayIntentBits } from '../../../common'; import { fakePromise, type GatewayIntentBits } from '../../../common';
import type { Cache, ReturnCache } from '../../index'; import type { Cache, ReturnCache } from '../../index';
@ -8,7 +9,7 @@ export class GuildBasedResource<T = any> {
constructor( constructor(
protected cache: Cache, protected cache: Cache,
client?: BaseClient, client?: UsingClient,
) { ) {
if (client) { if (client) {
this.client = client; this.client = client;
@ -16,7 +17,7 @@ export class GuildBasedResource<T = any> {
} }
/** @internal */ /** @internal */
__setClient(client: BaseClient) { __setClient(client: UsingClient) {
this.client = client; this.client = client;
} }

View File

@ -1,4 +1,5 @@
import type { BaseClient } from '../../../client/base'; import type { BaseClient } from '../../../client/base';
import type { UsingClient } from '../../../commands';
import { fakePromise, type GatewayIntentBits } from '../../../common'; import { fakePromise, type GatewayIntentBits } from '../../../common';
import type { Cache, ReturnCache } from '../../index'; import type { Cache, ReturnCache } from '../../index';
@ -8,7 +9,7 @@ export class GuildRelatedResource<T = any> {
constructor( constructor(
protected cache: Cache, protected cache: Cache,
client?: BaseClient, client?: UsingClient,
) { ) {
if (client) { if (client) {
this.client = client; this.client = client;
@ -16,7 +17,7 @@ export class GuildRelatedResource<T = any> {
} }
/** @internal */ /** @internal */
__setClient(client: BaseClient) { __setClient(client: UsingClient) {
this.client = client; this.client = client;
} }

View File

@ -1,9 +1,9 @@
import { basename, dirname } from 'node:path'; import { basename, dirname } from 'node:path';
import type { BaseClient } from '../client/base';
import type { Logger } from '../common'; import type { Logger } from '../common';
import { BaseHandler, Locale, type LocaleString } from '../common'; import { BaseHandler, Locale, type LocaleString } from '../common';
import { Command, SubCommand } from './applications/chat'; import { Command, SubCommand } from './applications/chat';
import { ContextMenuCommand } from './applications/menu'; import { ContextMenuCommand } from './applications/menu';
import type { UsingClient } from './applications/shared';
export class CommandHandler extends BaseHandler { export class CommandHandler extends BaseHandler {
values: (Command | ContextMenuCommand)[] = []; values: (Command | ContextMenuCommand)[] = [];
@ -11,7 +11,7 @@ export class CommandHandler extends BaseHandler {
constructor( constructor(
protected logger: Logger, protected logger: Logger,
protected client: BaseClient, protected client: UsingClient,
) { ) {
super(logger); super(logger);
} }
@ -35,7 +35,7 @@ export class CommandHandler extends BaseHandler {
} }
} }
async load(commandsDir: string, client: BaseClient) { async load(commandsDir: string, client: UsingClient) {
const result = (await this.loadFilesK<typeof Command>(await this.getFiles(commandsDir))).filter(x => x.file); const result = (await this.loadFilesK<typeof Command>(await this.getFiles(commandsDir))).filter(x => x.file);
this.values = []; this.values = [];
@ -65,6 +65,7 @@ export class CommandHandler extends BaseHandler {
commandInstance.__filePath = command.path; commandInstance.__filePath = command.path;
commandInstance.options ??= [] as NonNullable<Command['options']>; commandInstance.options ??= [] as NonNullable<Command['options']>;
if (commandInstance.__d) { if (commandInstance.__d) {
//@AutoLoad
const options = await this.getFiles(dirname(command.path)); const options = await this.getFiles(dirname(command.path));
for (const option of options) { for (const option of options) {
if (command.name === basename(option)) { if (command.name === basename(option)) {
@ -98,11 +99,11 @@ export class CommandHandler extends BaseHandler {
} }
this.values.push(commandInstance); this.values.push(commandInstance);
this.__parseLocales(commandInstance, client); this.__parseCommandLocales(commandInstance, client);
for (const i of commandInstance.options ?? []) { for (const i of commandInstance.options ?? []) {
if (i instanceof SubCommand) { if (i instanceof SubCommand) {
this.__parseLocales(i, client); this.__parseCommandLocales(i, client);
} }
} }
} }
@ -110,30 +111,23 @@ export class CommandHandler extends BaseHandler {
return this.values; return this.values;
} }
private __parseLocales(command: Command | SubCommand, client: BaseClient) { private __parseCommandLocales(command: Command | SubCommand, client: UsingClient) {
if (command.__t) { if (command.__t) {
command.name_localizations = {}; command.name_localizations = {};
command.description_localizations = {}; command.description_localizations = {};
for (const locale of Object.keys(client.langs.values)) { for (const locale of Object.keys(client.langs.values)) {
const aliases = this.client.langs.aliases.find(x => x[0] === locale)?.[1] ?? []; const locales = this.client.langs.aliases.find(x => x[0] === locale)?.[1] ?? [];
if (Object.values<string>(Locale).includes(locale)) { if (Object.values<string>(Locale).includes(locale)) locales.push(locale as LocaleString);
if (command.__t.name) {
const valueName = client.langs.getKey(locale, command.__t.name!);
if (valueName) command.name_localizations[locale as LocaleString] = valueName;
}
if (command.__t.description) {
const valueKey = client.langs.getKey(locale, command.__t.description!);
if (valueKey) command.description_localizations[locale as LocaleString] = valueKey;
}
}
for (const i of aliases) {
if (command.__t.name) { if (command.__t.name) {
for (const i of locales) {
const valueName = client.langs.getKey(locale, command.__t.name!); const valueName = client.langs.getKey(locale, command.__t.name!);
if (valueName) command.name_localizations[i] = valueName; if (valueName) command.name_localizations[i] = valueName;
} }
} }
for (const i of aliases) {
if (command.__t.description) { if (command.__t.description) {
for (const i of locales) {
const valueKey = client.langs.getKey(locale, command.__t.description!); const valueKey = client.langs.getKey(locale, command.__t.description!);
if (valueKey) command.description_localizations[i] = valueKey; if (valueKey) command.description_localizations[i] = valueKey;
} }

View File

@ -1,9 +1,9 @@
import type { Identify } from '..'; import type { Identify } from '..';
import type { ImageURLOptions } from '../../api'; import type { ImageURLOptions } from '../../api';
import type { BaseClient } from '../../client/base'; import type { UsingClient } from '../../commands';
export type ImageOptions = ImageURLOptions; export type ImageOptions = ImageURLOptions;
export type MethodContext<T = {}> = Identify<{ client: BaseClient } & T>; export type MethodContext<T = {}> = Identify<{ client: UsingClient } & T>;
export type MessageWebhookPayload<Body, Extra = {}> = Identify<{ body: Body } & Extra>; export type MessageWebhookPayload<Body, Extra = {}> = Identify<{ body: Body } & Extra>;

View File

@ -1,6 +1,6 @@
import type { ComponentCallback, ListenerOptions, ModalSubmitCallback } from '../builders/types'; import type { ComponentCallback, ListenerOptions, ModalSubmitCallback } from '../builders/types';
import type { BaseClient } from '../client/base';
import { LimitedCollection } from '../collection'; import { LimitedCollection } from '../collection';
import type { UsingClient } from '../commands';
import { BaseHandler, magicImport, type Logger, type OnFailCallback } from '../common'; import { BaseHandler, magicImport, type Logger, type OnFailCallback } from '../common';
import type { ComponentInteraction, ModalSubmitInteraction } from '../structures'; import type { ComponentInteraction, ModalSubmitInteraction } from '../structures';
import { ComponentCommand, InteractionCommandType, ModalCommand } from './command'; import { ComponentCommand, InteractionCommandType, ModalCommand } from './command';
@ -24,7 +24,7 @@ export class ComponentHandler extends BaseHandler {
constructor( constructor(
logger: Logger, logger: Logger,
protected client: BaseClient, protected client: UsingClient,
) { ) {
super(logger); super(logger);
} }

View File

@ -1,4 +1,4 @@
import type { BaseClient } from '../client/base'; import type { UsingClient } from '../commands';
import type { import type {
APIAutoModerationRule, APIAutoModerationRule,
MethodContext, MethodContext,
@ -11,7 +11,7 @@ import { DiscordBase } from './extra/DiscordBase';
export interface AutoModerationRule extends ObjectToLower<APIAutoModerationRule> {} export interface AutoModerationRule extends ObjectToLower<APIAutoModerationRule> {}
export class AutoModerationRule extends DiscordBase<APIAutoModerationRule> { export class AutoModerationRule extends DiscordBase<APIAutoModerationRule> {
constructor(client: BaseClient, data: APIAutoModerationRule) { constructor(client: UsingClient, data: APIAutoModerationRule) {
super(client, data); super(client, data);
} }

View File

@ -1,11 +1,11 @@
import type { BaseClient } from '../client/base'; import type { UsingClient } from '../commands';
import type { GatewayReadyDispatchData, RESTPatchAPICurrentUserJSONBody } from '../common'; import type { GatewayReadyDispatchData, RESTPatchAPICurrentUserJSONBody } from '../common';
import { User } from './User'; import { User } from './User';
export class ClientUser extends User { export class ClientUser extends User {
bot = true; bot = true;
constructor( constructor(
client: BaseClient, client: UsingClient,
data: GatewayReadyDispatchData['user'], data: GatewayReadyDispatchData['user'],
public application: GatewayReadyDispatchData['application'], public application: GatewayReadyDispatchData['application'],
) { ) {

View File

@ -1,4 +1,4 @@
import type { BaseClient } from '../client/base'; import type { UsingClient } from '../commands';
import type { APIGuild, APIPartialGuild, GatewayGuildCreateDispatchData, ObjectToLower } from '../common'; import type { APIGuild, APIPartialGuild, GatewayGuildCreateDispatchData, ObjectToLower } from '../common';
import type { StructPropState, StructStates, ToClass } from '../common/types/util'; import type { StructPropState, StructStates, ToClass } from '../common/types/util';
import { AutoModerationRule } from './AutoModerationRule'; import { AutoModerationRule } from './AutoModerationRule';
@ -21,7 +21,7 @@ export class Guild<State extends StructStates = 'api'> extends (BaseGuild as unk
large!: StructPropState<boolean, State, 'create'>; large!: StructPropState<boolean, State, 'create'>;
unavailable?: StructPropState<boolean, State, 'create'>; unavailable?: StructPropState<boolean, State, 'create'>;
constructor(client: BaseClient, data: APIGuild | GatewayGuildCreateDispatchData) { constructor(client: UsingClient, data: APIGuild | GatewayGuildCreateDispatchData) {
super(client, data); super(client, data);
if ('joined_at' in data) { if ('joined_at' in data) {

View File

@ -1,5 +1,5 @@
import type { BaseImageURLOptions } from '../api'; import type { BaseImageURLOptions } from '../api';
import type { BaseClient } from '../client/base'; import type { UsingClient } from '../commands';
import type { import type {
APIEmoji, APIEmoji,
EmojiShorter, EmojiShorter,
@ -14,7 +14,7 @@ export interface GuildEmoji extends DiscordBase, ObjectToLower<Omit<APIEmoji, 'i
export class GuildEmoji extends DiscordBase { export class GuildEmoji extends DiscordBase {
constructor( constructor(
client: BaseClient, client: UsingClient,
data: APIEmoji, data: APIEmoji,
readonly guildId: string, readonly guildId: string,
) { ) {

View File

@ -22,7 +22,7 @@ export type GuildMemberData =
| GatewayGuildMemberAddDispatchData | GatewayGuildMemberAddDispatchData
| APIInteractionDataResolvedGuildMember; | APIInteractionDataResolvedGuildMember;
import type { BaseClient } from '../client/base'; import type { UsingClient } from '../commands';
import type { ImageOptions, MethodContext } from '../common/types/options'; import type { ImageOptions, MethodContext } from '../common/types/options';
import type { GuildMemberResolvable } from '../common/types/resolvables'; import type { GuildMemberResolvable } from '../common/types/resolvables';
import { User } from './User'; import { User } from './User';
@ -38,7 +38,7 @@ export class BaseGuildMember extends DiscordBase {
joinedTimestamp?: number; joinedTimestamp?: number;
communicationDisabledUntilTimestamp?: number | null; communicationDisabledUntilTimestamp?: number | null;
constructor( constructor(
client: BaseClient, client: UsingClient,
data: GuildMemberData, data: GuildMemberData,
id: string, id: string,
/** the choosen guild id */ /** the choosen guild id */
@ -133,7 +133,7 @@ export interface GuildMember extends ObjectToLower<Omit<APIGuildMember, 'user' |
export class GuildMember extends BaseGuildMember { export class GuildMember extends BaseGuildMember {
user: User; user: User;
constructor( constructor(
client: BaseClient, client: UsingClient,
data: GuildMemberData, data: GuildMemberData,
user: APIUser | User, user: APIUser | User,
/** the choosen guild id */ /** the choosen guild id */
@ -212,7 +212,7 @@ export class InteractionGuildMember extends (GuildMember as unknown as ToClass<
>) { >) {
permissions: PermissionsBitField; permissions: PermissionsBitField;
constructor( constructor(
client: BaseClient, client: UsingClient,
data: APIInteractionDataResolvedGuildMember, data: APIInteractionDataResolvedGuildMember,
user: APIUser | User, user: APIUser | User,
/** the choosen guild id */ /** the choosen guild id */

View File

@ -1,4 +1,4 @@
import type { BaseClient } from '../client/base'; import type { UsingClient } from '../commands';
import type { APIGuildPreview, APIPartialGuild } from '../common'; import type { APIGuildPreview, APIPartialGuild } from '../common';
import { AnonymousGuild } from './AnonymousGuild'; import { AnonymousGuild } from './AnonymousGuild';
@ -7,7 +7,7 @@ import { AnonymousGuild } from './AnonymousGuild';
* @link https://discord.com/developers/docs/resources/guild#guild-preview-object * @link https://discord.com/developers/docs/resources/guild#guild-preview-object
*/ */
export class GuildPreview extends AnonymousGuild { export class GuildPreview extends AnonymousGuild {
constructor(client: BaseClient, data: APIGuildPreview) { constructor(client: UsingClient, data: APIGuildPreview) {
super(client, data as APIPartialGuild); super(client, data as APIPartialGuild);
} }
} }

View File

@ -1,4 +1,4 @@
import type { BaseClient } from '../client/base'; import type { UsingClient } from '../commands';
import type { import type {
APIRole, APIRole,
MethodContext, MethodContext,
@ -15,7 +15,7 @@ export interface GuildRole extends DiscordBase, ObjectToLower<Omit<APIRole, 'per
export class GuildRole extends DiscordBase { export class GuildRole extends DiscordBase {
permissions: PermissionsBitField; permissions: PermissionsBitField;
constructor( constructor(
client: BaseClient, client: UsingClient,
data: APIRole, data: APIRole,
readonly guildId: string, readonly guildId: string,
) { ) {

View File

@ -1,4 +1,4 @@
import type { BaseClient } from '../client/base'; import type { UsingClient } from '../commands';
import type { import type {
APITemplate, APITemplate,
MethodContext, MethodContext,
@ -11,7 +11,7 @@ import { Base } from './extra/Base';
export interface GuildTemplate extends Base, ObjectToLower<APITemplate> {} export interface GuildTemplate extends Base, ObjectToLower<APITemplate> {}
export class GuildTemplate extends Base { export class GuildTemplate extends Base {
constructor(client: BaseClient, data: APITemplate) { constructor(client: UsingClient, data: APITemplate) {
super(client); super(client);
this.__patchThis(data); this.__patchThis(data);
} }

View File

@ -1,8 +1,7 @@
import { mix } from 'ts-mixer'; import { mix } from 'ts-mixer';
import type { RawFile } from '../api'; import type { RawFile } from '../api';
import { ActionRow, Embed, Modal, resolveAttachment, resolveFiles } from '../builders'; import { ActionRow, Embed, Modal, resolveAttachment, resolveFiles } from '../builders';
import type { BaseClient } from '../client/base'; import { OptionResolver, type ContextOptionsResolved, type UsingClient } from '../commands';
import { type ContextOptionsResolved, OptionResolver, type UsingClient } from '../commands';
import type { import type {
APIActionRowComponent, APIActionRowComponent,
APIApplicationCommandAutocompleteInteraction, APIApplicationCommandAutocompleteInteraction,
@ -209,7 +208,7 @@ export class BaseInteraction<
}); });
} }
static from(client: BaseClient, gateway: GatewayInteractionCreateDispatchData, __reply?: __InternalReplyFunction) { static from(client: UsingClient, gateway: GatewayInteractionCreateDispatchData, __reply?: __InternalReplyFunction) {
switch (gateway.type) { switch (gateway.type) {
case InteractionType.ApplicationCommandAutocomplete: case InteractionType.ApplicationCommandAutocomplete:
return new AutocompleteInteraction(client, gateway, __reply); return new AutocompleteInteraction(client, gateway, __reply);
@ -293,7 +292,7 @@ export class AutocompleteInteraction<FromGuild extends boolean = boolean> extend
declare data: ObjectToLower<APIApplicationCommandAutocompleteInteraction['data']>; declare data: ObjectToLower<APIApplicationCommandAutocompleteInteraction['data']>;
options: OptionResolver; options: OptionResolver;
constructor( constructor(
client: BaseClient, client: UsingClient,
interaction: APIApplicationCommandAutocompleteInteraction, interaction: APIApplicationCommandAutocompleteInteraction,
protected __reply?: __InternalReplyFunction, protected __reply?: __InternalReplyFunction,
) { ) {
@ -492,7 +491,7 @@ export class SelectMenuInteraction extends ComponentInteraction {
declare data: ObjectToLower<APIMessageComponentSelectMenuInteraction['data']>; declare data: ObjectToLower<APIMessageComponentSelectMenuInteraction['data']>;
constructor( constructor(
client: BaseClient, client: UsingClient,
interaction: APIMessageComponentSelectMenuInteraction, interaction: APIMessageComponentSelectMenuInteraction,
protected __reply?: __InternalReplyFunction, protected __reply?: __InternalReplyFunction,
) { ) {
@ -517,7 +516,7 @@ export class StringSelectMenuInteraction<
export class ChannelSelectMenuInteraction extends SelectMenuInteraction { export class ChannelSelectMenuInteraction extends SelectMenuInteraction {
channels: AllChannels[]; channels: AllChannels[];
constructor( constructor(
client: BaseClient, client: UsingClient,
interaction: APIMessageComponentSelectMenuInteraction, interaction: APIMessageComponentSelectMenuInteraction,
protected __reply?: __InternalReplyFunction, protected __reply?: __InternalReplyFunction,
) { ) {
@ -532,7 +531,7 @@ export class MentionableSelectMenuInteraction extends SelectMenuInteraction {
members: InteractionGuildMember[]; members: InteractionGuildMember[];
users: User[]; users: User[];
constructor( constructor(
client: BaseClient, client: UsingClient,
interaction: APIMessageComponentSelectMenuInteraction, interaction: APIMessageComponentSelectMenuInteraction,
protected __reply?: __InternalReplyFunction, protected __reply?: __InternalReplyFunction,
) { ) {
@ -559,7 +558,7 @@ export class MentionableSelectMenuInteraction extends SelectMenuInteraction {
export class RoleSelectMenuInteraction extends SelectMenuInteraction { export class RoleSelectMenuInteraction extends SelectMenuInteraction {
roles: GuildRole[]; roles: GuildRole[];
constructor( constructor(
client: BaseClient, client: UsingClient,
interaction: APIMessageComponentSelectMenuInteraction, interaction: APIMessageComponentSelectMenuInteraction,
protected __reply?: __InternalReplyFunction, protected __reply?: __InternalReplyFunction,
) { ) {
@ -573,7 +572,7 @@ export class UserSelectMenuInteraction extends SelectMenuInteraction {
members: InteractionGuildMember[]; members: InteractionGuildMember[];
users: User[]; users: User[];
constructor( constructor(
client: BaseClient, client: UsingClient,
interaction: APIMessageComponentSelectMenuInteraction, interaction: APIMessageComponentSelectMenuInteraction,
protected __reply?: __InternalReplyFunction, protected __reply?: __InternalReplyFunction,
) { ) {

View File

@ -1,5 +1,5 @@
import type { ListenerOptions } from '../builders'; import type { ListenerOptions } from '../builders';
import type { BaseClient } from '../client/base'; import type { UsingClient } from '../commands';
import type { import type {
APIChannelMention, APIChannelMention,
APIGuildMember, APIGuildMember,
@ -35,7 +35,7 @@ export class BaseMessage extends DiscordBase {
users: (GuildMember | User)[]; users: (GuildMember | User)[];
}; };
constructor(client: BaseClient, data: MessageData) { constructor(client: UsingClient, data: MessageData) {
super(client, data); super(client, data);
this.mentions = { this.mentions = {
roles: data.mention_roles ?? [], roles: data.mention_roles ?? [],
@ -119,7 +119,7 @@ export interface Message
ObjectToLower<Omit<MessageData, 'timestamp' | 'author' | 'mentions' | 'components'>> {} ObjectToLower<Omit<MessageData, 'timestamp' | 'author' | 'mentions' | 'components'>> {}
export class Message extends BaseMessage { export class Message extends BaseMessage {
constructor(client: BaseClient, data: MessageData) { constructor(client: UsingClient, data: MessageData) {
super(client, data); super(client, data);
} }
@ -161,7 +161,7 @@ export type WriteMessageWebhook = MessageWebhookMethodWriteParams;
export class WebhookMessage extends BaseMessage { export class WebhookMessage extends BaseMessage {
constructor( constructor(
client: BaseClient, client: UsingClient,
data: MessageData, data: MessageData,
readonly webhookId: string, readonly webhookId: string,
readonly webhookToken: string, readonly webhookToken: string,

View File

@ -1,5 +1,5 @@
import type { UsingClient } from '..';
import type { Attachment } from '../builders'; import type { Attachment } from '../builders';
import type { BaseClient } from '../client/base';
import type { import type {
APISticker, APISticker,
MethodContext, MethodContext,
@ -14,7 +14,7 @@ export interface Sticker extends DiscordBase, ObjectToLower<Omit<APISticker, 'us
export class Sticker extends DiscordBase { export class Sticker extends DiscordBase {
user?: User; user?: User;
constructor(client: BaseClient, data: APISticker) { constructor(client: UsingClient, data: APISticker) {
super(client, data); super(client, data);
if (data.user) { if (data.user) {
this.user = new User(this.client, data.user); this.user = new User(this.client, data.user);

View File

@ -1,4 +1,4 @@
import type { BaseClient } from '../client/base'; import type { UsingClient } from '../commands';
import type { import type {
APIWebhook, APIWebhook,
ImageOptions, ImageOptions,
@ -22,7 +22,7 @@ export class Webhook extends DiscordBase {
user?: User; user?: User;
sourceGuild?: Partial<AnonymousGuild>; sourceGuild?: Partial<AnonymousGuild>;
messages!: ReturnType<typeof Webhook.messages>; messages!: ReturnType<typeof Webhook.messages>;
constructor(client: BaseClient, data: APIWebhook) { constructor(client: UsingClient, data: APIWebhook) {
super(client, data); super(client, data);
if (data.user) { if (data.user) {

View File

@ -15,7 +15,7 @@ import {
} from 'discord-api-types/v10'; } from 'discord-api-types/v10';
import { mix } from 'ts-mixer'; import { mix } from 'ts-mixer';
import { Embed, resolveAttachment } from '../builders'; import { Embed, resolveAttachment } from '../builders';
import type { BaseClient } from '../client/base'; import type { UsingClient } from '../commands';
import type { import type {
APIChannelBase, APIChannelBase,
APIGuildChannel, APIGuildChannel,
@ -43,7 +43,7 @@ import { channelLink } from './extra/functions';
export class BaseChannel<T extends ChannelType> extends DiscordBase<APIChannelBase<ChannelType>> { export class BaseChannel<T extends ChannelType> extends DiscordBase<APIChannelBase<ChannelType>> {
declare type: T; declare type: T;
constructor(client: BaseClient, data: APIChannelBase<ChannelType>) { constructor(client: UsingClient, data: APIChannelBase<ChannelType>) {
super(client, data); super(client, data);
} }
@ -164,7 +164,7 @@ interface IChannelTypes {
export interface BaseGuildChannel extends ObjectToLower<Omit<APIGuildChannel<ChannelType>, 'permission_overwrites'>> {} export interface BaseGuildChannel extends ObjectToLower<Omit<APIGuildChannel<ChannelType>, 'permission_overwrites'>> {}
export class BaseGuildChannel extends BaseChannel<ChannelType> { export class BaseGuildChannel extends BaseChannel<ChannelType> {
constructor(client: BaseClient, data: APIGuildChannel<ChannelType>) { constructor(client: UsingClient, data: APIGuildChannel<ChannelType>) {
const { permission_overwrites, ...rest } = data; const { permission_overwrites, ...rest } = data;
super(client, rest); super(client, rest);
} }
@ -265,7 +265,7 @@ export interface TextBaseGuildChannel
@mix(MessagesMethods) @mix(MessagesMethods)
export class TextBaseGuildChannel extends BaseGuildChannel {} export class TextBaseGuildChannel extends BaseGuildChannel {}
export default function channelFrom(data: APIChannelBase<ChannelType>, client: BaseClient): AllChannels { export default function channelFrom(data: APIChannelBase<ChannelType>, client: UsingClient): AllChannels {
switch (data.type) { switch (data.type) {
case ChannelType.GuildStageVoice: case ChannelType.GuildStageVoice:
return new StageChannel(client, data); return new StageChannel(client, data);

View File

@ -1,11 +1,10 @@
import { Router } from '../../api'; import { Router } from '../../api';
import type { BaseClient } from '../../client/base';
import type { UsingClient } from '../../commands'; import type { UsingClient } from '../../commands';
import { toCamelCase } from '../../common'; import { toCamelCase } from '../../common';
/** */ /** */
export abstract class Base { export abstract class Base {
constructor(client: BaseClient) { constructor(client: UsingClient) {
Object.assign(this, { client }); Object.assign(this, { client });
} }

View File

@ -1,11 +1,11 @@
import type { BaseClient } from '../../client/base'; import type { UsingClient } from '../../commands';
import { Base } from './Base'; import { Base } from './Base';
import { snowflakeToTimestamp } from './functions'; import { snowflakeToTimestamp } from './functions';
export class DiscordBase<Data extends Record<string, any> = { id: string }> extends Base { export class DiscordBase<Data extends Record<string, any> = { id: string }> extends Base {
id: string; id: string;
constructor( constructor(
client: BaseClient, client: UsingClient,
/** Unique ID of the object */ /** Unique ID of the object */
data: Data, data: Data,
) { ) {