aboutsummaryrefslogtreecommitdiff
path: root/src/lib/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/common')
-rw-r--r--src/lib/common/AutoMod.ts32
-rw-r--r--src/lib/common/ButtonPaginator.ts139
-rw-r--r--src/lib/common/ConfirmationPrompt.ts27
-rw-r--r--src/lib/common/DeleteButton.ts16
-rw-r--r--src/lib/common/util/Moderation.ts8
5 files changed, 117 insertions, 105 deletions
diff --git a/src/lib/common/AutoMod.ts b/src/lib/common/AutoMod.ts
index 7a30820..4de242a 100644
--- a/src/lib/common/AutoMod.ts
+++ b/src/lib/common/AutoMod.ts
@@ -1,5 +1,14 @@
import { banResponse, Moderation, type BushButtonInteraction, type BushMessage } from '#lib';
-import { GuildMember, MessageActionRow, MessageButton, MessageEmbed, type TextChannel } from 'discord.js';
+import {
+ ActionRow,
+ ButtonComponent,
+ ButtonStyle,
+ ChannelType,
+ GuildMember,
+ MessageEmbed,
+ Permissions,
+ type TextChannel
+} from 'discord.js';
/**
* Handles auto moderation functionality.
@@ -28,7 +37,7 @@ export class AutoMod {
* Handles the auto moderation
*/
private async handle() {
- if (this.message.channel.type === 'DM' || !this.message.guild) return;
+ if (this.message.channel.type === ChannelType.DM || !this.message.guild) return;
if (!(await this.message.guild.hasFeature('automod'))) return;
if (this.message.author.bot) return;
if (this.message.author.isOwner()) return;
@@ -110,7 +119,10 @@ export class AutoMod {
const includes = this.message.content.toLocaleLowerCase().includes;
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('MENTION_EVERYONE') || this.message.mentions.everyone)
+ if (
+ this.message.member?.permissionsIn(this.message.channelId).has(Permissions.FLAGS.MENTION_EVERYONE) ||
+ this.message.mentions.everyone
+ )
return;
if (
@@ -142,9 +154,9 @@ export class AutoMod {
components:
Severity.TEMP_MUTE >= 2
? [
- new MessageActionRow().addComponents(
- new MessageButton()
- .setStyle('DANGER')
+ new ActionRow().addComponents(
+ new ButtonComponent()
+ .setStyle(ButtonStyle.Danger)
.setLabel('Ban User')
.setCustomId(`automod;ban;${this.message.author.id};everyone mention and scam phrase`)
)
@@ -263,9 +275,9 @@ export class AutoMod {
components:
highestOffence.severity >= 2
? [
- new MessageActionRow().addComponents(
- new MessageButton()
- .setStyle('DANGER')
+ new ActionRow().addComponents(
+ new ButtonComponent()
+ .setStyle(ButtonStyle.Danger)
.setLabel('Ban User')
.setCustomId(`automod;ban;${this.message.author.id};${highestOffence.reason}`)
)
@@ -279,7 +291,7 @@ export class AutoMod {
* @param interaction The button interaction.
*/
public static async handleInteraction(interaction: BushButtonInteraction) {
- if (!interaction.memberPermissions?.has('BAN_MEMBERS'))
+ if (!interaction.memberPermissions?.has(Permissions.FLAGS.BAN_MEMBERS))
return interaction.reply({
content: `${util.emojis.error} You are missing the **Ban Members** permission.`,
ephemeral: true
diff --git a/src/lib/common/ButtonPaginator.ts b/src/lib/common/ButtonPaginator.ts
index 83f4219..9e72551 100644
--- a/src/lib/common/ButtonPaginator.ts
+++ b/src/lib/common/ButtonPaginator.ts
@@ -1,13 +1,15 @@
import { DeleteButton, type BushMessage, type BushSlashMessage } from '#lib';
import { CommandUtil } from 'discord-akairo';
import {
- MessageActionRow,
- MessageButton,
+ ActionRow,
+ ActionRowComponent,
+ ButtonComponent,
+ ButtonStyle,
+ ComponentType,
MessageEmbed,
type MessageComponentInteraction,
type MessageEmbedOptions
} from 'discord.js';
-import { MessageButtonStyles } from 'discord.js/typings/enums';
/**
* Sends multiple embeds with controls to switch between them
@@ -94,9 +96,15 @@ export class ButtonPaginator {
})) as BushMessage;
const collector = this.sentMessage.createMessageComponentCollector({
- filter: (i) => i.customId.startsWith('paginate_') && i.message?.id === this.sentMessage!.id,
- time: 300000
+ componentType: ComponentType.Button,
+ filter: (i) => {
+ const ret = i.customId.startsWith('paginate_') && i.message.id === this.sentMessage!.id;
+ console.debug(ret);
+ return ret;
+ },
+ idle: 300000
});
+ console.debug('got here');
collector.on('collect', (i) => void this.collect(i));
collector.on('end', () => void this.end());
@@ -107,8 +115,9 @@ export class ButtonPaginator {
* @param interaction The interaction received
*/
protected async collect(interaction: MessageComponentInteraction) {
+ console.debug(1);
if (interaction.user.id !== this.message.author.id && !client.config.owners.includes(interaction.user.id))
- return await interaction?.deferUpdate().catch(() => null);
+ return await interaction?.deferUpdate(); /* .catch(() => null); */
switch (interaction.customId) {
case 'paginate_beginning':
@@ -121,17 +130,16 @@ export class ButtonPaginator {
break;
case 'paginate_stop':
if (this.deleteOnExit) {
- await interaction.deferUpdate().catch(() => null);
- await this.sentMessage!.delete().catch(() => null);
+ await interaction.deferUpdate(); /* .catch(() => null); */
+ await this.sentMessage!.delete(); /* .catch(() => null); */
break;
} else {
- await interaction
- ?.update({
- content: `${this.text ? `${this.text}\n` : ''}Command closed by user.`,
- embeds: [],
- components: []
- })
- .catch(() => null);
+ await interaction?.update({
+ content: `${this.text ? `${this.text}\n` : ''}Command closed by user.`,
+ embeds: [],
+ components: []
+ });
+ /* .catch(() => null); */
break;
}
case 'paginate_next':
@@ -150,13 +158,12 @@ export class ButtonPaginator {
*/
protected async end() {
if (this.sentMessage && !CommandUtil.deletedMessages.has(this.sentMessage.id))
- await this.sentMessage
- .edit({
- content: this.text,
- embeds: [this.embeds[this.curPage]],
- components: [this.getPaginationRow(true)]
- })
- .catch(() => null);
+ await this.sentMessage.edit({
+ content: this.text,
+ embeds: [this.embeds[this.curPage]],
+ components: [this.getPaginationRow(true)]
+ });
+ /* .catch(() => null); */
}
/**
@@ -164,52 +171,46 @@ export class ButtonPaginator {
* @param interaction The interaction received
*/
protected async edit(interaction: MessageComponentInteraction) {
- await interaction
- ?.update({
- content: this.text,
- embeds: [this.embeds[this.curPage]],
- components: [this.getPaginationRow()]
- })
- .catch(() => null);
+ await interaction?.update({
+ content: this.text,
+ embeds: [this.embeds[this.curPage]],
+ components: [this.getPaginationRow()]
+ });
+ /* .catch(() => null); */
}
/**
* Generates the pagination row based on the class properties
* @param disableAll Whether to disable all buttons
- * @returns The generated {@link MessageActionRow}
+ * @returns The generated {@link ActionRow}
*/
- protected getPaginationRow(disableAll = false): MessageActionRow {
- return new MessageActionRow().addComponents(
- new MessageButton({
- style: MessageButtonStyles.PRIMARY,
- customId: 'paginate_beginning',
- emoji: PaginateEmojis.BEGGING,
- disabled: disableAll || this.curPage === 0
- }),
- new MessageButton({
- style: MessageButtonStyles.PRIMARY,
- customId: 'paginate_back',
- emoji: PaginateEmojis.BACK,
- disabled: disableAll || this.curPage === 0
- }),
- new MessageButton({
- style: MessageButtonStyles.PRIMARY,
- customId: 'paginate_stop',
- emoji: PaginateEmojis.STOP,
- disabled: disableAll
- }),
- new MessageButton({
- style: MessageButtonStyles.PRIMARY,
- customId: 'paginate_next',
- emoji: PaginateEmojis.FORWARD,
- disabled: disableAll || this.curPage === this.numPages - 1
- }),
- new MessageButton({
- style: MessageButtonStyles.PRIMARY,
- customId: 'paginate_end',
- emoji: PaginateEmojis.END,
- disabled: disableAll || this.curPage === this.numPages - 1
- })
+ protected getPaginationRow(disableAll = false): ActionRow<ActionRowComponent> {
+ return new ActionRow().addComponents(
+ new ButtonComponent()
+ .setStyle(ButtonStyle.Primary)
+ .setCustomId('paginate_beginning')
+ .setEmoji(PaginateEmojis.BEGINNING)
+ .setDisabled(disableAll || this.curPage === 0),
+ new ButtonComponent()
+ .setStyle(ButtonStyle.Primary)
+ .setCustomId('paginate_back')
+ .setEmoji(PaginateEmojis.BACK)
+ .setDisabled(disableAll || this.curPage === 0),
+ new ButtonComponent()
+ .setStyle(ButtonStyle.Primary)
+ .setCustomId('paginate_stop')
+ .setEmoji(PaginateEmojis.STOP)
+ .setDisabled(disableAll),
+ new ButtonComponent()
+ .setStyle(ButtonStyle.Primary)
+ .setCustomId('paginate_next')
+ .setEmoji(PaginateEmojis.FORWARD)
+ .setDisabled(disableAll || this.curPage === this.embeds.length - 1),
+ new ButtonComponent()
+ .setStyle(ButtonStyle.Primary)
+ .setCustomId('paginate_end')
+ .setEmoji(PaginateEmojis.END)
+ .setDisabled(disableAll || this.curPage === this.embeds.length - 1)
);
}
@@ -235,10 +236,10 @@ export class ButtonPaginator {
}
}
-export const enum PaginateEmojis {
- BEGGING = '853667381335162910',
- BACK = '853667410203770881',
- STOP = '853667471110570034',
- FORWARD = '853667492680564747',
- END = '853667514915225640'
-}
+export const PaginateEmojis = {
+ BEGINNING: { id: '853667381335162910', name: 'w_paginate_beginning', animated: false } as const,
+ BACK: { id: '853667410203770881', name: 'w_paginate_back', animated: false } as const,
+ STOP: { id: '853667471110570034', name: 'w_paginate_stop', animated: false } as const,
+ FORWARD: { id: '853667492680564747', name: 'w_paginate_next', animated: false } as const,
+ END: { id: '853667514915225640', name: 'w_paginate_end', animated: false } as const
+} as const;
diff --git a/src/lib/common/ConfirmationPrompt.ts b/src/lib/common/ConfirmationPrompt.ts
index a4acf83..97f18b3 100644
--- a/src/lib/common/ConfirmationPrompt.ts
+++ b/src/lib/common/ConfirmationPrompt.ts
@@ -1,6 +1,5 @@
import { type BushMessage, type BushSlashMessage } from '#lib';
-import { MessageActionRow, MessageButton, type MessageComponentInteraction, type MessageOptions } from 'discord.js';
-import { MessageButtonStyles } from 'discord.js/typings/enums';
+import { ActionRow, ButtonComponent, ButtonStyle, type MessageComponentInteraction, type MessageOptions } from 'discord.js';
/**
* Sends a message with buttons for the user to confirm or cancel the action.
@@ -30,19 +29,17 @@ export class ConfirmationPrompt {
*/
protected async send(): Promise<boolean> {
this.messageOptions.components = [
- new MessageActionRow().addComponents(
- new MessageButton({
- style: MessageButtonStyles.SUCCESS,
- customId: 'confirmationPrompt_confirm',
- emoji: util.emojis.successFull,
- label: 'Yes'
- }),
- new MessageButton({
- style: MessageButtonStyles.DANGER,
- customId: 'confirmationPrompt_deny',
- emoji: util.emojis.errorFull,
- label: 'No'
- })
+ new ActionRow().addComponents(
+ new ButtonComponent()
+ .setStyle(ButtonStyle.Primary)
+ .setCustomId('confirmationPrompt_confirm')
+ .setEmoji({ id: util.emojis.successFull, name: 'successFull', animated: false })
+ .setLabel('Yes'),
+ new ButtonComponent()
+ .setStyle(ButtonStyle.Danger)
+ .setCustomId('confirmationPrompt_cancel')
+ .setEmoji({ id: util.emojis.errorFull, name: 'errorFull', animated: false })
+ .setLabel('No')
)
];
diff --git a/src/lib/common/DeleteButton.ts b/src/lib/common/DeleteButton.ts
index b666a4f..edc40fe 100644
--- a/src/lib/common/DeleteButton.ts
+++ b/src/lib/common/DeleteButton.ts
@@ -1,7 +1,6 @@
import { PaginateEmojis, type BushMessage, type BushSlashMessage } from '#lib';
import { CommandUtil } from 'discord-akairo';
-import { MessageActionRow, MessageButton, type MessageComponentInteraction, type MessageOptions } from 'discord.js';
-import { MessageButtonStyles } from 'discord.js/typings/enums';
+import { ActionRow, ButtonComponent, ButtonStyle, MessageComponentInteraction, type MessageOptions } from 'discord.js';
/**
* Sends a message with a button for the user to delete it.
@@ -59,13 +58,12 @@ export class DeleteButton {
*/
protected updateComponents(edit = false, disable = false): void {
this.messageOptions.components = [
- new MessageActionRow().addComponents(
- new MessageButton({
- style: MessageButtonStyles.PRIMARY,
- customId: 'paginate__stop',
- emoji: PaginateEmojis.STOP,
- disabled: disable
- })
+ new ActionRow().addComponents(
+ new ButtonComponent()
+ .setStyle(ButtonStyle.Primary)
+ .setCustomId('paginate__stop')
+ .setEmoji(PaginateEmojis.STOP)
+ .setDisabled(disable)
)
];
if (edit) {
diff --git a/src/lib/common/util/Moderation.ts b/src/lib/common/util/Moderation.ts
index e5cb872..84d9fbf 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 { MessageEmbed, type Snowflake } from 'discord.js';
+import { MessageEmbed, Permissions, type Snowflake } from 'discord.js';
/**
* A utility class with moderation-related methods.
@@ -70,7 +70,11 @@ export class Moderation {
) {
return `${util.emojis.error} You cannot ${type} **${victim.user.tag}** because they have higher or equal role hierarchy as I do.`;
}
- if (checkModerator && victim.permissions.has('MANAGE_MESSAGES') && !(type.startsWith('un') && moderator.id === victim.id)) {
+ if (
+ checkModerator &&
+ victim.permissions.has(Permissions.FLAGS.MANAGE_MESSAGES) &&
+ !(type.startsWith('un') && moderator.id === victim.id)
+ ) {
if (await moderator.guild.hasFeature('modsCanPunishMods')) {
return true;
} else {