diff options
Diffstat (limited to 'src/lib/extensions')
-rw-r--r-- | src/lib/extensions/discord.js/BushClientEvents.d.ts | 102 | ||||
-rw-r--r-- | src/lib/extensions/discord.js/BushGuild.ts | 7 | ||||
-rw-r--r-- | src/lib/extensions/discord.js/BushGuildBan.d.ts | 14 | ||||
-rw-r--r-- | src/lib/extensions/discord.js/BushGuildMember.ts | 35 | ||||
-rw-r--r-- | src/lib/extensions/discord.js/BushMessage.ts | 2 | ||||
-rw-r--r-- | src/lib/extensions/discord.js/BushMessageReaction.ts | 4 | ||||
-rw-r--r-- | src/lib/extensions/discord.js/BushUser.ts | 4 |
7 files changed, 142 insertions, 26 deletions
diff --git a/src/lib/extensions/discord.js/BushClientEvents.d.ts b/src/lib/extensions/discord.js/BushClientEvents.d.ts index da5d647..ae9b186 100644 --- a/src/lib/extensions/discord.js/BushClientEvents.d.ts +++ b/src/lib/extensions/discord.js/BushClientEvents.d.ts @@ -1,7 +1,103 @@ -import { ClientEvents } from 'discord.js'; -import { BushMessage, BushPartialMessage } from './BushMessage'; +import { + ClientEvents, + Collection, + Interaction, + InvalidRequestWarningData, + Invite, + RateLimitData, + Snowflake, + Sticker, + Typing +} from 'discord.js'; +import { BushClient, BushTextBasedChannels } from '../discord-akairo/BushClient'; +import { BushApplicationCommand } from './BushApplicationCommand'; +import { BushDMChannel } from './BushDMChannel'; +import { BushGuild } from './BushGuild'; +import { BushGuildBan } from './BushGuildBan'; +import { BushGuildChannel } from './BushGuildChannel'; +import { BushGuildEmoji } from './BushGuildEmoji'; +import { BushGuildMember, PartialBushGuildMember } from './BushGuildMember'; +import { BushMessage, PartialBushMessage } from './BushMessage'; +import { BushMessageReaction, PartialBushMessageReaction } from './BushMessageReaction'; +import { BushPresence } from './BushPresence'; +import { BushRole } from './BushRole'; +import { BushStageInstance } from './BushStageInstance'; +import { BushTextChannel } from './BushTextChannel'; +import { BushThreadChannel } from './BushThreadChannel'; +import { BushThreadMember } from './BushThreadMember'; +import { BushUser, PartialBushUser } from './BushUser'; +import { BushVoiceState } from './BushVoiceState'; export interface BushClientEvents extends ClientEvents { + applicationCommandCreate: [command: BushApplicationCommand]; + applicationCommandDelete: [command: BushApplicationCommand]; + applicationCommandUpdate: [oldCommand: BushApplicationCommand | null, newCommand: BushApplicationCommand]; + channelCreate: [channel: BushGuildChannel]; + channelDelete: [channel: BushDMChannel | BushGuildChannel]; + channelPinsUpdate: [channel: BushTextBasedChannels, date: Date]; + channelUpdate: [oldChannel: BushDMChannel | BushGuildChannel, newChannel: BushDMChannel | BushGuildChannel]; + debug: [message: string]; + warn: [message: string]; + emojiCreate: [emoji: BushGuildEmoji]; + emojiDelete: [emoji: BushGuildEmoji]; + emojiUpdate: [oldEmoji: BushGuildEmoji, newEmoji: BushGuildEmoji]; + error: [error: Error]; + guildBanAdd: [ban: BushGuildBan]; + guildBanRemove: [ban: BushGuildBan]; + guildCreate: [guild: BushGuild]; + guildDelete: [guild: BushGuild]; + guildUnavailable: [guild: BushGuild]; + guildIntegrationsUpdate: [guild: BushGuild]; + guildMemberAdd: [member: BushGuildMember]; + guildMemberAvailable: [member: BushGuildMember | PartialBushGuildMember]; + guildMemberRemove: [member: BushGuildMember | PartialBushGuildMember]; + guildMembersChunk: [ + members: Collection<Snowflake, BushGuildMember>, + guild: BushGuild, + data: { count: number; index: number; nonce: string | undefined } + ]; + guildMemberUpdate: [oldMember: BushGuildMember | PartialBushGuildMember, newMember: BushGuildMember]; + guildUpdate: [oldGuild: BushGuild, newGuild: BushGuild]; + inviteCreate: [invite: Invite]; + inviteDelete: [invite: Invite]; messageCreate: [message: BushMessage]; - messageUpdate: [oldMessage: BushMessage | BushPartialMessage, newMessage: BushMessage | BushPartialMessage]; + messageDelete: [message: BushMessage | PartialBushMessage]; + messageReactionRemoveAll: [message: BushMessage | PartialBushMessage]; + messageReactionRemoveEmoji: [reaction: BushMessageReaction | PartialBushMessageReaction]; + messageDeleteBulk: [messages: Collection<Snowflake, BushMessage | PartialBushMessage>]; + messageReactionAdd: [reaction: BushMessageReaction | PartialBushMessageReaction, user: BushUser | PartialBushUser]; + 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]; + roleDelete: [role: BushRole]; + roleUpdate: [oldRole: BushRole, newRole: BushRole]; + threadCreate: [thread: BushThreadChannel]; + threadDelete: [thread: BushThreadChannel]; + threadListSync: [threads: Collection<Snowflake, BushThreadChannel>]; + threadMemberUpdate: [oldMember: BushThreadMember, newMember: BushThreadMember]; + threadMembersUpdate: [ + oldMembers: Collection<Snowflake, BushThreadMember>, + mewMembers: Collection<Snowflake, BushThreadMember> + ]; + threadUpdate: [oldThread: BushThreadChannel, newThread: BushThreadChannel]; + typingStart: [typing: Typing]; + userUpdate: [oldUser: BushUser | PartialBushUser, newUser: BushUser]; + voiceStateUpdate: [oldState: BushVoiceState, newState: BushVoiceState]; + webhookUpdate: [channel: BushTextChannel]; + interactionCreate: [interaction: Interaction]; + shardError: [error: Error, shardId: number]; + shardReady: [shardId: number, unavailableGuilds: Set<Snowflake> | undefined]; + shardReconnecting: [shardId: number]; + shardResume: [shardId: number, replayedEvents: number]; + stageInstanceCreate: [stageInstance: BushStageInstance]; + stageInstanceUpdate: [oldStageInstance: BushStageInstance | null, newStageInstance: BushStageInstance]; + stageInstanceDelete: [stageInstance: BushStageInstance]; + stickerCreate: [sticker: Sticker]; + stickerDelete: [sticker: Sticker]; + stickerUpdate: [oldSticker: Sticker, newSticker: Sticker]; } diff --git a/src/lib/extensions/discord.js/BushGuild.ts b/src/lib/extensions/discord.js/BushGuild.ts index 81c0108..efc780d 100644 --- a/src/lib/extensions/discord.js/BushGuild.ts +++ b/src/lib/extensions/discord.js/BushGuild.ts @@ -1,6 +1,6 @@ import { Guild } from 'discord.js'; import { RawGuildData } from 'discord.js/typings/rawDataTypes'; -import { Guild as GuildDB, GuildModel } from '../../models/Guild'; +import { Guild as GuildDB, GuildFeatures, GuildModel } from '../../models/Guild'; import { ModLogType } from '../../models/ModLog'; import { BushClient, BushUserResolvable } from '../discord-akairo/BushClient'; import { BushGuildMember } from './BushGuildMember'; @@ -15,6 +15,11 @@ export class BushGuild extends Guild { super(client, data); } + public async hasFeature(feature: GuildFeatures): Promise<boolean> { + const features = await this.getSetting('enabledFeatures'); + return features.includes(feature); + } + public async getSetting<K extends keyof GuildModel>(setting: K): Promise<GuildModel[K]> { return ( client.cache.guilds.get(this.id)?.[setting] ?? diff --git a/src/lib/extensions/discord.js/BushGuildBan.d.ts b/src/lib/extensions/discord.js/BushGuildBan.d.ts new file mode 100644 index 0000000..0174220 --- /dev/null +++ b/src/lib/extensions/discord.js/BushGuildBan.d.ts @@ -0,0 +1,14 @@ +import { GuildBan } from 'discord.js'; +import { RawGuildBanData } from 'discord.js/typings/rawDataTypes'; +import { BushClient } from '../discord-akairo/BushClient'; +import { BushGuild } from './BushGuild'; +import { BushUser } from './BushUser'; + +export class BushGuildBan extends GuildBan { + public constructor(client: BushClient, data: RawGuildBanData, guild: BushGuild); + public guild: BushGuild; + public user: BushUser; + public readonly partial: boolean; + public reason?: string | null; + public fetch(force?: boolean): Promise<BushGuildBan>; +} diff --git a/src/lib/extensions/discord.js/BushGuildMember.ts b/src/lib/extensions/discord.js/BushGuildMember.ts index 641cc74..e596c82 100644 --- a/src/lib/extensions/discord.js/BushGuildMember.ts +++ b/src/lib/extensions/discord.js/BushGuildMember.ts @@ -1,5 +1,5 @@ /* eslint-disable @typescript-eslint/no-unused-vars */ -import { GuildMember, Role } from 'discord.js'; +import { GuildMember, Partialize, Role } from 'discord.js'; import { RawGuildMemberData } from 'discord.js/typings/rawDataTypes'; import { ModLogType } from '../../models/ModLog'; import { BushClient, BushUserResolvable } from '../discord-akairo/BushClient'; @@ -72,6 +72,12 @@ interface BushBanOptions extends BushTimedPunishmentOptions { type BanResponse = PunishmentResponse | 'missing permissions' | 'error creating ban entry' | 'error banning'; +export type PartialBushGuildMember = Partialize< + BushGuildMember, + 'joinedAt' | 'joinedTimestamp', + 'user' | 'warn' | 'addRole' | 'removeRole' | 'mute' | 'unmute' | 'bushKick' | 'bushBan' | 'isOwner' | 'isSuperUser' +>; + export class BushGuildMember extends GuildMember { public declare readonly client: BushClient; public declare guild: BushGuild; @@ -98,8 +104,7 @@ export class BushGuildMember extends GuildMember { // dm user const ending = await this.guild.getSetting('punishmentEnding'); const dmSuccess = await this.send({ - // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing - content: `You have been warned in **${this.guild}** for **${options.reason || 'No reason provided'}**.${ + content: `You have been warned in **${this.guild.name}** for **${options.reason ?? 'No reason provided'}**.${ ending ? `\n\n${ending}` : '' }` }).catch(() => false); @@ -200,8 +205,7 @@ export class BushGuildMember extends GuildMember { // add role const muteSuccess = await this.roles - // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing - .add(muteRole, `[Mute] ${moderator.tag} | ${options.reason || 'No reason provided.'}`) + .add(muteRole, `[Mute] ${moderator.tag} | ${options.reason ?? 'No reason provided.'}`) .catch(async (e) => { await client.console.warn('muteRoleAddError', e?.stack || e); return false; @@ -236,8 +240,7 @@ export class BushGuildMember extends GuildMember { const dmSuccess = await this.send({ content: `You have been muted ${ options.duration ? 'for ' + util.humanizeDuration(options.duration) : 'permanently' - // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing - } in **${this.guild}** for **${options.reason || 'No reason provided'}**.${ending ? `\n\n${ending}` : ''}` + } in **${this.guild.name}** for **${options.reason ?? 'No reason provided'}**.${ending ? `\n\n${ending}` : ''}` }).catch(() => false); if (!dmSuccess) return 'failed to dm'; @@ -258,8 +261,7 @@ export class BushGuildMember extends GuildMember { //remove role const muteSuccess = await this.roles - // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing - .remove(muteRole, `[Unmute] ${moderator.tag} | ${options.reason || 'No reason provided.'}`) + .remove(muteRole, `[Unmute] ${moderator.tag} | ${options.reason ?? 'No reason provided.'}`) .catch(async (e) => { await client.console.warn('muteRoleAddError', e?.stack || e); return false; @@ -288,8 +290,7 @@ export class BushGuildMember extends GuildMember { //dm user const dmSuccess = await this.send({ - // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing - content: `You have been unmuted in **${this.guild}** because **${options.reason || 'No reason provided'}**.` + content: `You have been unmuted in **${this.guild.name}** because **${options.reason ?? 'No reason provided'}**.` }).catch(() => false); if (!dmSuccess) return 'failed to dm'; @@ -306,15 +307,13 @@ export class BushGuildMember extends GuildMember { // dm user const ending = await this.guild.getSetting('punishmentEnding'); const dmSuccess = await this.send({ - // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing - content: `You have been kicked from **${this.guild}** for **${options.reason || 'No reason provided'}**.${ + content: `You have been kicked from **${this.guild.name}** for **${options.reason ?? 'No reason provided'}**.${ ending ? `\n\n${ending}` : '' }` }).catch(() => false); // kick - // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing - const kickSuccess = await this.kick(`${moderator?.tag} | ${options.reason || 'No reason provided.'}`).catch(() => false); + const kickSuccess = await this.kick(`${moderator?.tag} | ${options.reason ?? 'No reason provided.'}`).catch(() => false); if (!kickSuccess) return 'error kicking'; // add modlog entry @@ -343,14 +342,12 @@ export class BushGuildMember extends GuildMember { const dmSuccess = await this.send({ content: `You have been banned ${ options?.duration ? 'for ' + util.humanizeDuration(options.duration) : 'permanently' - // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing - } from **${this.guild}** for **${options.reason || 'No reason provided'}**.${ending ? `\n\n${ending}` : ''}` + } from **${this.guild.name}** for **${options.reason ?? 'No reason provided'}**.${ending ? `\n\n${ending}` : ''}` }).catch(() => false); // ban const banSuccess = await this.ban({ - // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing - reason: `${moderator.tag} | ${options.reason || 'No reason provided.'}`, + reason: `${moderator.tag} | ${options.reason ?? 'No reason provided.'}`, days: options.deleteDays }).catch(() => false); if (!banSuccess) return 'error banning'; diff --git a/src/lib/extensions/discord.js/BushMessage.ts b/src/lib/extensions/discord.js/BushMessage.ts index 6d9a332..7907efe 100644 --- a/src/lib/extensions/discord.js/BushMessage.ts +++ b/src/lib/extensions/discord.js/BushMessage.ts @@ -7,7 +7,7 @@ import { BushGuild } from './BushGuild'; import { BushGuildMember } from './BushGuildMember'; import { BushUser } from './BushUser'; -export interface BushPartialMessage +export interface PartialBushMessage extends Partialize<BushMessage, 'type' | 'system' | 'pinned' | 'tts', 'content' | 'cleanContent' | 'author'> {} export class BushMessage extends Message { public declare readonly client: BushClient; diff --git a/src/lib/extensions/discord.js/BushMessageReaction.ts b/src/lib/extensions/discord.js/BushMessageReaction.ts index b0bc5d7..056e4e6 100644 --- a/src/lib/extensions/discord.js/BushMessageReaction.ts +++ b/src/lib/extensions/discord.js/BushMessageReaction.ts @@ -1,10 +1,12 @@ -import { MessageReaction } from 'discord.js'; +import { MessageReaction, Partialize } from 'discord.js'; import { RawMessageReactionData } from 'discord.js/typings/rawDataTypes'; import { BushClient } from '../discord-akairo/BushClient'; import { BushGuildEmoji } from './BushGuildEmoji'; import { BushMessage } from './BushMessage'; import { BushReactionEmoji } from './BushReactionEmoji'; +export type PartialBushMessageReaction = Partialize<BushMessageReaction, 'count'>; + export class BushMessageReaction extends MessageReaction { public declare readonly client: BushClient; public declare readonly emoji: BushGuildEmoji | BushReactionEmoji; diff --git a/src/lib/extensions/discord.js/BushUser.ts b/src/lib/extensions/discord.js/BushUser.ts index 9a183e1..15a0d03 100644 --- a/src/lib/extensions/discord.js/BushUser.ts +++ b/src/lib/extensions/discord.js/BushUser.ts @@ -1,8 +1,10 @@ -import { User } from 'discord.js'; +import { Partialize, User } from 'discord.js'; import { RawUserData } from 'discord.js/typings/rawDataTypes'; import { BushClient } from '../discord-akairo/BushClient'; import { BushDMChannel } from './BushDMChannel'; +export type PartialBushUser = Partialize<BushUser, 'username' | 'tag' | 'discriminator' | 'isOwner' | 'isSuperUser'>; + export class BushUser extends User { public declare readonly client: BushClient; public declare readonly dmChannel: BushDMChannel | null; |