feat: change force to rest,flow,cache

This commit is contained in:
MARCROCK22 2025-01-19 14:44:33 -04:00
parent c3ba598804
commit cb7dacc7a7
18 changed files with 254 additions and 69 deletions

View File

@ -150,7 +150,7 @@ export class CommandContext<
return (this.messageResponse = (await this.messageResponse!.fetch()) as never);
}
channel(mode?: 'rest' | 'flow'): Promise<If<InferWithPrefix, AllChannels | undefined, AllChannels>>;
channel(mode?: 'rest' | 'flow'): Promise<AllChannels>;
channel(mode: 'cache'): ReturnCache<If<InferWithPrefix, AllChannels | undefined, AllChannels>>;
channel(mode: 'cache' | 'rest' | 'flow' = 'flow') {
if (this.interaction && mode === 'cache')
@ -166,7 +166,7 @@ export class CommandContext<
}
}
me(mode?: 'rest' | 'flow'): Promise<GuildMemberStructure>;
me(mode?: 'rest' | 'flow'): Promise<GuildMemberStructure | undefined>;
me(mode: 'cache'): ReturnCache<GuildMemberStructure | undefined>;
me(mode: 'cache' | 'rest' | 'flow' = 'flow') {
if (!this.guildId)
@ -186,11 +186,7 @@ export class CommandContext<
guild(mode: 'cache'): ReturnCache<GuildStructure<'cached'> | undefined>;
guild(mode: 'cache' | 'rest' | 'flow' = 'flow') {
if (!this.guildId)
return (mode === 'cache'
? this.client.cache.adapter.isAsync
? Promise.resolve()
: undefined
: Promise.resolve()) as unknown as undefined;
return mode === 'cache' ? (this.client.cache.adapter.isAsync ? Promise.resolve() : undefined) : Promise.resolve();
switch (mode) {
case 'cache':
return (

View File

@ -89,19 +89,22 @@ export class EntryPointContext<M extends keyof RegisteredMiddlewares = never> ex
channel(mode?: 'rest' | 'flow'): Promise<AllChannels>;
channel(mode: 'cache'): ReturnCache<AllChannels>;
channel(mode: 'cache' | 'rest' | 'flow' = 'flow') {
if (this.interaction.channel && mode === 'cache')
if (mode === 'cache')
return this.client.cache.adapter.isAsync ? Promise.resolve(this.interaction.channel) : this.interaction.channel;
return this.client.channels.fetch(this.channelId, mode === 'rest');
}
me(mode?: 'rest' | 'flow'): Promise<GuildMemberStructure>;
me(mode?: 'rest' | 'flow'): Promise<GuildMemberStructure | undefined>;
me(mode: 'cache'): ReturnCache<GuildMemberStructure | undefined>;
me(mode: 'cache' | 'rest' | 'flow' = 'flow') {
if (!this.guildId)
return mode === 'cache' ? (this.client.cache.adapter.isAsync ? Promise.resolve() : undefined) : Promise.resolve();
switch (mode) {
case 'cache':
return this.client.cache.members?.get(this.client.botId, this.guildId);
return (
this.client.cache.members?.get(this.client.botId, this.guildId) ||
(this.client.cache.adapter.isAsync ? (Promise.resolve() as any) : undefined)
);
default:
return this.client.members.fetch(this.guildId, this.client.botId, mode === 'rest');
}

View File

@ -113,14 +113,14 @@ export class MenuCommandContext<
channel(mode?: 'rest' | 'flow'): Promise<AllChannels>;
channel(mode: 'cache'): ReturnCache<AllChannels>;
channel(mode: 'cache' | 'rest' | 'flow' = 'flow') {
if (this.interaction.channel && mode === 'cache')
if (mode === 'cache')
return this.client.cache.adapter.isAsync ? Promise.resolve(this.interaction.channel) : this.interaction.channel;
return this.client.channels.fetch(this.channelId, mode === 'rest');
}
me(mode?: 'rest' | 'flow'): Promise<GuildMemberStructure>;
me(mode?: 'rest' | 'flow'): Promise<GuildMemberStructure | undefined>;
me(mode: 'cache'): ReturnCache<GuildMemberStructure | undefined>;
me(mode: 'cache' | 'rest' | 'flow' = 'flow') {
me(mode: 'cache' | 'rest' | 'flow' = 'flow'): any {
if (!this.guildId)
return mode === 'cache' ? (this.client.cache.adapter.isAsync ? Promise.resolve() : undefined) : Promise.resolve();
switch (mode) {

View File

@ -162,7 +162,7 @@ export class ComponentContext<
channel(mode?: 'rest' | 'flow'): Promise<AllChannels>;
channel(mode: 'cache'): ReturnCache<AllChannels>;
channel(mode: 'cache' | 'rest' | 'flow' = 'flow') {
if (this.interaction.channel && mode === 'cache')
if (mode === 'cache')
return this.client.cache.adapter.isAsync ? Promise.resolve(this.interaction.channel) : this.interaction.channel;
return this.client.channels.fetch(this.channelId, mode === 'rest');
}
@ -172,9 +172,9 @@ export class ComponentContext<
* @param mode - The mode to fetch the member.
* @returns A promise that resolves to the bot member.
*/
me(mode?: 'rest' | 'flow'): Promise<GuildMemberStructure>;
me(mode?: 'rest' | 'flow'): Promise<GuildMemberStructure | undefined>;
me(mode: 'cache'): ReturnCache<GuildMemberStructure | undefined>;
me(mode: 'cache' | 'rest' | 'flow' = 'flow') {
me(mode: 'cache' | 'rest' | 'flow' = 'flow'): any {
if (!this.guildId)
return mode === 'cache' ? (this.client.cache.adapter.isAsync ? Promise.resolve() : undefined) : Promise.resolve();
switch (mode) {

View File

@ -132,7 +132,7 @@ export class ModalContext<M extends keyof RegisteredMiddlewares = never> extends
channel(mode?: 'rest' | 'flow'): Promise<AllChannels>;
channel(mode: 'cache'): ReturnCache<AllChannels>;
channel(mode: 'cache' | 'rest' | 'flow' = 'flow') {
if (this.interaction.channel && mode === 'cache')
if (mode === 'cache')
return this.client.cache.adapter.isAsync ? Promise.resolve(this.interaction.channel) : this.interaction.channel;
return this.client.channels.fetch(this.channelId, mode === 'rest');
}
@ -142,9 +142,9 @@ export class ModalContext<M extends keyof RegisteredMiddlewares = never> extends
* @param mode - The mode to fetch the member.
* @returns A promise that resolves to the bot member.
*/
me(mode?: 'rest' | 'flow'): Promise<GuildMemberStructure>;
me(mode?: 'rest' | 'flow'): Promise<GuildMemberStructure | undefined>;
me(mode: 'cache'): ReturnCache<GuildMemberStructure | undefined>;
me(mode: 'cache' | 'rest' | 'flow' = 'flow') {
me(mode: 'cache' | 'rest' | 'flow' = 'flow'): any {
if (!this.guildId)
return mode === 'cache' ? (this.client.cache.adapter.isAsync ? Promise.resolve() : undefined) : Promise.resolve();
switch (mode) {

View File

@ -1,3 +1,4 @@
import type { ReturnCache } from '../../src';
import type { AutoModerationRuleStructure, GuildMemberStructure, GuildStructure } from '../client';
import type { UsingClient } from '../commands';
import type { MethodContext, ObjectToLower } from '../common';
@ -19,8 +20,18 @@ export class AutoModerationRule extends DiscordBase<APIAutoModerationRule> {
return this.client.members.fetch(this.guildId, this.creatorId, force);
}
guild(force = false): Promise<GuildStructure<'api'>> {
return this.client.guilds.fetch(this.guildId, force);
guild(mode?: 'rest' | 'flow'): Promise<GuildStructure<'cached' | 'api'>>;
guild(mode: 'cache'): ReturnCache<GuildStructure<'cached'> | undefined>;
guild(mode: 'cache' | 'rest' | 'flow' = 'flow'): any {
switch (mode) {
case 'cache':
return (
this.client.cache.guilds?.get(this.guildId) ||
(this.client.cache.adapter.isAsync ? (Promise.resolve() as any) : undefined)
);
default:
return this.client.guilds.fetch(this.guildId, mode === 'rest');
}
}
fetch(): Promise<AutoModerationRuleStructure> {

View File

@ -1,3 +1,4 @@
import type { ReturnCache } from '../../src';
import type { GuildBanStructure, GuildStructure } from '../client';
import type { UsingClient } from '../commands';
import { Formatter, type MethodContext, type ObjectToLower } from '../common';
@ -24,8 +25,18 @@ export class GuildBan extends DiscordBase {
return this.client.bans.remove(this.guildId, this.id, reason);
}
guild(force = false): Promise<GuildStructure<'api'>> {
return this.client.guilds.fetch(this.guildId, force);
guild(mode?: 'rest' | 'flow'): Promise<GuildStructure<'cached' | 'api'>>;
guild(mode: 'cache'): ReturnCache<GuildStructure<'cached'> | undefined>;
guild(mode: 'cache' | 'rest' | 'flow' = 'flow') {
switch (mode) {
case 'cache':
return (
this.client.cache.guilds?.get(this.guildId) ||
(this.client.cache.adapter.isAsync ? (Promise.resolve() as any) : undefined)
);
default:
return this.client.guilds.fetch(this.guildId, mode === 'rest');
}
}
fetch(force = false): Promise<GuildBanStructure> {

View File

@ -1,3 +1,4 @@
import type { ReturnCache } from '../../src';
import type { BaseCDNUrlOptions } from '../api';
import type { GuildEmojiStructure, GuildStructure } from '../client';
import type { UsingClient } from '../commands';
@ -16,9 +17,18 @@ export class GuildEmoji extends DiscordBase {
super(client, { ...data, id: data.id! });
}
async guild(force = false): Promise<GuildStructure<'api'> | undefined> {
if (!this.guildId) return;
return this.client.guilds.fetch(this.guildId, force);
guild(mode?: 'rest' | 'flow'): Promise<GuildStructure<'cached' | 'api'>>;
guild(mode: 'cache'): ReturnCache<GuildStructure<'cached'> | undefined>;
guild(mode: 'cache' | 'rest' | 'flow' = 'flow'): unknown {
switch (mode) {
case 'cache':
return (
this.client.cache.guilds?.get(this.guildId) ||
(this.client.cache.adapter.isAsync ? (Promise.resolve() as any) : undefined)
);
default:
return this.client.guilds.fetch(this.guildId, mode === 'rest');
}
}
edit(body: RESTPatchAPIChannelJSONBody, reason?: string): Promise<GuildEmojiStructure> {

View File

@ -7,6 +7,7 @@ export type GuildMemberData =
| GatewayGuildMemberAddDispatchData
| APIInteractionDataResolvedGuildMember;
import type { ReturnCache } from '../../src';
import {
type DMChannelStructure,
type GuildMemberStructure,
@ -59,8 +60,18 @@ export class BaseGuildMember extends DiscordBase {
this.patch(data);
}
guild(force = false): Promise<GuildStructure<'api'>> {
return this.client.guilds.fetch(this.guildId, force);
guild(mode?: 'rest' | 'flow'): Promise<GuildStructure<'cached' | 'api'>>;
guild(mode: 'cache'): ReturnCache<GuildStructure<'cached'> | undefined>;
guild(mode: 'cache' | 'rest' | 'flow' = 'flow') {
switch (mode) {
case 'cache':
return (
this.client.cache.guilds?.get(this.guildId) ||
(this.client.cache.adapter.isAsync ? (Promise.resolve() as any) : undefined)
);
default:
return this.client.guilds.fetch(this.guildId, mode === 'rest');
}
}
fetch(force = false): Promise<GuildMemberStructure> {

View File

@ -1,3 +1,4 @@
import type { ReturnCache } from '../../src';
import type { GuildRoleStructure, GuildStructure } from '../client';
import type { UsingClient } from '../commands';
import { Formatter, type MethodContext, type ObjectToLower } from '../common';
@ -23,9 +24,18 @@ export class GuildRole extends DiscordBase {
this.permissions = new PermissionsBitField(BigInt(data.permissions));
}
async guild(force = false): Promise<GuildStructure<'api'> | undefined> {
if (!this.guildId) return;
return this.client.guilds.fetch(this.guildId, force);
guild(mode?: 'rest' | 'flow'): Promise<GuildStructure<'cached' | 'api'>>;
guild(mode: 'cache'): ReturnCache<GuildStructure<'cached'> | undefined>;
guild(mode: 'cache' | 'rest' | 'flow' = 'flow') {
switch (mode) {
case 'cache':
return (
this.client.cache.guilds?.get(this.guildId) ||
(this.client.cache.adapter.isAsync ? (Promise.resolve() as any) : undefined)
);
default:
return this.client.guilds.fetch(this.guildId, mode === 'rest');
}
}
fetch(force = false): Promise<GuildRoleStructure> {

View File

@ -1,3 +1,4 @@
import type { ReturnCache } from '../../src';
import type { GuildStructure, GuildTemplateStructure } from '../client';
import type { UsingClient } from '../commands';
import type { MethodContext, ObjectToLower } from '../common';
@ -12,8 +13,18 @@ export class GuildTemplate extends Base {
this.__patchThis(data);
}
guild(force = false): Promise<GuildStructure<'api'>> {
return this.client.guilds.fetch(this.sourceGuildId, force);
guild(mode?: 'rest' | 'flow'): Promise<GuildStructure<'cached' | 'api'>>;
guild(mode: 'cache'): ReturnCache<GuildStructure<'cached'> | undefined>;
guild(mode: 'cache' | 'rest' | 'flow' = 'flow') {
switch (mode) {
case 'cache':
return (
this.client.cache.guilds?.get(this.sourceGuildId) ||
(this.client.cache.adapter.isAsync ? (Promise.resolve() as any) : undefined)
);
default:
return this.client.guilds.fetch(this.sourceGuildId, mode === 'rest');
}
}
fetch(): Promise<GuildTemplateStructure> {

View File

@ -42,6 +42,7 @@ import {
type RESTPostAPIInteractionCallbackResult,
} from '../types';
import type { ReturnCache } from '../../src';
import type { RawFile } from '../api';
import { ActionRow, Embed, Modal, PollBuilder, resolveAttachment, resolveFiles } from '../builders';
import {
@ -364,8 +365,20 @@ export class BaseInteraction<
}
}
async fetchGuild(force = false): Promise<GuildStructure<'api'> | undefined> {
return this.guildId ? this.client.guilds.fetch(this.guildId, force) : undefined;
fetchGuild(mode?: 'rest' | 'flow'): Promise<GuildStructure<'cached' | 'api'> | undefined>;
fetchGuild(mode: 'cache'): ReturnCache<GuildStructure<'cached'> | undefined>;
fetchGuild(mode: 'cache' | 'rest' | 'flow' = 'flow') {
if (!this.guildId)
return mode === 'cache' ? (this.client.cache.adapter.isAsync ? Promise.resolve() : undefined) : Promise.resolve();
switch (mode) {
case 'cache':
return (
this.client.cache.guilds?.get(this.guildId) ||
(this.client.cache.adapter.isAsync ? (Promise.resolve() as any) : undefined)
);
default:
return this.client.guilds.fetch(this.guildId, mode === 'rest');
}
}
}

View File

@ -81,14 +81,27 @@ export class BaseMessage extends DiscordBase {
) as any;
switch (mode) {
case 'cache':
return this.client.cache.guilds?.get(this.guildId);
return (
this.client.cache.guilds?.get(this.guildId) ||
(this.client.cache.adapter.isAsync ? (Promise.resolve() as any) : undefined)
);
default:
return this.client.guilds.fetch(this.guildId, mode === 'rest');
}
}
channel(force = false): Promise<AllChannels> {
return this.client.channels.fetch(this.channelId, force);
channel(mode?: 'rest' | 'flow'): Promise<AllChannels>;
channel(mode: 'cache'): ReturnCache<AllChannels | undefined>;
channel(mode: 'cache' | 'rest' | 'flow' = 'flow') {
switch (mode) {
case 'cache':
return (
this.client.cache.channels?.get(this.channelId) ||
(this.client.cache.adapter.isAsync ? (Promise.resolve() as any) : undefined)
);
default:
return this.client.channels.fetch(this.channelId, mode === 'rest');
}
}
react(emoji: EmojiResolvable) {

View File

@ -1,4 +1,5 @@
import type { GuildStructure, RawFile, StickerStructure, UsingClient } from '..';
import type { ReturnCache } from '../../src';
import type { Attachment, AttachmentBuilder } from '../builders';
import { Transformers, type UserStructure } from '../client/transformers';
import type { MethodContext, ObjectToLower } from '../common';
@ -16,9 +17,20 @@ export class Sticker extends DiscordBase {
}
}
async guild(force = false): Promise<GuildStructure<'api'> | undefined> {
if (!this.guildId) return;
return this.client.guilds.fetch(this.guildId, force);
guild(mode?: 'rest' | 'flow'): Promise<GuildStructure<'cached' | 'api'> | undefined>;
guild(mode: 'cache'): ReturnCache<GuildStructure<'cached'> | undefined>;
guild(mode: 'cache' | 'rest' | 'flow' = 'flow') {
if (!this.guildId)
return mode === 'cache' ? (this.client.cache.adapter.isAsync ? Promise.resolve() : undefined) : Promise.resolve();
switch (mode) {
case 'cache':
return (
this.client.cache.guilds?.get(this.guildId) ||
(this.client.cache.adapter.isAsync ? (Promise.resolve() as any) : undefined)
);
default:
return this.client.guilds.fetch(this.guildId, mode === 'rest');
}
}
async edit(body: RESTPatchAPIGuildStickerJSONBody, reason?: string): Promise<StickerStructure | undefined> {

View File

@ -1,9 +1,10 @@
import type { UserStructure, UsingClient, VoiceStateStructure } from '../';
import type { GuildStructure, ReturnCache } from '../../src';
import type { VoiceStateResource } from '../cache/resources/voice-states';
import { type GuildMemberStructure, Transformers } from '../client/transformers';
import type { ObjectToLower } from '../common';
import type { APIVoiceState } from '../types';
import type { AllGuildVoiceChannels } from './channels';
import type { AllChannels } from './channels';
import { Base } from './extra/Base';
export interface VoiceState extends Base, ObjectToLower<Omit<VoiceStateResource, 'member'>> {}
@ -30,9 +31,20 @@ export class VoiceState extends Base {
return this.client.users.fetch(this.userId, force);
}
async channel(force?: boolean): Promise<AllGuildVoiceChannels | undefined> {
if (!this.channelId) return;
return this.client.channels.fetch(this.channelId, force) as Promise<AllGuildVoiceChannels>;
channel(mode?: 'rest' | 'flow'): Promise<AllChannels | undefined>;
channel(mode: 'cache'): ReturnCache<AllChannels | undefined>;
channel(mode: 'cache' | 'rest' | 'flow' = 'flow') {
if (!this.channelId)
return mode === 'cache' ? (this.client.cache.adapter.isAsync ? Promise.resolve() : undefined) : Promise.resolve();
switch (mode) {
case 'cache':
return (
this.client.cache.channels?.get(this.channelId) ||
(this.client.cache.adapter.isAsync ? (Promise.resolve() as any) : undefined)
);
default:
return this.client.channels.fetch(this.channelId, mode === 'rest');
}
}
async setMute(mute = !this.mute, reason?: string): Promise<GuildMemberStructure> {
@ -74,4 +86,18 @@ export class VoiceState extends Base {
this.channelId = channel_id;
return member;
}
guild(mode?: 'rest' | 'flow'): Promise<GuildStructure<'cached' | 'api'>>;
guild(mode: 'cache'): ReturnCache<GuildStructure<'cached'> | undefined>;
guild(mode: 'cache' | 'rest' | 'flow' = 'flow') {
switch (mode) {
case 'cache':
return (
this.client.cache.guilds?.get(this.guildId) ||
(this.client.cache.adapter.isAsync ? (Promise.resolve() as any) : undefined)
);
default:
return this.client.guilds.fetch(this.guildId, mode === 'rest');
}
}
}

View File

@ -1,3 +1,4 @@
import type { ReturnCache } from '../../src';
import {
type AnonymousGuildStructure,
type GuildStructure,
@ -66,9 +67,20 @@ export class Webhook extends DiscordBase {
* @param force Whether to force fetching the guild even if it's already cached.
* @returns A promise that resolves to the guild associated with the webhook, or undefined if not applicable.
*/
async guild(force = false): Promise<GuildStructure<'api'> | undefined> {
if (!this.sourceGuild?.id) return;
return this.client.guilds.fetch(this.sourceGuild.id, force);
guild(mode?: 'rest' | 'flow'): Promise<GuildStructure<'cached' | 'api'> | undefined>;
guild(mode: 'cache'): ReturnCache<GuildStructure<'cached'> | undefined>;
guild(mode: 'cache' | 'rest' | 'flow' = 'flow') {
if (!this.guildId)
return mode === 'cache' ? (this.client.cache.adapter.isAsync ? Promise.resolve() : undefined) : Promise.resolve();
switch (mode) {
case 'cache':
return (
this.client.cache.guilds?.get(this.guildId) ||
(this.client.cache.adapter.isAsync ? (Promise.resolve() as any) : undefined)
);
default:
return this.client.guilds.fetch(this.guildId, mode === 'rest');
}
}
/**
@ -76,9 +88,18 @@ export class Webhook extends DiscordBase {
* @param force Whether to force fetching the channel even if it's already cached.
* @returns A promise that resolves to the channel associated with the webhook, or undefined if not applicable.
*/
async channel(force = false): Promise<AllChannels | undefined> {
if (!this.sourceChannel?.id) return;
return this.client.channels.fetch(this.sourceChannel.id, force);
channel(mode?: 'rest' | 'flow'): Promise<AllChannels>;
channel(mode: 'cache'): ReturnCache<AllChannels | undefined>;
channel(mode: 'cache' | 'rest' | 'flow' = 'flow') {
switch (mode) {
case 'cache':
return (
this.client.cache.channels?.get(this.channelId) ||
(this.client.cache.adapter.isAsync ? (Promise.resolve() as any) : undefined)
);
default:
return this.client.channels.fetch(this.channelId, mode === 'rest');
}
}
/**

View File

@ -84,8 +84,18 @@ export class BaseNoEditableChannel<T extends ChannelType> extends DiscordBase<AP
return Formatter.channelLink(this.id);
}
fetch(force = false): Promise<AllChannels> {
return this.client.channels.fetch(this.id, force);
fetch(mode?: 'rest' | 'flow'): Promise<AllChannels>;
fetch(mode: 'cache'): ReturnCache<AllChannels | undefined>;
fetch(mode: 'cache' | 'rest' | 'flow' = 'flow') {
switch (mode) {
case 'cache':
return (
this.client.cache.channels?.get(this.id) ||
(this.client.cache.adapter.isAsync ? (Promise.resolve() as any) : undefined)
);
default:
return this.client.channels.fetch(this.id, mode === 'rest');
}
}
delete(reason?: string): Promise<AllChannels> {
@ -195,6 +205,7 @@ interface IChannelTypes {
export interface BaseGuildChannel extends ObjectToLower<Omit<APIGuildChannel<ChannelType>, 'permission_overwrites'>> {}
export class BaseGuildChannel extends BaseChannel<ChannelType> {
declare guildId: string;
constructor(client: UsingClient, data: APIGuildChannel<ChannelType>) {
const { permission_overwrites, ...rest } = data;
super(client, rest);
@ -225,8 +236,18 @@ export class BaseGuildChannel extends BaseChannel<ChannelType> {
return this.client.channels.overwritesFor(this.id, member);
}
guild(force = false): Promise<GuildStructure<'api'>> {
return this.client.guilds.fetch(this.guildId!, force);
guild(mode?: 'rest' | 'flow'): Promise<GuildStructure<'cached' | 'api'>>;
guild(mode: 'cache'): ReturnCache<GuildStructure<'cached'> | undefined>;
guild(mode: 'cache' | 'rest' | 'flow' = 'flow') {
switch (mode) {
case 'cache':
return (
this.client.cache.guilds?.get(this.guildId) ||
(this.client.cache.adapter.isAsync ? (Promise.resolve() as any) : undefined)
);
default:
return this.client.guilds.fetch(this.guildId, mode === 'rest');
}
}
get url() {
@ -341,7 +362,7 @@ export class MessagesMethods extends DiscordBase {
}
export interface TextBaseGuildChannel
extends ObjectToLower<Omit<APITextChannel, 'type' | 'permission_overwrites'>>,
extends ObjectToLower<Omit<APITextChannel, 'type' | 'permission_overwrites' | 'guild_id'>>,
MessagesMethods {}
@mix(MessagesMethods)
export class TextBaseGuildChannel extends BaseGuildChannel {}
@ -491,7 +512,7 @@ export class WebhookChannelMethods extends DiscordBase {
}
export interface TextGuildChannel
extends ObjectToLower<Omit<APITextChannel, 'type' | 'permission_overwrites'>>,
extends ObjectToLower<Omit<APITextChannel, 'type' | 'permission_overwrites' | 'guild_id'>>,
BaseGuildChannel,
TextBaseGuildChannel,
WebhookChannelMethods {}
@ -506,26 +527,30 @@ export class DMChannel extends BaseNoEditableChannel<ChannelType.DM> {
declare type: ChannelType.DM;
}
export interface VoiceChannel
extends ObjectToLower<Omit<APIGuildVoiceChannel, 'permission_overwrites'>>,
extends ObjectToLower<Omit<APIGuildVoiceChannel, 'permission_overwrites' | 'guild_id'>>,
Omit<TextGuildChannel, keyof BaseGuildChannel>,
VoiceChannelMethods,
WebhookChannelMethods {}
WebhookChannelMethods {
guildId: string;
}
@mix(TextGuildChannel, VoiceChannelMethods)
export class VoiceChannel extends BaseGuildChannel {
declare type: ChannelType.GuildVoice;
}
export interface StageChannel
extends ObjectToLower<Omit<APIGuildStageVoiceChannel, 'type' | 'permission_overwrites'>>,
extends ObjectToLower<Omit<APIGuildStageVoiceChannel, 'type' | 'permission_overwrites' | 'guild_id'>>,
TopicableGuildChannel,
VoiceChannelMethods {}
VoiceChannelMethods {
guildId: string;
}
@mix(TopicableGuildChannel, VoiceChannelMethods)
export class StageChannel extends BaseGuildChannel {
declare type: ChannelType.GuildStageVoice;
}
export interface MediaChannel
extends ObjectToLower<Omit<APIGuildMediaChannel, 'type' | 'permission_overwrites'>>,
extends ObjectToLower<Omit<APIGuildMediaChannel, 'type' | 'permission_overwrites' | 'guild_id'>>,
ThreadOnlyMethods {}
@mix(ThreadOnlyMethods)
export class MediaChannel extends BaseGuildChannel {
@ -533,7 +558,7 @@ export class MediaChannel extends BaseGuildChannel {
}
export interface ForumChannel
extends ObjectToLower<Omit<APIGuildForumChannel, 'permission_overwrites'>>,
extends ObjectToLower<Omit<APIGuildForumChannel, 'permission_overwrites' | 'guild_id'>>,
Omit<ThreadOnlyMethods, 'type' | 'edit'>,
WebhookChannelMethods {}
@mix(ThreadOnlyMethods, WebhookChannelMethods)
@ -542,7 +567,7 @@ export class ForumChannel extends BaseGuildChannel {
}
export interface ThreadChannel
extends ObjectToLower<Omit<APIThreadChannel, 'permission_overwrites'>>,
extends ObjectToLower<Omit<APIThreadChannel, 'permission_overwrites' | 'guild_id'>>,
Omit<TextBaseGuildChannel, 'edit' | 'parentId'> {}
@mix(TextBaseGuildChannel)
export class ThreadChannel extends BaseChannel<
@ -602,7 +627,8 @@ export class ThreadChannel extends BaseChannel<
}
}
export interface CategoryChannel extends ObjectToLower<Omit<APIGuildCategoryChannel, 'permission_overwrites'>> {}
export interface CategoryChannel
extends ObjectToLower<Omit<APIGuildCategoryChannel, 'permission_overwrites' | 'guild_id'>> {}
export class CategoryChannel extends (BaseGuildChannel as unknown as ToClass<
Omit<BaseGuildChannel, 'setParent' | 'type'>,
@ -612,7 +638,7 @@ export class CategoryChannel extends (BaseGuildChannel as unknown as ToClass<
}
export interface NewsChannel
extends ObjectToLower<Omit<APINewsChannel, 'permission_overwrites'>>,
extends ObjectToLower<Omit<APINewsChannel, 'permission_overwrites' | 'guild_id'>>,
WebhookChannelMethods,
Omit<TextGuildChannel, keyof BaseGuildChannel> {}
@mix(TextGuildChannel, WebhookChannelMethods)

View File

@ -1,4 +1,6 @@
import type { WorkerClient } from '../..';
import type { ReturnCache } from '../../../src';
import type { GuildStructure } from '../../client';
import { type ObjectToLower, calculateShardId } from '../../common';
import type { ImageOptions } from '../../common/types/options';
import { type APIPartialGuild, GuildFeature } from '../../types';
@ -31,9 +33,18 @@ export class BaseGuild extends DiscordBase<APIPartialGuild> {
/**
* Fetch guild on API
*/
async fetch() {
const data = await this.api.guilds(this.id).get();
return new BaseGuild(this.client, data);
fetch(mode?: 'rest' | 'flow'): Promise<GuildStructure<'cached' | 'api'>>;
fetch(mode: 'cache'): ReturnCache<GuildStructure<'cached'> | undefined>;
fetch(mode: 'cache' | 'rest' | 'flow' = 'flow') {
switch (mode) {
case 'cache':
return (
this.client.cache.guilds?.get(this.id) ||
(this.client.cache.adapter.isAsync ? (Promise.resolve() as any) : undefined)
);
default:
return this.client.guilds.fetch(this.id, mode === 'rest');
}
}
/**