aboutsummaryrefslogtreecommitdiff
path: root/src/lib/extensions/discord.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/extensions/discord.js')
-rw-r--r--src/lib/extensions/discord.js/BushGuildChannelManager.d.ts123
-rw-r--r--src/lib/extensions/discord.js/BushMessage.ts28
-rw-r--r--src/lib/extensions/discord.js/other.ts159
3 files changed, 309 insertions, 1 deletions
diff --git a/src/lib/extensions/discord.js/BushGuildChannelManager.d.ts b/src/lib/extensions/discord.js/BushGuildChannelManager.d.ts
new file mode 100644
index 0000000..3b07145
--- /dev/null
+++ b/src/lib/extensions/discord.js/BushGuildChannelManager.d.ts
@@ -0,0 +1,123 @@
+import type {
+ BushFetchedThreads,
+ BushGuild,
+ BushMappedGuildChannelTypes,
+ BushNonThreadGuildBasedChannel,
+ BushStoreChannel
+} from '#lib';
+import {
+ CachedManager,
+ type BaseFetchOptions,
+ type ChannelPosition,
+ type Collection,
+ type GuildBasedChannel,
+ type GuildChannelCreateOptions,
+ type GuildChannelManager,
+ type GuildChannelResolvable,
+ type GuildChannelTypes,
+ type Snowflake
+} from 'discord.js';
+import type { RawGuildChannelData } from 'discord.js/typings/rawDataTypes';
+
+/**
+ * Manages API methods for GuildChannels and stores their cache.
+ */
+export class BushGuildChannelManager
+ extends CachedManager<Snowflake, GuildBasedChannel, GuildChannelResolvable>
+ implements GuildChannelManager
+{
+ public constructor(guild: BushGuild, iterable?: Iterable<RawGuildChannelData>);
+
+ /**
+ * The number of channels in this managers cache excluding thread channels
+ * that do not count towards a guild's maximum channels restriction.
+ */
+ public readonly channelCountWithoutThreads: number;
+
+ /**
+ * The guild this Manager belongs to
+ */
+ public guild: BushGuild;
+
+ /**
+ * Creates a new channel in the guild.
+ * @param name The name of the new channel
+ * @param options Options for creating the new channel
+ * @example
+ * // Create a new text channel
+ * guild.channels.create('new-general', { reason: 'Needed a cool new channel' })
+ * .then(console.log)
+ * .catch(console.error);
+ * @example
+ * // Create a new channel with permission overwrites
+ * guild.channels.create('new-voice', {
+ * type: 'GUILD_VOICE',
+ * permissionOverwrites: [
+ * {
+ * id: message.author.id,
+ * deny: [Permissions.FLAGS.VIEW_CHANNEL],
+ * },
+ * ],
+ * })
+ * @deprecated See [Self-serve Game Selling Deprecation](https://support-dev.discord.com/hc/en-us/articles/4414590563479) for more information
+ */
+ // eslint-disable-next-line deprecation/deprecation
+ public create(name: string, options: GuildChannelCreateOptions & { type: 'GUILD_STORE' }): Promise<BushStoreChannel>;
+
+ /**
+ * Creates a new channel in the guild.
+ * @param name The name of the new channel
+ * @param options Options for creating the new channel
+ */
+ public create<T extends GuildChannelTypes>(
+ name: string,
+ options: GuildChannelCreateOptions & { type: T }
+ ): Promise<BushMappedGuildChannelTypes[T]>;
+
+ /**
+ * Creates a new channel in the guild.
+ * @param name The name of the new channel
+ * @param options Options for creating the new channel
+ */
+ public create(name: string, options: GuildChannelCreateOptions): Promise<BushNonThreadGuildBasedChannel>;
+
+ /**
+ * Obtains one or more guild channels from Discord, or the channel cache if they're already available.
+ * @param id The channel's id
+ * @param options Additional options for this fetch
+ * @example
+ * // Fetch all channels from the guild (excluding threads)
+ * message.guild.channels.fetch()
+ * .then(channels => console.log(`There are ${channels.size} channels.`))
+ * .catch(console.error);
+ * @example
+ * // Fetch a single channel
+ * message.guild.channels.fetch('222197033908436994')
+ * .then(channel => console.log(`The channel name is: ${channel.name}`))
+ * .catch(console.error);
+ */
+ public fetch(id: Snowflake, options?: BaseFetchOptions): Promise<BushNonThreadGuildBasedChannel | null>;
+ public fetch(id?: undefined, options?: BaseFetchOptions): Promise<Collection<Snowflake, BushNonThreadGuildBasedChannel>>;
+
+ /**
+ * Batch-updates the guild's channels' positions.
+ * <info>Only one channel's parent can be changed at a time</info>
+ * @param channelPositions Channel positions to update
+ * @example
+ * guild.channels.setPositions([{ channel: channelId, position: newChannelIndex }])
+ * .then(guild => console.log(`Updated channel positions for ${guild}`))
+ * .catch(console.error);
+ */
+ public setPositions(channelPositions: readonly ChannelPosition[]): Promise<BushGuild>;
+
+ /**
+ * Obtains all active thread channels in the guild from Discord
+ * @param cache Whether to cache the fetched data
+ * @example
+ * // Fetch all threads from the guild
+ * message.guild.channels.fetchActiveThreads()
+ * .then(fetched => console.log(`There are ${fetched.threads.size} threads.`))
+ * .catch(console.error);
+ */
+ public fetchActiveThreads(cache?: boolean): Promise<BushFetchedThreads>;
+}
diff --git a/src/lib/extensions/discord.js/BushMessage.ts b/src/lib/extensions/discord.js/BushMessage.ts
index b442196..16c57a2 100644
--- a/src/lib/extensions/discord.js/BushMessage.ts
+++ b/src/lib/extensions/discord.js/BushMessage.ts
@@ -4,10 +4,22 @@ import type {
BushGuild,
BushGuildMember,
BushGuildTextBasedChannel,
+ BushMessageReaction,
BushTextBasedChannel,
+ BushThreadChannel,
BushUser
} from '#lib';
-import { Message, type If, type Partialize } from 'discord.js';
+import {
+ Message,
+ type EmojiIdentifierResolvable,
+ type If,
+ type MessageActionRowComponent,
+ type MessageEditOptions,
+ type MessagePayload,
+ type Partialize,
+ type ReplyMessageOptions,
+ type StartThreadOptions
+} from 'discord.js';
import type { RawMessageData } from 'discord.js/typings/rawDataTypes';
export type PartialBushMessage = Partialize<
@@ -33,5 +45,19 @@ export class BushMessage<Cached extends boolean = boolean> extends Message<Cache
}
export interface BushMessage<Cached extends boolean = boolean> extends Message<Cached> {
+ delete(): Promise<BushMessage>;
+ edit(content: string | MessageEditOptions | MessagePayload): Promise<BushMessage>;
+ equals(message: BushMessage, rawData: unknown): boolean;
+ fetchReference(): Promise<BushMessage>;
+ crosspost(): Promise<BushMessage>;
fetch(force?: boolean): Promise<BushMessage>;
+ pin(): Promise<BushMessage>;
+ react(emoji: EmojiIdentifierResolvable): Promise<BushMessageReaction>;
+ removeAttachments(): Promise<BushMessage>;
+ reply(options: string | MessagePayload | ReplyMessageOptions): Promise<BushMessage>;
+ resolveComponent(customId: string): MessageActionRowComponent | null;
+ startThread(options: StartThreadOptions): Promise<BushThreadChannel>;
+ suppressEmbeds(suppress?: boolean): Promise<BushMessage>;
+ unpin(): Promise<BushMessage>;
+ inGuild(): this is BushMessage<true> & this;
}
diff --git a/src/lib/extensions/discord.js/other.ts b/src/lib/extensions/discord.js/other.ts
new file mode 100644
index 0000000..f81e01c
--- /dev/null
+++ b/src/lib/extensions/discord.js/other.ts
@@ -0,0 +1,159 @@
+import type {
+ BushApplicationCommand,
+ BushCategoryChannel,
+ BushDMChannel,
+ BushGuild,
+ BushGuildEmoji,
+ BushGuildMember,
+ BushMessage,
+ BushNewsChannel,
+ BushReactionEmoji,
+ BushRole,
+ BushStageChannel,
+ BushStoreChannel,
+ BushTextChannel,
+ BushThreadChannel,
+ BushThreadMember,
+ BushUser,
+ BushVoiceChannel
+} from '#lib';
+import type { Collection, EnumValueMapped, Message, PartialDMChannel, Snowflake } from 'discord.js';
+import type { ChannelTypes } from 'discord.js/typings/enums';
+
+/**
+ * Data that resolves to give a ThreadMember object.
+ */
+export type BushThreadMemberResolvable = BushThreadMember | BushUserResolvable;
+
+/**
+ * Data that resolves to give a User object.
+ */
+export type BushUserResolvable = BushUser | Snowflake | BushMessage | BushGuildMember | BushThreadMember;
+
+/**
+ * Data that resolves to give a GuildMember object.
+ */
+export type BushGuildMemberResolvable = BushGuildMember | BushUserResolvable;
+
+/**
+ * Data that can be resolved to a Role object.
+ */
+export type BushRoleResolvable = BushRole | Snowflake;
+
+/**
+ * Data that can be resolved to a Message object.
+ */
+export type BushMessageResolvable = Message | BushMessage | Snowflake;
+
+/**
+ * Data that can be resolved into a GuildEmoji object.
+ */
+export type BushEmojiResolvable = Snowflake | BushGuildEmoji | BushReactionEmoji;
+
+/**
+ * Data that can be resolved to give an emoji identifier. This can be:
+ * * The unicode representation of an emoji
+ * * The `<a:name:id>`, `<:name:id>`, `a:name:id` or `name:id` emoji identifier string of an emoji
+ * * An EmojiResolvable
+ */
+export type BushEmojiIdentifierResolvable = string | BushEmojiResolvable;
+
+/**
+ * Data that can be resolved to a Thread Channel object.
+ */
+export type BushThreadChannelResolvable = BushThreadChannel | Snowflake;
+
+/**
+ * Data that resolves to give an ApplicationCommand object.
+ */
+export type BushApplicationCommandResolvable = BushApplicationCommand | Snowflake;
+
+/**
+ * Data that can be resolved to a GuildTextChannel object.
+ */
+export type BushGuildTextChannelResolvable = BushTextChannel | BushNewsChannel | Snowflake;
+
+/**
+ * Data that can be resolved to give a Channel object.
+ */
+export type BushChannelResolvable = BushAnyChannel | Snowflake;
+
+/**
+ * Data that can be resolved to give a Guild Channel object.
+ */
+export type BushGuildChannelResolvable = Snowflake | BushGuildBasedChannel;
+
+export type BushAnyChannel =
+ | BushCategoryChannel
+ | BushDMChannel
+ | PartialDMChannel
+ | BushNewsChannel
+ | BushStageChannel
+ // eslint-disable-next-line deprecation/deprecation
+ | BushStoreChannel
+ | BushTextChannel
+ | BushThreadChannel
+ | BushVoiceChannel;
+
+/**
+ * The channels that are text-based.
+ */
+export type BushTextBasedChannel = PartialDMChannel | BushThreadChannel | BushDMChannel | BushNewsChannel | BushTextChannel;
+
+/**
+ * The types of channels that are text-based.
+ */
+export type BushTextBasedChannelTypes = BushTextBasedChannel['type'];
+
+export type BushVoiceBasedChannel = Extract<BushAnyChannel, { bitrate: number }>;
+
+export type BushGuildBasedChannel = Extract<BushAnyChannel, { guild: BushGuild }>;
+
+export type BushNonThreadGuildBasedChannel = Exclude<BushGuildBasedChannel, BushThreadChannel>;
+
+export type BushGuildTextBasedChannel = Extract<BushGuildBasedChannel, BushTextBasedChannel>;
+
+/**
+ * Data that can be resolved to a Text Channel object.
+ */
+export type BushTextChannelResolvable = Snowflake | BushTextChannel;
+
+/**
+ * Data that can be resolved to a GuildVoiceChannel object.
+ */
+export type BushGuildVoiceChannelResolvable = BushVoiceBasedChannel | Snowflake;
+
+export type BushMappedChannelCategoryTypes = EnumValueMapped<
+ typeof ChannelTypes,
+ {
+ GUILD_NEWS: BushNewsChannel;
+ GUILD_VOICE: BushVoiceChannel;
+ GUILD_TEXT: BushTextChannel;
+ // eslint-disable-next-line deprecation/deprecation
+ GUILD_STORE: BushStoreChannel;
+ GUILD_STAGE_VOICE: BushStageChannel;
+ }
+>;
+
+export type BushMappedGuildChannelTypes = EnumValueMapped<
+ typeof ChannelTypes,
+ {
+ GUILD_CATEGORY: BushCategoryChannel;
+ }
+> &
+ BushMappedChannelCategoryTypes;
+
+/**
+ * The data returned from a thread fetch that returns multiple threads.
+ */
+export interface BushFetchedThreads {
+ /**
+ * The threads that were fetched, with any members returned
+ */
+ threads: Collection<Snowflake, BushThreadChannel>;
+
+ /**
+ * Whether there are potentially additional threads that require a subsequent call
+ */
+ hasMore?: boolean;
+}