diff options
author | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2022-05-24 18:29:57 -0400 |
---|---|---|
committer | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2022-05-24 18:29:57 -0400 |
commit | 9f5d9da2a37ecfec412b149ec7dc385ab7b6a98c (patch) | |
tree | 4b95a06ff6991207ab8b8e93f0bca26e24a97f80 /src/lib/extensions/discord.js | |
parent | 6b8115ab1ec94d4330019fc7a93e094d9d64c48e (diff) | |
download | tanzanite-9f5d9da2a37ecfec412b149ec7dc385ab7b6a98c.tar.gz tanzanite-9f5d9da2a37ecfec412b149ec7dc385ab7b6a98c.tar.bz2 tanzanite-9f5d9da2a37ecfec412b149ec7dc385ab7b6a98c.zip |
fix: breaking changes
Diffstat (limited to 'src/lib/extensions/discord.js')
-rw-r--r-- | src/lib/extensions/discord.js/BushGuild.ts | 22 | ||||
-rw-r--r-- | src/lib/extensions/discord.js/BushGuildMember.ts | 52 | ||||
-rw-r--r-- | src/lib/extensions/discord.js/BushGuildMemberManager.ts | 8 | ||||
-rw-r--r-- | src/lib/extensions/discord.js/BushThreadManager.ts | 12 | ||||
-rw-r--r-- | src/lib/extensions/discord.js/BushThreadMemberManager.ts | 7 | ||||
-rw-r--r-- | src/lib/extensions/discord.js/other.ts | 17 |
6 files changed, 67 insertions, 51 deletions
diff --git a/src/lib/extensions/discord.js/BushGuild.ts b/src/lib/extensions/discord.js/BushGuild.ts index 8b1b5fa..80755bc 100644 --- a/src/lib/extensions/discord.js/BushGuild.ts +++ b/src/lib/extensions/discord.js/BushGuild.ts @@ -1,15 +1,15 @@ import { AllowedMentions, banResponse, + BushGuildChannelManager, + BushGuildMemberManager, BushMessage, dmResponse, permissionsResponse, punishmentEntryRemove, type BanResponse, type BushClient, - type BushGuildChannelManager, type BushGuildMember, - type BushGuildMemberManager, type BushGuildMemberResolvable, type BushNewsChannel, type BushTextChannel, @@ -151,7 +151,7 @@ export class BushGuild extends Guild { if (!logChannel || !logChannel.isTextBased()) return; if ( !logChannel - .permissionsFor(this.me!.id) + .permissionsFor(this.members.me!.id) ?.has([PermissionFlagsBits.ViewChannel, PermissionFlagsBits.SendMessages, PermissionFlagsBits.EmbedLinks]) ) return; @@ -176,7 +176,7 @@ export class BushGuild extends Guild { */ public async bushBan(options: GuildBushBanOptions): Promise<BanResponse> { // checks - if (!this.me!.permissions.has(PermissionFlagsBits.BanMembers)) return banResponse.MISSING_PERMISSIONS; + if (!this.members.me!.permissions.has(PermissionFlagsBits.BanMembers)) return banResponse.MISSING_PERMISSIONS; let caseID: string | undefined = undefined; let dmSuccessEvent: boolean | undefined = undefined; @@ -319,7 +319,7 @@ export class BushGuild extends Guild { */ public async bushUnban(options: GuildBushUnbanOptions): Promise<UnbanResponse> { // checks - if (!this.me!.permissions.has(PermissionFlagsBits.BanMembers)) return unbanResponse.MISSING_PERMISSIONS; + if (!this.members.me!.permissions.has(PermissionFlagsBits.BanMembers)) return unbanResponse.MISSING_PERMISSIONS; let caseID: string | undefined = undefined; let dmSuccessEvent: boolean | undefined = undefined; @@ -413,7 +413,7 @@ export class BushGuild extends Guild { success.set(channel.id, false); continue; } - if (!channel.permissionsFor(this.me!.id)?.has([PermissionFlagsBits.ManageChannels])) { + if (!channel.permissionsFor(this.members.me!.id)?.has([PermissionFlagsBits.ManageChannels])) { errors.set(channel.id, new Error('client no permission')); success.set(channel.id, false); continue; @@ -442,7 +442,7 @@ export class BushGuild extends Guild { success.set(channel.id, false); } else { success.set(channel.id, true); - await permissionOverwrites.edit(this.me!, permsForMe, { reason }); + await permissionOverwrites.edit(this.members.me!, permsForMe, { reason }); await channel.send({ embeds: [ { @@ -466,8 +466,8 @@ export class BushGuild extends Guild { } public async quote(rawQuote: APIMessage, channel: BushTextChannel | BushNewsChannel | BushThreadChannel) { - if (!channel.isTextBased() || channel.isDMBased() || channel.guildId !== this.id || !this.me) return null; - if (!channel.permissionsFor(this.me).has('ManageWebhooks')) return null; + if (!channel.isTextBased() || channel.isDMBased() || channel.guildId !== this.id || !this.members.me) return null; + if (!channel.permissionsFor(this.members.me).has('ManageWebhooks')) return null; const quote = new BushMessage(client, rawQuote); @@ -643,10 +643,6 @@ export class BushGuild extends Guild { } } -export interface BushGuild extends Guild { - get me(): BushGuildMember | null; -} - /** * Options for unbanning a user */ diff --git a/src/lib/extensions/discord.js/BushGuildMember.ts b/src/lib/extensions/discord.js/BushGuildMember.ts index 5d7144b..5e9e150 100644 --- a/src/lib/extensions/discord.js/BushGuildMember.ts +++ b/src/lib/extensions/discord.js/BushGuildMember.ts @@ -65,7 +65,7 @@ export class BushGuildMember extends GuildMember { public async bushWarn(options: BushPunishmentOptions): Promise<{ result: WarnResponse; caseNum: number | null }> { let caseID: string | undefined = undefined; let dmSuccessEvent: boolean | undefined = undefined; - const moderator = await util.resolveNonCachedUser(options.moderator ?? this.guild.me); + const moderator = await util.resolveNonCachedUser(options.moderator ?? this.guild.members.me); if (!moderator) return { result: warnResponse.CANNOT_RESOLVE_USER, caseNum: null }; const ret = await (async (): Promise<{ result: WarnResponse; caseNum: number | null }> => { @@ -107,12 +107,12 @@ export class BushGuildMember extends GuildMember { */ public async bushAddRole(options: AddRoleOptions): Promise<AddRoleResponse> { // checks - if (!this.guild.me!.permissions.has(PermissionFlagsBits.ManageRoles)) return addRoleResponse.MISSING_PERMISSIONS; + if (!this.guild.members.me!.permissions.has(PermissionFlagsBits.ManageRoles)) return addRoleResponse.MISSING_PERMISSIONS; const ifShouldAddRole = this.#checkIfShouldAddRole(options.role, options.moderator); if (ifShouldAddRole !== true) return ifShouldAddRole; let caseID: string | undefined = undefined; - const moderator = await util.resolveNonCachedUser(options.moderator ?? this.guild.me); + const moderator = await util.resolveNonCachedUser(options.moderator ?? this.guild.members.me); if (!moderator) return addRoleResponse.CANNOT_RESOLVE_USER; const ret = await (async () => { @@ -178,12 +178,12 @@ export class BushGuildMember extends GuildMember { */ public async bushRemoveRole(options: RemoveRoleOptions): Promise<RemoveRoleResponse> { // checks - if (!this.guild.me!.permissions.has(PermissionFlagsBits.ManageRoles)) return removeRoleResponse.MISSING_PERMISSIONS; + if (!this.guild.members.me!.permissions.has(PermissionFlagsBits.ManageRoles)) return removeRoleResponse.MISSING_PERMISSIONS; const ifShouldAddRole = this.#checkIfShouldAddRole(options.role, options.moderator); if (ifShouldAddRole !== true) return ifShouldAddRole; let caseID: string | undefined = undefined; - const moderator = await util.resolveNonCachedUser(options.moderator ?? this.guild.me); + const moderator = await util.resolveNonCachedUser(options.moderator ?? this.guild.members.me); if (!moderator) return removeRoleResponse.CANNOT_RESOLVE_USER; const ret = await (async () => { @@ -255,7 +255,7 @@ export class BushGuildMember extends GuildMember { return shouldAddRoleResponse.USER_HIERARCHY; } else if (role.managed) { return shouldAddRoleResponse.ROLE_MANAGED; - } else if (this.guild.me!.roles.highest.position <= role.position) { + } else if (this.guild.members.me!.roles.highest.position <= role.position) { return shouldAddRoleResponse.CLIENT_HIERARCHY; } return true; @@ -269,17 +269,17 @@ export class BushGuildMember extends GuildMember { */ public async bushMute(options: BushTimedPunishmentOptions): Promise<MuteResponse> { // checks - if (!this.guild.me!.permissions.has(PermissionFlagsBits.ManageRoles)) return muteResponse.MISSING_PERMISSIONS; + if (!this.guild.members.me!.permissions.has(PermissionFlagsBits.ManageRoles)) return muteResponse.MISSING_PERMISSIONS; const muteRoleID = await this.guild.getSetting('muteRole'); if (!muteRoleID) return muteResponse.NO_MUTE_ROLE; const muteRole = this.guild.roles.cache.get(muteRoleID); if (!muteRole) return muteResponse.MUTE_ROLE_INVALID; - if (muteRole.position >= this.guild.me!.roles.highest.position || muteRole.managed) + if (muteRole.position >= this.guild.members.me!.roles.highest.position || muteRole.managed) return muteResponse.MUTE_ROLE_NOT_MANAGEABLE; let caseID: string | undefined = undefined; let dmSuccessEvent: boolean | undefined = undefined; - const moderator = await util.resolveNonCachedUser(options.moderator ?? this.guild.me); + const moderator = await util.resolveNonCachedUser(options.moderator ?? this.guild.members.me); if (!moderator) return muteResponse.CANNOT_RESOLVE_USER; const ret = await (async () => { @@ -355,17 +355,17 @@ export class BushGuildMember extends GuildMember { */ public async bushUnmute(options: BushPunishmentOptions): Promise<UnmuteResponse> { // checks - if (!this.guild.me!.permissions.has(PermissionFlagsBits.ManageRoles)) return unmuteResponse.MISSING_PERMISSIONS; + if (!this.guild.members.me!.permissions.has(PermissionFlagsBits.ManageRoles)) return unmuteResponse.MISSING_PERMISSIONS; const muteRoleID = await this.guild.getSetting('muteRole'); if (!muteRoleID) return unmuteResponse.NO_MUTE_ROLE; const muteRole = this.guild.roles.cache.get(muteRoleID); if (!muteRole) return unmuteResponse.MUTE_ROLE_INVALID; - if (muteRole.position >= this.guild.me!.roles.highest.position || muteRole.managed) + if (muteRole.position >= this.guild.members.me!.roles.highest.position || muteRole.managed) return unmuteResponse.MUTE_ROLE_NOT_MANAGEABLE; let caseID: string | undefined = undefined; let dmSuccessEvent: boolean | undefined = undefined; - const moderator = await util.resolveNonCachedUser(options.moderator ?? this.guild.me); + const moderator = await util.resolveNonCachedUser(options.moderator ?? this.guild.members.me); if (!moderator) return unmuteResponse.CANNOT_RESOLVE_USER; const ret = await (async () => { @@ -438,12 +438,12 @@ export class BushGuildMember extends GuildMember { */ public async bushKick(options: BushPunishmentOptions): Promise<KickResponse> { // checks - if (!this.guild.me?.permissions.has(PermissionFlagsBits.KickMembers) || !this.kickable) + if (!this.guild.members.me?.permissions.has(PermissionFlagsBits.KickMembers) || !this.kickable) return kickResponse.MISSING_PERMISSIONS; let caseID: string | undefined = undefined; let dmSuccessEvent: boolean | undefined = undefined; - const moderator = await util.resolveNonCachedUser(options.moderator ?? this.guild.me); + const moderator = await util.resolveNonCachedUser(options.moderator ?? this.guild.members.me); if (!moderator) return kickResponse.CANNOT_RESOLVE_USER; const ret = await (async () => { // add modlog entry @@ -492,17 +492,18 @@ export class BushGuildMember extends GuildMember { */ public async bushBan(options: BushBanOptions): Promise<Exclude<BanResponse, typeof banResponse['ALREADY_BANNED']>> { // checks - if (!this.guild.me!.permissions.has(PermissionFlagsBits.BanMembers) || !this.bannable) return banResponse.MISSING_PERMISSIONS; + if (!this.guild.members.me!.permissions.has(PermissionFlagsBits.BanMembers) || !this.bannable) + return banResponse.MISSING_PERMISSIONS; let caseID: string | undefined = undefined; let dmSuccessEvent: boolean | undefined = undefined; - const moderator = await util.resolveNonCachedUser(options.moderator ?? this.guild.me); + const moderator = await util.resolveNonCachedUser(options.moderator ?? this.guild.members.me); if (!moderator) return banResponse.CANNOT_RESOLVE_USER; // ignore result, they should still be banned even if their mute cannot be removed await this.bushUnmute({ reason: 'User is about to be banned, a mute is no longer necessary.', - moderator: this.guild.me!, + moderator: this.guild.members.me!, silent: true }); @@ -574,12 +575,12 @@ export class BushGuildMember extends GuildMember { if (!channel || (!channel.isTextBased() && !channel.isThread())) return blockResponse.INVALID_CHANNEL; // checks - if (!channel.permissionsFor(this.guild.me!)!.has(PermissionFlagsBits.ManageChannels)) + if (!channel.permissionsFor(this.guild.members.me!)!.has(PermissionFlagsBits.ManageChannels)) return blockResponse.MISSING_PERMISSIONS; let caseID: string | undefined = undefined; let dmSuccessEvent: boolean | undefined = undefined; - const moderator = await util.resolveNonCachedUser(options.moderator ?? this.guild.me); + const moderator = await util.resolveNonCachedUser(options.moderator ?? this.guild.members.me); if (!moderator) return blockResponse.CANNOT_RESOLVE_USER; const ret = await (async () => { @@ -665,12 +666,12 @@ export class BushGuildMember extends GuildMember { const channel = _channel as BushGuildTextBasedChannel; // checks - if (!channel.permissionsFor(this.guild.me!)!.has(PermissionFlagsBits.ManageChannels)) + if (!channel.permissionsFor(this.guild.members.me!)!.has(PermissionFlagsBits.ManageChannels)) return unblockResponse.MISSING_PERMISSIONS; let caseID: string | undefined = undefined; let dmSuccessEvent: boolean | undefined = undefined; - const moderator = await util.resolveNonCachedUser(options.moderator ?? this.guild.me); + const moderator = await util.resolveNonCachedUser(options.moderator ?? this.guild.members.me); if (!moderator) return unblockResponse.CANNOT_RESOLVE_USER; const ret = await (async () => { @@ -748,14 +749,14 @@ export class BushGuildMember extends GuildMember { */ public async bushTimeout(options: BushTimeoutOptions): Promise<TimeoutResponse> { // checks - if (!this.guild.me!.permissions.has(PermissionFlagsBits.ModerateMembers)) return timeoutResponse.MISSING_PERMISSIONS; + if (!this.guild.members.me!.permissions.has(PermissionFlagsBits.ModerateMembers)) return timeoutResponse.MISSING_PERMISSIONS; const twentyEightDays = Time.Day * 28; if (options.duration > twentyEightDays) return timeoutResponse.INVALID_DURATION; let caseID: string | undefined = undefined; let dmSuccessEvent: boolean | undefined = undefined; - const moderator = await util.resolveNonCachedUser(options.moderator ?? this.guild.me); + const moderator = await util.resolveNonCachedUser(options.moderator ?? this.guild.members.me); if (!moderator) return timeoutResponse.CANNOT_RESOLVE_USER; const ret = await (async () => { @@ -812,11 +813,12 @@ export class BushGuildMember extends GuildMember { */ public async bushRemoveTimeout(options: BushPunishmentOptions): Promise<RemoveTimeoutResponse> { // checks - if (!this.guild.me!.permissions.has(PermissionFlagsBits.ModerateMembers)) return removeTimeoutResponse.MISSING_PERMISSIONS; + if (!this.guild.members.me!.permissions.has(PermissionFlagsBits.ModerateMembers)) + return removeTimeoutResponse.MISSING_PERMISSIONS; let caseID: string | undefined = undefined; let dmSuccessEvent: boolean | undefined = undefined; - const moderator = await util.resolveNonCachedUser(options.moderator ?? this.guild.me); + const moderator = await util.resolveNonCachedUser(options.moderator ?? this.guild.members.me); if (!moderator) return removeTimeoutResponse.CANNOT_RESOLVE_USER; const ret = await (async () => { diff --git a/src/lib/extensions/discord.js/BushGuildMemberManager.ts b/src/lib/extensions/discord.js/BushGuildMemberManager.ts index 3f8dcd2..b0368b5 100644 --- a/src/lib/extensions/discord.js/BushGuildMemberManager.ts +++ b/src/lib/extensions/discord.js/BushGuildMemberManager.ts @@ -52,7 +52,7 @@ export declare class BushGuildMemberManager * @example * // Ban a user by id (or with a user/guild member object) * guild.members.ban('84484653687267328') - * .then(kickInfo => console.log(`Banned ${kickInfo.user?.tag ?? kickInfo.tag ?? kickInfo}`)) + * .then(banInfo => console.log(`Banned ${banInfo.user?.tag ?? banInfo.tag ?? banInfo}`)) * .catch(console.error); */ public ban(user: BushUserResolvable, options?: BanOptions): Promise<BushGuildMember | BushUser | Snowflake>; @@ -169,5 +169,9 @@ export declare class BushGuildMemberManager * .then(user => console.log(`Unbanned ${user.username} from ${guild.name}`)) * .catch(console.error); */ - public unban(user: BushUserResolvable, reason?: string): Promise<BushUser>; + public unban(user: BushUserResolvable, reason?: string): Promise<BushUser | null>; +} + +export interface BushGuildMemberManager extends CachedManager<Snowflake, BushGuildMember, BushGuildMemberResolvable> { + get me(): BushGuildMember | null; } diff --git a/src/lib/extensions/discord.js/BushThreadManager.ts b/src/lib/extensions/discord.js/BushThreadManager.ts index b84b98d..0748a4d 100644 --- a/src/lib/extensions/discord.js/BushThreadManager.ts +++ b/src/lib/extensions/discord.js/BushThreadManager.ts @@ -1,10 +1,8 @@ -import type { BushThreadChannel } from '#lib'; +import type { BushFetchedThreads, BushThreadChannel } from '#lib'; import { CachedManager, - FetchedThreads, NewsChannel, TextChannel, - ThreadChannel, ThreadManager, type BaseFetchOptions, type FetchArchivedThreadOptions, @@ -54,7 +52,7 @@ export declare class BushThreadManager<AllowedThreadType> * .then(threadChannel => console.log(threadChannel)) * .catch(console.error); */ - public create(options: ThreadCreateOptions<AllowedThreadType>): Promise<ThreadChannel>; + public create(options: ThreadCreateOptions<AllowedThreadType>): Promise<BushThreadChannel>; /** * Obtains a thread from Discord, or the channel cache if it's already available. @@ -69,18 +67,18 @@ export declare class BushThreadManager<AllowedThreadType> * .catch(console.error); */ public fetch(options: ThreadChannelResolvable, cacheOptions?: BaseFetchOptions): Promise<BushThreadChannel | null>; - public fetch(options?: FetchThreadsOptions, cacheOptions?: { cache?: boolean }): Promise<FetchedThreads>; + public fetch(options?: FetchThreadsOptions, cacheOptions?: { cache?: boolean }): Promise<BushFetchedThreads>; /** * Obtains a set of archived threads from Discord, requires `READ_MESSAGE_HISTORY` in the parent channel. * @param options The options to fetch archived threads * @param cache Whether to cache the new thread objects if they aren't already */ - public fetchArchived(options?: FetchArchivedThreadOptions, cache?: boolean): Promise<FetchedThreads>; + public fetchArchived(options?: FetchArchivedThreadOptions, cache?: boolean): Promise<BushFetchedThreads>; /** * Obtains the accessible active threads from Discord, requires `READ_MESSAGE_HISTORY` in the parent channel. * @param cache Whether to cache the new thread objects if they aren't already */ - public fetchActive(cache?: boolean): Promise<FetchedThreads>; + public fetchActive(cache?: boolean): Promise<BushFetchedThreads>; } diff --git a/src/lib/extensions/discord.js/BushThreadMemberManager.ts b/src/lib/extensions/discord.js/BushThreadMemberManager.ts index 48e968f..d183b30 100644 --- a/src/lib/extensions/discord.js/BushThreadMemberManager.ts +++ b/src/lib/extensions/discord.js/BushThreadMemberManager.ts @@ -47,6 +47,13 @@ export declare class BushThreadMemberManager public remove(id: Snowflake | '@me', reason?: string): Promise<Snowflake>; } +export interface BushThreadMemberManager extends CachedManager<Snowflake, BushThreadMember, BushThreadMemberResolvable> { + /** + * The client user as a ThreadMember of this ThreadChannel + */ + get me(): BushThreadMember | null; +} + export interface BushThreadMemberFetchOptions extends BaseFetchOptions { /** * The specific user to fetch from the thread diff --git a/src/lib/extensions/discord.js/other.ts b/src/lib/extensions/discord.js/other.ts index 086ace0..aeba01c 100644 --- a/src/lib/extensions/discord.js/other.ts +++ b/src/lib/extensions/discord.js/other.ts @@ -27,10 +27,12 @@ import type { Collection, EmojiIdentifierResolvable, EmojiResolvable, + FetchedThreads, GuildChannelResolvable, GuildMemberResolvable, GuildTextChannelResolvable, MessageResolvable, + PartialGroupDMChannel, RoleResolvable, Snowflake, ThreadChannelResolvable, @@ -105,6 +107,7 @@ export type BushAnyChannel = | BushCategoryChannel | BushDMChannel | PartialBushDMChannel + | PartialGroupDMChannel | BushNewsChannel | BushStageChannel | BushTextChannel @@ -114,7 +117,13 @@ export type BushAnyChannel = /** * The channels that are text-based. */ -export type BushTextBasedChannel = PartialBushDMChannel | BushThreadChannel | BushDMChannel | BushNewsChannel | BushTextChannel; +export type BushTextBasedChannel = + | BushDMChannel + | PartialBushDMChannel + | BushNewsChannel + | BushTextChannel + | BushThreadChannel + | BushVoiceChannel; /** * The types of channels that are text-based. @@ -125,6 +134,8 @@ export type BushVoiceBasedChannel = Extract<BushAnyChannel, { bitrate: number }> export type BushGuildBasedChannel = Extract<BushAnyChannel, { guild: BushGuild }>; +export type BushNonCategoryGuildBasedChannel = Exclude<BushGuildBasedChannel, BushCategoryChannel>; + export type BushNonThreadGuildBasedChannel = Exclude<BushGuildBasedChannel, BushThreadChannel>; export type BushGuildTextBasedChannel = Extract<BushGuildBasedChannel, BushTextBasedChannel>; @@ -154,7 +165,7 @@ export type BushMappedGuildChannelTypes = { /** * The data returned from a thread fetch that returns multiple threads. */ -export interface BushFetchedThreads { +export interface BushFetchedThreads extends FetchedThreads { /** * The threads that were fetched, with any members returned */ @@ -166,8 +177,6 @@ export interface BushFetchedThreads { hasMore?: boolean; } -export type BushNonCategoryGuildBasedChannel = Exclude<BushGuildBasedChannel, BushCategoryChannel>; - export type BushGuildCacheMessage<Cached extends CacheType> = CacheTypeReducer< Cached, BushMessage<true>, |