diff options
Diffstat (limited to 'src/lib')
20 files changed, 154 insertions, 142 deletions
diff --git a/src/lib/common/AutoMod.ts b/src/lib/common/AutoMod.ts index c57d581..8d94dab 100644 --- a/src/lib/common/AutoMod.ts +++ b/src/lib/common/AutoMod.ts @@ -6,7 +6,7 @@ import { ChannelType, Embed, GuildMember, - Permissions, + PermissionFlagsBits, type TextChannel } from 'discord.js'; @@ -120,7 +120,7 @@ export class AutoMod { if (!includes('@everyone') && !includes('@here')) return; // It would be bad if we deleted a message that actually pinged @everyone or @here if ( - this.message.member?.permissionsIn(this.message.channelId).has(Permissions.FLAGS.MENTION_EVERYONE) || + this.message.member?.permissionsIn(this.message.channelId).has(PermissionFlagsBits.MentionEveryone) || this.message.mentions.everyone ) return; @@ -291,7 +291,7 @@ export class AutoMod { * @param interaction The button interaction. */ public static async handleInteraction(interaction: BushButtonInteraction) { - if (!interaction.memberPermissions?.has(Permissions.FLAGS.BAN_MEMBERS)) + if (!interaction.memberPermissions?.has(PermissionFlagsBits.BanMembers)) return interaction.reply({ content: `${util.emojis.error} You are missing the **Ban Members** permission.`, ephemeral: true diff --git a/src/lib/common/util/Moderation.ts b/src/lib/common/util/Moderation.ts index 62dbc90..0ba6fca 100644 --- a/src/lib/common/util/Moderation.ts +++ b/src/lib/common/util/Moderation.ts @@ -10,7 +10,7 @@ import { type BushUserResolvable, type ModLogType } from '#lib'; -import { Embed, Permissions, type Snowflake } from 'discord.js'; +import { Embed, PermissionFlagsBits, type Snowflake } from 'discord.js'; /** * A utility class with moderation-related methods. @@ -72,7 +72,7 @@ export class Moderation { } if ( checkModerator && - victim.permissions.has(Permissions.FLAGS.MANAGE_MESSAGES) && + victim.permissions.has(PermissionFlagsBits.ManageMessages) && !(type.startsWith('un') && moderator.id === victim.id) ) { if (await moderator.guild.hasFeature('modsCanPunishMods')) { diff --git a/src/lib/extensions/discord-akairo/BushClient.ts b/src/lib/extensions/discord-akairo/BushClient.ts index 712d610..ce72ee2 100644 --- a/src/lib/extensions/discord-akairo/BushClient.ts +++ b/src/lib/extensions/discord-akairo/BushClient.ts @@ -25,8 +25,8 @@ import * as Sentry from '@sentry/node'; import { AkairoClient, ContextMenuCommandHandler, version as akairoVersion } from 'discord-akairo'; import { ActivityType, - Intents, Options, + Partials, Structures, version as discordJsVersion, type Awaitable, @@ -189,21 +189,18 @@ export class BushClient<Ready extends boolean = boolean> extends AkairoClient<Re public constructor(config: Config) { super({ ownerID: config.owners, - intents: Object.values(Intents.FLAGS).reduce((acc, p) => acc | p, 0), - partials: ['USER', 'CHANNEL', 'GUILD_MEMBER', 'MESSAGE', 'REACTION', 'GUILD_SCHEDULED_EVENT'], + intents: Object.keys(GatewayIntentBits) + .map((i) => (typeof i === 'string' ? GatewayIntentBits[i as keyof typeof GatewayIntentBits] : i)) + .reduce((acc, p) => acc | p, 0), + partials: Object.keys(Partials).map((p) => Partials[p as keyof typeof Partials]), presence: { - activities: [ - { - name: 'Beep Boop', - type: ActivityType.Watching - } - ], + activities: [{ name: 'Beep Boop', type: ActivityType.Watching }], status: 'online' }, - http: { api: 'https://canary.discord.com/api' }, allowedMentions: AllowedMentions.users(), // No everyone or role mentions by default makeCache: Options.cacheWithLimits({}), - failIfNotExists: false + failIfNotExists: false, + rest: { api: 'https://canary.discord.com/api' } }); patch(this); @@ -211,7 +208,7 @@ export class BushClient<Ready extends boolean = boolean> extends AkairoClient<Re this.config = config; this.util = new BushClientUtil(this); - /* handlers */ + /* =-=-= handlers =-=-= */ this.listenerHandler = new BushListenerHandler(this, { directory: path.join(__dirname, '..', '..', '..', 'listeners'), automateCategories: true @@ -238,12 +235,12 @@ export class BushClient<Ready extends boolean = boolean> extends AkairoClient<Re commandUtilLifetime: 300_000, // 5 minutes argumentDefaults: { prompt: { - start: 'Placeholder argument prompt. If you see this please tell my developers.', - retry: 'Placeholder failed argument prompt. If you see this please tell my developers.', + start: 'Placeholder argument prompt. **If you see this please tell my developers**.', + retry: 'Placeholder failed argument prompt. **If you see this please tell my developers**.', modifyStart: (_: Message, str: string): string => `${str}\n\n Type \`cancel\` to cancel the command`, modifyRetry: (_: Message, str: string): string => `${str.replace('{error}', this.util.emojis.error)}\n\n Type \`cancel\` to cancel the command`, - timeout: 'You took too long the command has been cancelled', + timeout: ':hourglass: You took too long the command has been cancelled.', ended: 'You exceeded the maximum amount of tries the command has been cancelled', cancel: 'The command has been cancelled', retries: 3, @@ -262,7 +259,7 @@ export class BushClient<Ready extends boolean = boolean> extends AkairoClient<Re automateCategories: true }); - /* databases */ + /* =-=-= databases =-=-= */ const sharedDBOptions: SequelizeOptions = { username: this.config.db.username, password: this.config.db.password, @@ -281,8 +278,7 @@ export class BushClient<Ready extends boolean = boolean> extends AkairoClient<Re database: 'bushbot-shared' }); - // eslint-disable-next-line @typescript-eslint/no-unused-vars - /* global objects */ + /* =-=-= global objects =-=-= */ global.client = this; global.util = this.util; } @@ -351,7 +347,8 @@ export class BushClient<Ready extends boolean = boolean> extends AkairoClient<Re contextMenuCommandHandler: this.contextMenuCommandHandler, process, stdin: rl, - gateway: this.ws + gateway: this.ws, + rest: this.rest }); this.commandHandler.resolver.addTypes({ duration, @@ -515,3 +512,23 @@ export interface BushStats { */ commandsUsed: bigint; } + +// exported as const enum from discord-api-types +enum GatewayIntentBits { + Guilds = 1, + GuildMembers = 2, + GuildBans = 4, + GuildEmojisAndStickers = 8, + GuildIntegrations = 16, + GuildWebhooks = 32, + GuildInvites = 64, + GuildVoiceStates = 128, + GuildPresences = 256, + GuildMessages = 512, + GuildMessageReactions = 1024, + GuildMessageTyping = 2048, + DirectMessages = 4096, + DirectMessageReactions = 8192, + DirectMessageTyping = 16384, + GuildScheduledEvents = 65536 +} diff --git a/src/lib/extensions/discord-akairo/BushClientUtil.ts b/src/lib/extensions/discord-akairo/BushClientUtil.ts index e3c0803..7a4d5b0 100644 --- a/src/lib/extensions/discord-akairo/BushClientUtil.ts +++ b/src/lib/extensions/discord-akairo/BushClientUtil.ts @@ -20,12 +20,13 @@ import { humanizeDuration } from '@notenoughupdates/humanize-duration'; import { exec } from 'child_process'; import deepLock from 'deep-lock'; import { ClientUtil, Util as AkairoUtil } from 'discord-akairo'; -import type { APIMessage } from 'discord-api-types'; +import { APIMessage } from 'discord-api-types'; import { Constants as DiscordConstants, GuildMember, Message, - Permissions, + PermissionFlagsBits, + PermissionsBitField, ThreadMember, User, Util as DiscordUtil, @@ -404,8 +405,8 @@ export class BushClientUtil extends ClientUtil { * @returns The combined elements or `ifEmpty`. * * @example - * const permissions = oxford([Permissions.FLAGS.ADMINISTRATOR, Permissions.FLAGS.SEND_MESSAGES, Permissions.FLAGS.MANAGE_MESSAGES], 'and', 'none'); - * console.log(permissions); // ADMINISTRATOR, SEND_MESSAGES and MANAGE_MESSAGES + * const permissions = oxford([PermissionFlagsBits.Administrator, PermissionFlagsBits.SendMessages, PermissionFlagsBits.ManageMessages], 'and', 'none'); + * console.log(permissions); // Administrator, SendMessages and ManageMessages */ public oxford(array: string[], conjunction: string, ifEmpty?: string): string | undefined { const l = array.length; @@ -767,7 +768,7 @@ export class BushClientUtil extends ClientUtil { public userGuildPermCheck(message: BushMessage | BushSlashMessage, permissions: bigint[]) { const missing = message.member?.permissions.missing(permissions) ?? []; - return missing.length ? missing.map((p) => Permissions.FLAGS[p]) : null; + return missing.length ? missing.map((p) => PermissionFlagsBits[p]) : null; } /** @@ -779,7 +780,7 @@ export class BushClientUtil extends ClientUtil { public clientGuildPermCheck(message: BushMessage | BushSlashMessage, permissions: bigint[]) { const missing = message.guild?.me?.permissions.missing(permissions) ?? []; - return missing.length ? missing.map((p) => Permissions.FLAGS[p]) : null; + return missing.length ? missing.map((p) => PermissionFlagsBits[p]) : null; } /** @@ -792,7 +793,7 @@ export class BushClientUtil extends ClientUtil { */ public clientSendAndPermCheck(message: BushMessage | BushSlashMessage, permissions: bigint[] = [], checkChannel = false) { const missing = []; - const sendPerm = message.channel!.isThread() ? Permissions.FLAGS.SEND_MESSAGES : Permissions.FLAGS.SEND_MESSAGES_IN_THREADS; + const sendPerm = message.channel!.isThread() ? PermissionFlagsBits.SendMessages : PermissionFlagsBits.SendMessagesInThreads; if (!message.inGuild()) return null; if (!message.guild.me!.permissionsIn(message.channel.id).has(sendPerm)) missing.push(sendPerm); @@ -802,7 +803,7 @@ export class BushClientUtil extends ClientUtil { ? message .guild!.me!.permissionsIn(message.channel!.id!) .missing(permissions) - .map((p) => Permissions.FLAGS[p]) + .map((p) => PermissionFlagsBits[p]) : this.clientGuildPermCheck(message, permissions) ?? []) ); @@ -875,7 +876,7 @@ export class BushClientUtil extends ClientUtil { return `https://discord.com/api/oauth2/authorize?client_id=${Buffer.from( client.token!.split('.')[0], 'base64' - ).toString()}&permissions=${Permissions.ALL}&scope=bot%20applications.commands`; + ).toString()}&permissions=${PermissionsBitField.All}&scope=bot%20applications.commands`; } /** diff --git a/src/lib/extensions/discord-akairo/BushCommand.ts b/src/lib/extensions/discord-akairo/BushCommand.ts index 0456b80..650b538 100644 --- a/src/lib/extensions/discord-akairo/BushCommand.ts +++ b/src/lib/extensions/discord-akairo/BushCommand.ts @@ -51,7 +51,7 @@ import { type Collection, type Invite, type PermissionResolvable, - type PermissionString, + type PermissionsString, type Snowflake } from 'discord.js'; @@ -106,7 +106,7 @@ export interface OverriddenBaseArgumentType extends BaseArgumentType { export interface BaseBushArgumentType extends OverriddenBaseArgumentType { duration: number | null; contentWithDuration: ParsedDuration; - permission: PermissionString | null; + permission: PermissionsString | null; snowflake: Snowflake | null; discordEmoji: DiscordEmojiInfo | null; roleWithDuration: RoleWithDuration | null; diff --git a/src/lib/extensions/discord-akairo/BushCommandHandler.ts b/src/lib/extensions/discord-akairo/BushCommandHandler.ts index 6c06c5b..2c1903f 100644 --- a/src/lib/extensions/discord-akairo/BushCommandHandler.ts +++ b/src/lib/extensions/discord-akairo/BushCommandHandler.ts @@ -1,6 +1,6 @@ import { type BushClient, type BushCommand, type BushMessage, type BushSlashMessage } from '#lib'; import { CommandHandler, type Category, type CommandHandlerEvents, type CommandHandlerOptions } from 'discord-akairo'; -import { type Collection, type PermissionString } from 'discord.js'; +import { type Collection, type PermissionsString } from 'discord.js'; export type BushCommandHandlerOptions = CommandHandlerOptions; @@ -18,7 +18,7 @@ export interface BushCommandHandlerEvents extends CommandHandlerEvents { load: [command: BushCommand, isReload: boolean]; messageBlocked: [message: BushMessage | BushSlashMessage, reason: string]; messageInvalid: [message: BushMessage]; - missingPermissions: [message: BushMessage, command: BushCommand, type: 'client' | 'user', missing: Array<PermissionString>]; + missingPermissions: [message: BushMessage, command: BushCommand, type: 'client' | 'user', missing: PermissionsString[]]; remove: [command: BushCommand]; slashBlocked: [message: BushSlashMessage, command: BushCommand, reason: string]; slashError: [error: Error, message: BushSlashMessage, command: BushCommand]; @@ -27,7 +27,7 @@ export interface BushCommandHandlerEvents extends CommandHandlerEvents { message: BushSlashMessage, command: BushCommand, type: 'client' | 'user', - missing: Array<PermissionString> + missing: PermissionsString[] ]; slashStarted: [message: BushSlashMessage, command: BushCommand, args: any]; } diff --git a/src/lib/extensions/discord.js/BushChannel.ts b/src/lib/extensions/discord.js/BushChannel.ts index 50ec723..8779342 100644 --- a/src/lib/extensions/discord.js/BushChannel.ts +++ b/src/lib/extensions/discord.js/BushChannel.ts @@ -12,7 +12,7 @@ import type { BushVoiceBasedChannel, BushVoiceChannel } from '#lib'; -import { Channel, ChannelType, type Snowflake } from 'discord.js'; +import { Channel, ChannelType, PartialGroupDMChannel, type Snowflake } from 'discord.js'; import type { RawChannelData } from 'discord.js/typings/rawDataTypes'; /** @@ -20,8 +20,8 @@ import type { RawChannelData } from 'discord.js/typings/rawDataTypes'; */ export declare class BushChannel extends Channel { public constructor(client: BushClient, data?: RawChannelData, immediatePatch?: boolean); - public readonly createdAt: Date; - public readonly createdTimestamp: number; + public readonly createdAt: Date | null; + public readonly createdTimestamp: number | null; public deleted: boolean; public id: Snowflake; public readonly partial: false; @@ -30,6 +30,7 @@ export declare class BushChannel extends Channel { public fetch(force?: boolean): Promise<this>; public isText(): this is BushTextChannel; public isDM(): this is BushDMChannel; + public isDMBased(): this is PartialGroupDMChannel | BushDMChannel; public isVoice(): this is BushVoiceChannel; public isCategory(): this is BushCategoryChannel; public isNews(): this is BushNewsChannel; diff --git a/src/lib/extensions/discord.js/BushClientEvents.ts b/src/lib/extensions/discord.js/BushClientEvents.ts index 02f0017..fe60964 100644 --- a/src/lib/extensions/discord.js/BushClientEvents.ts +++ b/src/lib/extensions/discord.js/BushClientEvents.ts @@ -28,17 +28,7 @@ import type { PartialBushUser } from '#lib'; import type { AkairoClientEvents } from 'discord-akairo'; -import type { - Collection, - GuildScheduledEvent, - Interaction, - InvalidRequestWarningData, - Invite, - RateLimitData, - Snowflake, - Sticker, - Typing -} from 'discord.js'; +import type { Collection, GuildScheduledEvent, Interaction, Invite, Snowflake, Sticker, Typing } from 'discord.js'; export interface BushClientEvents extends AkairoClientEvents { applicationCommandCreate: [command: BushApplicationCommand]; @@ -88,8 +78,6 @@ export interface BushClientEvents extends AkairoClientEvents { messageReactionRemove: [reaction: BushMessageReaction | PartialBushMessageReaction, user: BushUser | PartialBushUser]; messageUpdate: [oldMessage: BushMessage | PartialBushMessage, newMessage: BushMessage | PartialBushMessage]; presenceUpdate: [oldPresence: BushPresence | null, newPresence: BushPresence]; - rateLimit: [rateLimitData: RateLimitData]; - invalidRequestWarning: [invalidRequestWarningData: InvalidRequestWarningData]; ready: [client: BushClient<true>]; invalidated: []; roleCreate: [role: BushRole]; diff --git a/src/lib/extensions/discord.js/BushDMChannel.ts b/src/lib/extensions/discord.js/BushDMChannel.ts index 363c620..d73ad70 100644 --- a/src/lib/extensions/discord.js/BushDMChannel.ts +++ b/src/lib/extensions/discord.js/BushDMChannel.ts @@ -13,7 +13,7 @@ import type { BushVoiceBasedChannel, BushVoiceChannel } from '#lib'; -import { DMChannel, type Partialize } from 'discord.js'; +import { DMChannel, PartialGroupDMChannel, type Partialize } from 'discord.js'; import type { RawDMChannelData } from 'discord.js/typings/rawDataTypes'; /** @@ -32,6 +32,7 @@ export class BushDMChannel extends DMChannel { export interface BushDMChannel extends DMChannel { isText(): this is BushTextChannel; isDM(): this is BushDMChannel; + isDMBased(): this is PartialGroupDMChannel | BushDMChannel; isVoice(): this is BushVoiceChannel; isCategory(): this is BushCategoryChannel; isNews(): this is BushNewsChannel; diff --git a/src/lib/extensions/discord.js/BushGuild.ts b/src/lib/extensions/discord.js/BushGuild.ts index b546dab..83e024d 100644 --- a/src/lib/extensions/discord.js/BushGuild.ts +++ b/src/lib/extensions/discord.js/BushGuild.ts @@ -18,7 +18,7 @@ import { type GuildLogType, type GuildModel } from '#lib'; -import { Collection, Guild, Permissions, Snowflake, type MessageOptions, type MessagePayload } from 'discord.js'; +import { Collection, Guild, PermissionFlagsBits, Snowflake, type MessageOptions, type MessagePayload } from 'discord.js'; import type { RawGuildData } from 'discord.js/typings/rawDataTypes'; import _ from 'lodash'; import { Moderation } from '../../common/util/Moderation.js'; @@ -138,7 +138,7 @@ export class BushGuild extends Guild { if ( !logChannel .permissionsFor(this.me!.id) - ?.has([Permissions.FLAGS.VIEW_CHANNEL, Permissions.FLAGS.SEND_MESSAGES, Permissions.FLAGS.EMBED_LINKS]) + ?.has([PermissionFlagsBits.ViewChannel, PermissionFlagsBits.SendMessages, PermissionFlagsBits.EmbedLinks]) ) return; @@ -162,7 +162,7 @@ export class BushGuild extends Guild { */ public async bushBan(options: GuildBushBanOptions): Promise<BanResponse> { // checks - if (!this.me!.permissions.has(Permissions.FLAGS.BAN_MEMBERS)) return banResponse.MISSING_PERMISSIONS; + if (!this.me!.permissions.has(PermissionFlagsBits.BanMembers)) return banResponse.MISSING_PERMISSIONS; let caseID: string | undefined = undefined; let dmSuccessEvent: boolean | undefined = undefined; @@ -241,7 +241,7 @@ export class BushGuild extends Guild { */ public async bushUnban(options: GuildBushUnbanOptions): Promise<UnbanResponse> { // checks - if (!this.me!.permissions.has(Permissions.FLAGS.BAN_MEMBERS)) return unbanResponse.MISSING_PERMISSIONS; + if (!this.me!.permissions.has(PermissionFlagsBits.BanMembers)) return unbanResponse.MISSING_PERMISSIONS; let caseID: string | undefined = undefined; let dmSuccessEvent: boolean | undefined = undefined; @@ -335,11 +335,11 @@ export class BushGuild extends Guild { success.set(channel.id, false); continue; } - if (!channel.permissionsFor(this.me!.id)?.has([Permissions.FLAGS.MANAGE_CHANNELS])) { + if (!channel.permissionsFor(this.me!.id)?.has([PermissionFlagsBits.ManageChannels])) { errors.set(channel.id, new Error('client no permission')); success.set(channel.id, false); continue; - } else if (!channel.permissionsFor(moderator)?.has([Permissions.FLAGS.MANAGE_CHANNELS])) { + } else if (!channel.permissionsFor(moderator)?.has([PermissionFlagsBits.ManageChannels])) { errors.set(channel.id, new Error('moderator no permission')); success.set(channel.id, false); continue; @@ -351,10 +351,10 @@ export class BushGuild extends Guild { const permissionOverwrites = channel.isThread() ? channel.parent!.permissionOverwrites : channel.permissionOverwrites; const perms = { - [channel.isThread() ? 'SEND_MESSAGES_IN_THREADS' : 'FLAGS.SEND_MESSAGES']: options.unlock ? null : false + [channel.isThread() ? 'SendMessagesInThreads' : 'SendMessages']: options.unlock ? null : false }; const permsForMe = { - [channel.isThread() ? 'SEND_MESSAGES_IN_THREADS' : 'FLAGS.SEND_MESSAGES']: options.unlock ? null : true + [channel.isThread() ? 'SendMessagesInThreads' : 'SendMessages']: options.unlock ? null : true }; // so I can send messages in the channel const changePermSuccess = await permissionOverwrites.edit(this.id, perms, { reason }).catch((e) => e); diff --git a/src/lib/extensions/discord.js/BushGuildChannel.ts b/src/lib/extensions/discord.js/BushGuildChannel.ts index 053507e..dd523e5 100644 --- a/src/lib/extensions/discord.js/BushGuildChannel.ts +++ b/src/lib/extensions/discord.js/BushGuildChannel.ts @@ -14,7 +14,7 @@ import type { BushVoiceBasedChannel, BushVoiceChannel } from '#lib'; -import { GuildChannel } from 'discord.js'; +import { GuildChannel, PartialGroupDMChannel } from 'discord.js'; import type { RawGuildChannelData } from 'discord.js/typings/rawDataTypes'; /** @@ -37,6 +37,7 @@ export class BushGuildChannel extends GuildChannel { export interface BushGuildChannel extends GuildChannel { isText(): this is BushTextChannel; + isDMBased(): this is PartialGroupDMChannel | BushDMChannel; isDM(): this is BushDMChannel; isVoice(): this is BushVoiceChannel; isCategory(): this is BushCategoryChannel; diff --git a/src/lib/extensions/discord.js/BushGuildChannelManager.ts b/src/lib/extensions/discord.js/BushGuildChannelManager.ts index dd3885b..029f7d3 100644 --- a/src/lib/extensions/discord.js/BushGuildChannelManager.ts +++ b/src/lib/extensions/discord.js/BushGuildChannelManager.ts @@ -55,7 +55,7 @@ export declare class BushGuildChannelManager * permissionOverwrites: [ * { * id: message.author.id, - * deny: [Permissions.FLAGS.VIEW_CHANNEL], + * deny: [PermissionFlagsBits.ViewChannel], * }, * ], * }) diff --git a/src/lib/extensions/discord.js/BushGuildMember.ts b/src/lib/extensions/discord.js/BushGuildMember.ts index 10d8a4c..ab6cd65 100644 --- a/src/lib/extensions/discord.js/BushGuildMember.ts +++ b/src/lib/extensions/discord.js/BushGuildMember.ts @@ -11,7 +11,7 @@ import { type BushThreadChannelResolvable, type BushUser } from '#lib'; -import { GuildMember, Permissions, type Partialize, type Role } from 'discord.js'; +import { GuildMember, PermissionFlagsBits, type Partialize, type Role } from 'discord.js'; import type { RawGuildMemberData } from 'discord.js/typings/rawDataTypes'; /* eslint-enable @typescript-eslint/no-unused-vars */ @@ -90,7 +90,7 @@ export class BushGuildMember extends GuildMember { */ public async bushAddRole(options: AddRoleOptions): Promise<AddRoleResponse> { // checks - if (!this.guild.me!.permissions.has(Permissions.FLAGS.MANAGE_ROLES)) return addRoleResponse.MISSING_PERMISSIONS; + if (!this.guild.me!.permissions.has(PermissionFlagsBits.ManageRoles)) return addRoleResponse.MISSING_PERMISSIONS; const ifShouldAddRole = this.#checkIfShouldAddRole(options.role, options.moderator); if (ifShouldAddRole !== true) return ifShouldAddRole; @@ -161,7 +161,7 @@ export class BushGuildMember extends GuildMember { */ public async bushRemoveRole(options: RemoveRoleOptions): Promise<RemoveRoleResponse> { // checks - if (!this.guild.me!.permissions.has(Permissions.FLAGS.MANAGE_ROLES)) return removeRoleResponse.MISSING_PERMISSIONS; + if (!this.guild.me!.permissions.has(PermissionFlagsBits.ManageRoles)) return removeRoleResponse.MISSING_PERMISSIONS; const ifShouldAddRole = this.#checkIfShouldAddRole(options.role, options.moderator); if (ifShouldAddRole !== true) return ifShouldAddRole; @@ -252,7 +252,7 @@ export class BushGuildMember extends GuildMember { */ public async bushMute(options: BushTimedPunishmentOptions): Promise<MuteResponse> { // checks - if (!this.guild.me!.permissions.has(Permissions.FLAGS.MANAGE_ROLES)) return muteResponse.MISSING_PERMISSIONS; + if (!this.guild.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); @@ -338,7 +338,7 @@ export class BushGuildMember extends GuildMember { */ public async bushUnmute(options: BushPunishmentOptions): Promise<UnmuteResponse> { // checks - if (!this.guild.me!.permissions.has(Permissions.FLAGS.MANAGE_ROLES)) return unmuteResponse.MISSING_PERMISSIONS; + if (!this.guild.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); @@ -421,7 +421,7 @@ export class BushGuildMember extends GuildMember { */ public async bushKick(options: BushPunishmentOptions): Promise<KickResponse> { // checks - if (!this.guild.me?.permissions.has(Permissions.FLAGS.KICK_MEMBERS) || !this.kickable) + if (!this.guild.me?.permissions.has(PermissionFlagsBits.KickMembers) || !this.kickable) return kickResponse.MISSING_PERMISSIONS; let caseID: string | undefined = undefined; @@ -474,7 +474,7 @@ export class BushGuildMember extends GuildMember { */ public async bushBan(options: BushBanOptions): Promise<Exclude<BanResponse, typeof banResponse['ALREADY_BANNED']>> { // checks - if (!this.guild.me!.permissions.has(Permissions.FLAGS.BAN_MEMBERS) || !this.bannable) return banResponse.MISSING_PERMISSIONS; + if (!this.guild.me!.permissions.has(PermissionFlagsBits.BanMembers) || !this.bannable) return banResponse.MISSING_PERMISSIONS; let caseID: string | undefined = undefined; let dmSuccessEvent: boolean | undefined = undefined; @@ -554,7 +554,8 @@ export class BushGuildMember extends GuildMember { if (!channel || (!channel.isTextBased() && !channel.isThread())) return blockResponse.INVALID_CHANNEL; // checks - if (!channel.permissionsFor(this.guild.me!)!.has(Permissions.FLAGS.MANAGE_CHANNELS)) return blockResponse.MISSING_PERMISSIONS; + if (!channel.permissionsFor(this.guild.me!)!.has(PermissionFlagsBits.ManageChannels)) + return blockResponse.MISSING_PERMISSIONS; let caseID: string | undefined = undefined; let dmSuccessEvent: boolean | undefined = undefined; @@ -564,7 +565,7 @@ export class BushGuildMember extends GuildMember { const ret = await (async () => { // change channel permissions const channelToUse = channel.isThread() ? channel.parent! : channel; - const perm = channel.isThread() ? { SEND_MESSAGES_IN_THREADS: false } : { SEND_MESSAGES: false }; + const perm = channel.isThread() ? { SendMessagesInThreads: false } : { SendMessages: false }; const blockSuccess = await channelToUse.permissionOverwrites .edit(this, perm, { reason: `[Block] ${moderator.tag} | ${options.reason ?? 'No reason provided.'}` }) .catch(() => false); @@ -643,7 +644,7 @@ export class BushGuildMember extends GuildMember { const channel = _channel as BushGuildTextBasedChannel; // checks - if (!channel.permissionsFor(this.guild.me!)!.has(Permissions.FLAGS.MANAGE_CHANNELS)) + if (!channel.permissionsFor(this.guild.me!)!.has(PermissionFlagsBits.ManageChannels)) return unblockResponse.MISSING_PERMISSIONS; let caseID: string | undefined = undefined; @@ -654,7 +655,7 @@ export class BushGuildMember extends GuildMember { const ret = await (async () => { // change channel permissions const channelToUse = channel.isThread() ? channel.parent! : channel; - const perm = channel.isThread() ? { SEND_MESSAGES_IN_THREADS: null } : { SEND_MESSAGES: null }; + const perm = channel.isThread() ? { SendMessagesInThreads: null } : { SendMessages: null }; const blockSuccess = await channelToUse.permissionOverwrites .edit(this, perm, { reason: `[Unblock] ${moderator.tag} | ${options.reason ?? 'No reason provided.'}` }) .catch(() => false); @@ -720,7 +721,7 @@ export class BushGuildMember extends GuildMember { */ public async bushTimeout(options: BushTimeoutOptions): Promise<TimeoutResponse> { // checks - if (!this.guild.me!.permissions.has(Permissions.FLAGS.MODERATE_MEMBERS)) return timeoutResponse.MISSING_PERMISSIONS; + if (!this.guild.me!.permissions.has(PermissionFlagsBits.ModerateMembers)) return timeoutResponse.MISSING_PERMISSIONS; const twentyEightDays = client.consts.timeUnits.days.value * 28; if (options.duration > twentyEightDays) return timeoutResponse.INVALID_DURATION; @@ -784,7 +785,7 @@ export class BushGuildMember extends GuildMember { */ public async bushRemoveTimeout(options: BushPunishmentOptions): Promise<RemoveTimeoutResponse> { // checks - if (!this.guild.me!.permissions.has(Permissions.FLAGS.MODERATE_MEMBERS)) return removeTimeoutResponse.MISSING_PERMISSIONS; + if (!this.guild.me!.permissions.has(PermissionFlagsBits.ModerateMembers)) return removeTimeoutResponse.MISSING_PERMISSIONS; let caseID: string | undefined = undefined; let dmSuccessEvent: boolean | undefined = undefined; diff --git a/src/lib/extensions/discord.js/BushGuildMemberManager.ts b/src/lib/extensions/discord.js/BushGuildMemberManager.ts index bb130fc..3f8dcd2 100644 --- a/src/lib/extensions/discord.js/BushGuildMemberManager.ts +++ b/src/lib/extensions/discord.js/BushGuildMemberManager.ts @@ -31,7 +31,7 @@ export declare class BushGuildMemberManager public guild: BushGuild; /** - * Adds a user to the guild using OAuth2. Requires the `CREATE_INSTANT_INVITE` permission. + * Adds a user to the guild using OAuth2. Requires the `PermissionFlagsBits.CreateInstantInvite` permission. * @param user The user to add to the guild * @param options Options for adding the user to the guild */ diff --git a/src/lib/extensions/discord.js/BushStoreChannel.ts b/src/lib/extensions/discord.js/BushStoreChannel.ts index dbc53e8..eadc8af 100644 --- a/src/lib/extensions/discord.js/BushStoreChannel.ts +++ b/src/lib/extensions/discord.js/BushStoreChannel.ts @@ -14,7 +14,7 @@ import type { BushVoiceBasedChannel, BushVoiceChannel } from '#lib'; -import { StoreChannel, type Collection, type Snowflake } from 'discord.js'; +import { PartialGroupDMChannel, StoreChannel, type Collection, type Snowflake } from 'discord.js'; import type { RawGuildChannelData } from 'discord.js/typings/rawDataTypes'; /** @@ -34,6 +34,7 @@ export class BushStoreChannel extends StoreChannel { export interface BushStoreChannel extends StoreChannel { isText(): this is BushTextChannel; isDM(): this is BushDMChannel; + isDMBased(): this is PartialGroupDMChannel | BushDMChannel; isVoice(): this is BushVoiceChannel; isCategory(): this is BushCategoryChannel; isNews(): this is BushNewsChannel; diff --git a/src/lib/extensions/discord.js/BushTextChannel.ts b/src/lib/extensions/discord.js/BushTextChannel.ts index 15be7bd..ad54b76 100644 --- a/src/lib/extensions/discord.js/BushTextChannel.ts +++ b/src/lib/extensions/discord.js/BushTextChannel.ts @@ -14,7 +14,7 @@ import type { BushVoiceBasedChannel, BushVoiceChannel } from '#lib'; -import { TextChannel, type AllowedThreadTypeForTextChannel } from 'discord.js'; +import { PartialGroupDMChannel, TextChannel, type AllowedThreadTypeForTextChannel } from 'discord.js'; import type { RawGuildChannelData } from 'discord.js/typings/rawDataTypes'; /** @@ -33,6 +33,7 @@ export class BushTextChannel extends TextChannel { export interface BushTextChannel extends TextChannel { isText(): this is BushTextChannel; isDM(): this is BushDMChannel; + isDMBased(): this is PartialGroupDMChannel | BushDMChannel; isVoice(): this is BushVoiceChannel; isCategory(): this is BushCategoryChannel; isNews(): this is BushNewsChannel; diff --git a/src/lib/extensions/discord.js/BushThreadChannel.ts b/src/lib/extensions/discord.js/BushThreadChannel.ts index a342dd7..691fabf 100644 --- a/src/lib/extensions/discord.js/BushThreadChannel.ts +++ b/src/lib/extensions/discord.js/BushThreadChannel.ts @@ -16,7 +16,7 @@ import type { BushVoiceBasedChannel, BushVoiceChannel } from '#lib'; -import { ThreadChannel, type Collection, type Snowflake } from 'discord.js'; +import { PartialGroupDMChannel, ThreadChannel, type Collection, type Snowflake } from 'discord.js'; import type { RawThreadChannelData } from 'discord.js/typings/rawDataTypes'; /** @@ -38,6 +38,7 @@ export class BushThreadChannel extends ThreadChannel { export interface BushThreadChannel extends ThreadChannel { isText(): this is BushTextChannel; isDM(): this is BushDMChannel; + isDMBased(): this is PartialGroupDMChannel | BushDMChannel; isVoice(): this is BushVoiceChannel; isCategory(): this is BushCategoryChannel; isNews(): this is BushNewsChannel; diff --git a/src/lib/extensions/discord.js/BushThreadMemberManager.ts b/src/lib/extensions/discord.js/BushThreadMemberManager.ts index d597673..48e968f 100644 --- a/src/lib/extensions/discord.js/BushThreadMemberManager.ts +++ b/src/lib/extensions/discord.js/BushThreadMemberManager.ts @@ -32,7 +32,7 @@ export declare class BushThreadMemberManager public add(member: UserResolvable | '@me', reason?: string): Promise<Snowflake>; /** - * Fetches member(s) for the thread from Discord, requires access to the `GUILD_MEMBERS` gateway intent. + * Fetches member(s) for the thread from Discord, requires access to the `GatewayIntentBits.GuildMembers` gateway intent. * @param options Additional options for this fetch, when a `boolean` is provided * all members are fetched with `options.cache` set to the boolean value */ diff --git a/src/lib/extensions/discord.js/BushUserManager.ts b/src/lib/extensions/discord.js/BushUserManager.ts index ae28f1d..c26dbde 100644 --- a/src/lib/extensions/discord.js/BushUserManager.ts +++ b/src/lib/extensions/discord.js/BushUserManager.ts @@ -4,7 +4,7 @@ import { Message, MessageOptions, MessagePayload, - UserFlags, + UserFlagsBitField, UserManager, type BaseFetchOptions, type Snowflake @@ -49,7 +49,7 @@ export declare class BushUserManager extends CachedManager<Snowflake, BushUser, * @param user The UserResolvable to identify * @param options Additional options for this fetch */ - public fetchFlags(user: BushUserResolvable, options?: BaseFetchOptions): Promise<UserFlags>; + public fetchFlags(user: BushUserResolvable, options?: BaseFetchOptions): Promise<UserFlagsBitField>; /** * Sends a message to a user. diff --git a/src/lib/utils/BushConstants.ts b/src/lib/utils/BushConstants.ts index e7b69ae..df8212b 100644 --- a/src/lib/utils/BushConstants.ts +++ b/src/lib/utils/BushConstants.ts @@ -171,49 +171,47 @@ export class BushConstants { }, permissions: { - CREATE_INSTANT_INVITE: { name: 'Create Invite', important: false }, - KICK_MEMBERS: { name: 'Kick Members', important: true }, - BAN_MEMBERS: { name: 'Ban Members', important: true }, - ADMINISTRATOR: { name: 'Administrator', important: true }, - MANAGE_CHANNELS: { name: 'Manage Channels', important: true }, - MANAGE_GUILD: { name: 'Manage Server', important: true }, - ADD_REACTIONS: { name: 'Add Reactions', important: false }, - VIEW_AUDIT_LOG: { name: 'View Audit Log', important: true }, - PRIORITY_SPEAKER: { name: 'Priority Speaker', important: true }, - STREAM: { name: 'Video', important: false }, - VIEW_CHANNEL: { name: 'View Channel', important: false }, - SEND_MESSAGES: { name: 'Send Messages', important: false }, - SEND_TTS_MESSAGES: { name: 'Send Text-to-Speech Messages', important: true }, - MANAGE_MESSAGES: { name: 'Manage Messages', important: true }, - EMBED_LINKS: { name: 'Embed Links', important: false }, - ATTACH_FILES: { name: 'Attach Files', important: false }, - READ_MESSAGE_HISTORY: { name: 'Read Message History', important: false }, - MENTION_EVERYONE: { name: 'Mention @\u200Beveryone, @\u200Bhere, and All Roles', important: true }, // name has a zero-width space to prevent accidents - USE_EXTERNAL_EMOJIS: { name: 'Use External Emoji', important: false }, - VIEW_GUILD_INSIGHTS: { name: 'View Server Insights', important: true }, - CONNECT: { name: 'Connect', important: false }, - SPEAK: { name: 'Speak', important: false }, - MUTE_MEMBERS: { name: 'Mute Members', important: true }, - DEAFEN_MEMBERS: { name: 'Deafen Members', important: true }, - MOVE_MEMBERS: { name: 'Move Members', important: true }, - USE_VAD: { name: 'Use Voice Activity', important: false }, - CHANGE_NICKNAME: { name: 'Change Nickname', important: false }, - MANAGE_NICKNAMES: { name: 'Change Nicknames', important: true }, - MANAGE_ROLES: { name: 'Manage Roles', important: true }, - MANAGE_WEBHOOKS: { name: 'Manage Webhooks', important: true }, - MANAGE_EMOJIS_AND_STICKERS: { name: 'Manage Emojis and Stickers', important: true }, - USE_APPLICATION_COMMANDS: { name: 'Use Slash Commands', important: false }, - REQUEST_TO_SPEAK: { name: 'Request to Speak', important: false }, - MANAGE_THREADS: { name: 'Manage Threads', important: true }, - USE_PUBLIC_THREADS: { name: 'Use public Threads', important: false }, - CREATE_PUBLIC_THREADS: { name: 'Create Public Threads', important: false }, - USE_PRIVATE_THREADS: { name: 'Use Private Threads', important: false }, - CREATE_PRIVATE_THREADS: { name: 'Create Private Threads', important: false }, - USE_EXTERNAL_STICKERS: { name: 'Use External Stickers', important: false }, - SEND_MESSAGES_IN_THREADS: { name: 'Send Messages In Threads', important: false }, - START_EMBEDDED_ACTIVITIES: { name: 'Start Activities', important: false }, - MODERATE_MEMBERS: { name: 'Timeout Members', important: true }, - MANAGE_EVENTS: { name: 'Manage Events', important: true } + CreateInstantInvite: { name: 'Create Invite', important: false }, + KickMembers: { name: 'Kick Members', important: true }, + BanMembers: { name: 'Ban Members', important: true }, + Administrator: { name: 'Administrator', important: true }, + ManageChannels: { name: 'Manage Channels', important: true }, + ManageGuild: { name: 'Manage Server', important: true }, + AddReactions: { name: 'Add Reactions', important: false }, + ViewAuditLog: { name: 'View Audit Log', important: true }, + PrioritySpeaker: { name: 'Priority Speaker', important: true }, + Stream: { name: 'Video', important: false }, + ViewChannel: { name: 'View Channel', important: false }, + SendMessages: { name: 'Send Messages', important: false }, + SendTTSMessages: { name: 'Send Text-to-Speech Messages', important: true }, + ManageMessages: { name: 'Manage Messages', important: true }, + EmbedLinks: { name: 'Embed Links', important: false }, + AttachFiles: { name: 'Attach Files', important: false }, + ReadMessageHistory: { name: 'Read Message History', important: false }, + MentionEveryone: { name: 'Mention @\u200Beveryone, @\u200Bhere, and All Roles', important: true }, // name has a zero-width space to prevent accidents + UseExternalEmojis: { name: 'Use External Emoji', important: false }, + ViewGuildInsights: { name: 'View Server Insights', important: true }, + Connect: { name: 'Connect', important: false }, + Speak: { name: 'Speak', important: false }, + MuteMembers: { name: 'Mute Members', important: true }, + DeafenMembers: { name: 'Deafen Members', important: true }, + MoveMembers: { name: 'Move Members', important: true }, + UseVAD: { name: 'Use Voice Activity', important: false }, + ChangeNickname: { name: 'Change Nickname', important: false }, + ManageNicknames: { name: 'Change Nicknames', important: true }, + ManageRoles: { name: 'Manage Roles', important: true }, + ManageWebhooks: { name: 'Manage Webhooks', important: true }, + ManageEmojisAndStickers: { name: 'Manage Emojis and Stickers', important: true }, + UseApplicationCommands: { name: 'Use Slash Commands', important: false }, + RequestToSpeak: { name: 'Request to Speak', important: false }, + ManageEvents: { name: 'Manage Events', important: true }, + ManageThreads: { name: 'Manage Threads', important: true }, + CreatePublicThreads: { name: 'Create Public Threads', important: false }, + CreatePrivateThreads: { name: 'Create Private Threads', important: false }, + UseExternalStickers: { name: 'Use External Stickers', important: false }, + SendMessagesInThreads: { name: 'Send Messages In Threads', important: false }, + StartEmbeddedActivities: { name: 'Start Activities', important: false }, + ModerateMembers: { name: 'Timeout Members', important: true } }, // prettier-ignore @@ -294,20 +292,21 @@ export class BushConstants { }, userFlags: { - STAFF: '<:discordEmployee:848742947826434079>', - PARTNER: '<:partneredServerOwner:848743051593777152>', - HYPESQUAD: '<:hypeSquadEvents:848743108283072553>', - BUG_HUNTER_LEVEL_1: '<:bugHunter:848743239850393640>', - HYPESQUAD_ONLINE_HOUSE_1: '<:hypeSquadBravery:848742910563844127>', - HYPESQUAD_ONLINE_HOUSE_2: '<:hypeSquadBrilliance:848742840649646101>', - HYPESQUAD_ONLINE_HOUSE_3: '<:hypeSquadBalance:848742877537370133>', - PREMIUM_EARLY_SUPPORTER: '<:earlySupporter:848741030102171648>', - TEAM_PSEUDO_USER: 'TEAM_PSEUDO_USER', - BUG_HUNTER_LEVEL_2: '<:bugHunterGold:848743283080822794>', - VERIFIED_BOT: 'VERIFIED_BOT', - VERIFIED_DEVELOPER: '<:earlyVerifiedBotDeveloper:848741079875846174>', - CERTIFIED_MODERATOR: '<:discordCertifiedModerator:877224285901582366>', - BOT_HTTP_INTERACTIONS: 'BOT_HTTP_INTERACTIONS' + None: '', + Staff: '<:discordEmployee:848742947826434079>', + Partner: '<:partneredServerOwner:848743051593777152>', + Hypesquad: '<:hypeSquadEvents:848743108283072553>', + BugHunterLevel1: '<:bugHunter:848743239850393640>', + HypeSquadOnlineHouse1: '<:hypeSquadBravery:848742910563844127>', + HypeSquadOnlineHouse2: '<:hypeSquadBrilliance:848742840649646101>', + HypeSquadOnlineHouse3: '<:hypeSquadBalance:848742877537370133>', + PremiumEarlySupporter: '<:earlySupporter:848741030102171648>', + TeamPseudoUser: 'TEAM_PSEUDO_USER', + BugHunterLevel2: '<:bugHunterGold:848743283080822794>', + VerifiedBot: 'VERIFIED_BOT', + VerifiedDeveloper: '<:earlyVerifiedBotDeveloper:848741079875846174>', + CertifiedModerator: '<:discordCertifiedModerator:877224285901582366>', + BotHTTPInteractions: 'BOT_HTTP_INTERACTIONS' }, status: { |