Skip to content
This repository was archived by the owner on Oct 9, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ const customId = CustomID.parseCustomId(interaction.customId);

To handle components (buttons, selects, modals) create a new method called `handleComponents` or `handleModals` for modals in the command/subcommand class. Then create a decorator for the method using the `@InteractionHandler` decorator with the customId prefix of the components/modals. The method will be called when the component is triggered. Example:

```ts
```typescript
// you can change the type of `interaction` to ButtonInteraction etc. if you are aware of the type of component
@InteractionHandler('cool_button_')
public async handleComponents(interaction: MessageComponentInteraction) {
static override async handleComponents(interaction: MessageComponentInteraction) {
const customId = CustomID.parseCustomId(interaction.customId);
// handle component logic, same as how it is with collectors
}
Expand Down
2 changes: 1 addition & 1 deletion src/commands/context-menu/blacklist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export default class Blacklist extends BaseCommand {
}

@RegisterInteractionHandler('blacklist')
async handleComponents(interaction: MessageComponentInteraction): Promise<void> {
static override async handleComponents(interaction: MessageComponentInteraction): Promise<void> {
const customId = CustomID.parseCustomId(interaction.customId);

if (interaction.user.id !== customId.args[0]) {
Expand Down
7 changes: 1 addition & 6 deletions src/commands/context-menu/deleteMsg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,8 @@ export default class DeleteMessage extends BaseCommand {
);
}

// find all the messages through the network
const channelSettingsArr = await db.connectedList.findMany({
where: { channelId: { in: messageInDb.originalMsg.broadcastMsgs.map((c) => c.channelId) } },
});

const results = messageInDb.originalMsg.broadcastMsgs.map(async (element) => {
const connection = channelSettingsArr.find((c) => c.channelId === element.channelId);
const connection = interaction.client.connectionCache.find((c) => c.channelId === element.channelId);
if (!connection) return false;

const webhookURL = connection.webhookURL.split('/');
Expand Down
15 changes: 10 additions & 5 deletions src/commands/context-menu/messageInfo.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable complexity */
import {
ActionRow,
ActionRowBuilder,
Expand Down Expand Up @@ -96,7 +97,7 @@ export default class MessageInfo extends BaseCommand {
}

@RegisterInteractionHandler('msgInfo')
async handleComponents(interaction: MessageComponentInteraction) {
static override async handleComponents(interaction: MessageComponentInteraction) {
// create a variable to store the profile card buffer
const customId = CustomID.parseCustomId(interaction.customId);
const messageId = customId.args[0];
Expand All @@ -109,14 +110,15 @@ export default class MessageInfo extends BaseCommand {
)?.originalMsg;

if (!originalMsg) {
return await interaction.update({
await interaction.update({
content: t(
{ phrase: 'errors.unknownNetworkMessage', locale: interaction.user.locale },
{ emoji: emojis.no },
),
embeds: [],
components: [],
});
return;
}

const author = await interaction.client.users.fetch(originalMsg.authorId);
Expand Down Expand Up @@ -144,14 +146,15 @@ export default class MessageInfo extends BaseCommand {
// server info button
case 'serverInfo': {
if (!server) {
return await interaction.update({
await interaction.update({
content: t(
{ phrase: 'errors.unknownServer', locale: interaction.user.locale },
{ emoji: emojis.no },
),
embeds: [],
components: [],
});
return;
}

const owner = await interaction.client.users.fetch(server.ownerId);
Expand Down Expand Up @@ -276,7 +279,7 @@ export default class MessageInfo extends BaseCommand {

case 'report': {
if (!originalMsg.hub?.logChannels?.reports) {
return await interaction.reply({
await interaction.reply({
embeds: [
simpleEmbed(
t(
Expand All @@ -287,6 +290,7 @@ export default class MessageInfo extends BaseCommand {
],
ephemeral: true,
});
return;
}

const modal = new ModalBuilder()
Expand Down Expand Up @@ -323,7 +327,7 @@ export default class MessageInfo extends BaseCommand {
});

if (!messageInDb?.originalMsg.hub?.logChannels?.reports) {
return await interaction.reply({
await interaction.reply({
embeds: [
simpleEmbed(
t(
Expand All @@ -334,6 +338,7 @@ export default class MessageInfo extends BaseCommand {
],
ephemeral: true,
});
return;
}

const { authorId, serverId } = messageInDb.originalMsg;
Expand Down
2 changes: 1 addition & 1 deletion src/commands/context-menu/translate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export default class Translate extends BaseCommand {
}

@RegisterInteractionHandler('translate')
async handleComponents(interaction: ButtonInteraction) {
static override async handleComponents(interaction: ButtonInteraction) {
const modal = new ModalBuilder()
.setCustomId(new CustomID('translate_modal').toString())
.setTitle('Specify Language')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import {
} from 'discord.js';
import { badgeEmojis, emojis, LINKS } from '../../../utils/Constants.js';
import { getCredits, simpleEmbed } from '../../../utils/Utils.js';
import BaseCommand from '../../../core/BaseCommand.js';
import { stripIndents } from 'common-tags';
import BaseCommand from '../../../core/BaseCommand.js';

export default class Credits extends BaseCommand {
export default class About extends BaseCommand {
readonly data: RESTPostAPIChatInputApplicationCommandsJSONBody = {
name: 'credits',
description: 'Shows the credits for InterChat',
name: 'about',
description: 'Learn more about the InterChat team and project.',
};

private async getUsernames(client: Client): Promise<string[]> {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/slash/Information/stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export default class Stats extends BaseCommand {
}

@RegisterInteractionHandler('stats')
async handleComponents(interaction: ButtonInteraction) {
static override async handleComponents(interaction: ButtonInteraction) {
const customId = CustomID.parseCustomId(interaction.customId);

const allCusterData = await interaction.client.cluster.broadcastEval((client) => {
Expand Down
2 changes: 2 additions & 0 deletions src/commands/slash/Main/blacklist/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,8 @@ export default class BlacklistCommand extends BaseCommand {
await interaction.respond(choices);
break;
}
default:
break;
}
}
}
Loading