From d401b3842c545e2da678646f4cafe4a8d3829648 Mon Sep 17 00:00:00 2001 From: Aed Date: Wed, 23 Jul 2025 15:01:55 +0100 Subject: [PATCH 01/16] add preview feature --- bingus-bot/src/contexts/reply.ts | 47 +++++++++++++++-- bingus-bot/src/contexts/replyWithList.ts | 65 ++++++++++++++++++++---- bingus-bot/src/util.ts | 9 ++-- 3 files changed, 105 insertions(+), 16 deletions(-) diff --git a/bingus-bot/src/contexts/reply.ts b/bingus-bot/src/contexts/reply.ts index 2fcfd4b..e707dd8 100644 --- a/bingus-bot/src/contexts/reply.ts +++ b/bingus-bot/src/contexts/reply.ts @@ -1,7 +1,12 @@ import { + ActionRowBuilder, ApplicationCommandType, + ButtonBuilder, + ButtonStyle, + Client, ContextMenuCommandBuilder, EmbedBuilder, + GatewayIntentBits, MessageFlags, } from "discord.js"; import { ContextMenu } from "../index.js"; @@ -16,7 +21,7 @@ export const replyContext: ContextMenu = { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion const query = interaction.targetMessage.content; console.log( - `User ${interaction.user} asked about "${query}" for ${interaction.targetMessage.author}`, + `User ${interaction.user} asked "${query}" for ${interaction.targetMessage.author}`, ); try { @@ -28,7 +33,16 @@ export const replyContext: ContextMenu = { return; } - interaction.targetMessage.reply({ + const show = new ButtonBuilder() + .setCustomId('show') + .setLabel("show embed") + .setStyle(ButtonStyle.Primary); + + const showB = new ActionRowBuilder() + .addComponents(show); + + + const message = await interaction.editReply({ embeds: [ new EmbedBuilder() .setAuthor({ @@ -40,10 +54,37 @@ export const replyContext: ContextMenu = { .setColor("#65459A") .setFooter({ text: `${data[0].relevance.toFixed()}% relevant` }) .data, + + ], + components: [showB], + }); + + const collector = message.createMessageComponentCollector(); + + collector.on('collect', async i => { + interaction.deleteReply(); + interaction.targetMessage.reply({ + embeds: [ + new EmbedBuilder() + .setAuthor({ + name: `Triggered by ${interaction.user.displayName}`, + iconURL: interaction.user.avatarURL() ?? undefined, + }) + .setTitle(data[0].title) + .setDescription(data[0].text) + .setColor("#65459A") + .setFooter({text: `${data[0].relevance.toFixed()}% relevant` }) + + + .data, + ], }); + }); + + + - await interaction.editReply("Replied to the message!"); } catch (error) { console.error(error); interaction.editReply("An error occurred while fetching results."); diff --git a/bingus-bot/src/contexts/replyWithList.ts b/bingus-bot/src/contexts/replyWithList.ts index 3ebb259..68a2132 100644 --- a/bingus-bot/src/contexts/replyWithList.ts +++ b/bingus-bot/src/contexts/replyWithList.ts @@ -1,6 +1,9 @@ import { + ActionRowBuilder, ApplicationCommandType, + ButtonBuilder, ContextMenuCommandBuilder, + ButtonStyle, EmbedBuilder, MessageFlags, } from "discord.js"; @@ -16,7 +19,7 @@ export const replyListContext: ContextMenu = { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion const query = interaction.targetMessage.content; console.log( - `User ${interaction.user} asked about "${query}" for ${interaction.targetMessage.author}`, + `User ${interaction.user} asked "${query}" for ${interaction.targetMessage.author}`, ); try { @@ -34,8 +37,17 @@ export const replyListContext: ContextMenu = { return; } - const embedList = new EmbedList(); - embedList.push( + const show = new ButtonBuilder() + .setCustomId('show') + .setLabel("show embed") + .setStyle(ButtonStyle.Primary); + + const showB = new ActionRowBuilder() + .addComponents(show); + + + const embedList1 = new EmbedList(); + embedList1.push( ...data.slice(0, 5).map( (res) => new EmbedBuilder() @@ -50,15 +62,48 @@ export const replyListContext: ContextMenu = { .data, ), ); + const targetChannel = interaction.targetMessage.channel + - await embedList.sendChannel( - interaction.targetMessage.channel, - interaction.user.id, - undefined, - { messageReference: interaction.targetMessage }, - ); + await embedList1.sendChatInput(interaction); + + + const message = await interaction.followUp({ + flags: MessageFlags.Ephemeral, + components: [showB] + }); + + + const collector = message.createMessageComponentCollector(); + collector.on('collect', async i => { + interaction.deleteReply(); + interaction.deleteReply(message); + const embedList = new EmbedList(); + embedList.push( + ...data.slice(0, 5).map( + (res) => + new EmbedBuilder() + .setAuthor({ + name: `Triggered by ${interaction.user.displayName}`, + iconURL: interaction.user.avatarURL() ?? undefined, + }) + .setTitle(res.title) + .setDescription(res.text) + .setColor("#65459A") + .setFooter({ text: `(${res.relevance.toFixed()}% relevant)` }) + .data, + ), + ); + + embedList.sendChannel( + targetChannel, + interaction.user.id, + undefined, + { + messageReference: interaction.targetMessage}, + ); - await interaction.editReply("Replied to the message!"); + }); } catch (error) { console.error(error); interaction.editReply("An error occurred while fetching results."); diff --git a/bingus-bot/src/util.ts b/bingus-bot/src/util.ts index 36e6877..cc3ca4a 100644 --- a/bingus-bot/src/util.ts +++ b/bingus-bot/src/util.ts @@ -7,6 +7,7 @@ import { ComponentType, EmbedBuilder, EmojiIdentifierResolvable, + MessageContextMenuCommandInteraction, ReplyOptions, SendableChannels, } from "discord.js"; @@ -54,9 +55,11 @@ export class EmbedList { .setLabel("< Prev") .setStyle(ButtonStyle.Secondary) .setDisabled(this.index === 0); + return new ActionRowBuilder().addComponents(prev, next); } + get(): EmbedBuilder { const embed = this.embeds[this.index]; @@ -66,7 +69,7 @@ export class EmbedList { }`.trim(), }); } - + async sendChannel( channel: SendableChannels, who: string | null, @@ -115,7 +118,7 @@ export class EmbedList { } async sendChatInput( - interaction: ChatInputCommandInteraction, + interaction: ChatInputCommandInteraction | MessageContextMenuCommandInteraction, publicInteraction: boolean | undefined = true, ) { const reply = await (interaction.deferred @@ -163,7 +166,7 @@ export class EmbedList { await interaction.editReply({ components: [] }); }); - return collector; + return this.getActionRow(), collector; } } From 73dda2e47fe02ee4d115b140550851e7a3fafa30 Mon Sep 17 00:00:00 2001 From: Aed <145398159+Aed-1@users.noreply.github.com> Date: Fri, 25 Jul 2025 15:00:31 +0100 Subject: [PATCH 02/16] Update bingus-bot/src/contexts/replyWithList.ts Co-authored-by: Uriel --- bingus-bot/src/contexts/replyWithList.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bingus-bot/src/contexts/replyWithList.ts b/bingus-bot/src/contexts/replyWithList.ts index 68a2132..dc135c4 100644 --- a/bingus-bot/src/contexts/replyWithList.ts +++ b/bingus-bot/src/contexts/replyWithList.ts @@ -39,7 +39,7 @@ export const replyListContext: ContextMenu = { const show = new ButtonBuilder() .setCustomId('show') - .setLabel("show embed") + .setLabel("Show message") .setStyle(ButtonStyle.Primary); const showB = new ActionRowBuilder() From 3339fb022067da2ff7caa1d2dea2cd832d3e70b5 Mon Sep 17 00:00:00 2001 From: Aed <145398159+Aed-1@users.noreply.github.com> Date: Fri, 25 Jul 2025 15:00:42 +0100 Subject: [PATCH 03/16] Update bingus-bot/src/contexts/reply.ts Co-authored-by: Uriel --- bingus-bot/src/contexts/reply.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bingus-bot/src/contexts/reply.ts b/bingus-bot/src/contexts/reply.ts index e707dd8..4136a41 100644 --- a/bingus-bot/src/contexts/reply.ts +++ b/bingus-bot/src/contexts/reply.ts @@ -35,7 +35,7 @@ export const replyContext: ContextMenu = { const show = new ButtonBuilder() .setCustomId('show') - .setLabel("show embed") + .setLabel("Show message") .setStyle(ButtonStyle.Primary); const showB = new ActionRowBuilder() From 68853bb4bd2dd0eb7be50a7687274c69bda13ee7 Mon Sep 17 00:00:00 2001 From: Aed <145398159+Aed-1@users.noreply.github.com> Date: Fri, 25 Jul 2025 15:00:55 +0100 Subject: [PATCH 04/16] Update bingus-bot/src/contexts/reply.ts Co-authored-by: Uriel --- bingus-bot/src/contexts/reply.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bingus-bot/src/contexts/reply.ts b/bingus-bot/src/contexts/reply.ts index 4136a41..81ff256 100644 --- a/bingus-bot/src/contexts/reply.ts +++ b/bingus-bot/src/contexts/reply.ts @@ -21,7 +21,7 @@ export const replyContext: ContextMenu = { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion const query = interaction.targetMessage.content; console.log( - `User ${interaction.user} asked "${query}" for ${interaction.targetMessage.author}`, + `User ${interaction.user} asked about "${query}" for ${interaction.targetMessage.author}`, ); try { From 24cdb95771d3de7a6dafcd3fe30989da674c6a1f Mon Sep 17 00:00:00 2001 From: Aed <145398159+Aed-1@users.noreply.github.com> Date: Fri, 25 Jul 2025 15:07:22 +0100 Subject: [PATCH 05/16] Update bingus-bot/src/util.ts Co-authored-by: Uriel --- bingus-bot/src/util.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/bingus-bot/src/util.ts b/bingus-bot/src/util.ts index cc3ca4a..20f9bec 100644 --- a/bingus-bot/src/util.ts +++ b/bingus-bot/src/util.ts @@ -69,7 +69,6 @@ export class EmbedList { }`.trim(), }); } - async sendChannel( channel: SendableChannels, who: string | null, From 9abc2fad979801e00b675b3abcd1b142c6c2ab3b Mon Sep 17 00:00:00 2001 From: Aed <145398159+Aed-1@users.noreply.github.com> Date: Fri, 25 Jul 2025 15:07:33 +0100 Subject: [PATCH 06/16] Update bingus-bot/src/contexts/replyWithList.ts Co-authored-by: Uriel --- bingus-bot/src/contexts/replyWithList.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bingus-bot/src/contexts/replyWithList.ts b/bingus-bot/src/contexts/replyWithList.ts index dc135c4..1e98a50 100644 --- a/bingus-bot/src/contexts/replyWithList.ts +++ b/bingus-bot/src/contexts/replyWithList.ts @@ -19,7 +19,7 @@ export const replyListContext: ContextMenu = { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion const query = interaction.targetMessage.content; console.log( - `User ${interaction.user} asked "${query}" for ${interaction.targetMessage.author}`, + `User ${interaction.user} asked about "${query}" for ${interaction.targetMessage.author}`, ); try { From ab814278dbb1f5ac787ade4c4fef04d524d0e1b5 Mon Sep 17 00:00:00 2001 From: Aed <145398159+Aed-1@users.noreply.github.com> Date: Fri, 25 Jul 2025 15:07:46 +0100 Subject: [PATCH 07/16] Update bingus-bot/src/util.ts Co-authored-by: Uriel --- bingus-bot/src/util.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/bingus-bot/src/util.ts b/bingus-bot/src/util.ts index 20f9bec..109e1a2 100644 --- a/bingus-bot/src/util.ts +++ b/bingus-bot/src/util.ts @@ -59,7 +59,6 @@ export class EmbedList { return new ActionRowBuilder().addComponents(prev, next); } - get(): EmbedBuilder { const embed = this.embeds[this.index]; From 9105b19965320a988e10ef29cd17231ea2e000d0 Mon Sep 17 00:00:00 2001 From: Aed <145398159+Aed-1@users.noreply.github.com> Date: Fri, 25 Jul 2025 15:08:01 +0100 Subject: [PATCH 08/16] Update bingus-bot/src/util.ts Co-authored-by: Uriel --- bingus-bot/src/util.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/bingus-bot/src/util.ts b/bingus-bot/src/util.ts index 109e1a2..ed83d3a 100644 --- a/bingus-bot/src/util.ts +++ b/bingus-bot/src/util.ts @@ -55,7 +55,6 @@ export class EmbedList { .setLabel("< Prev") .setStyle(ButtonStyle.Secondary) .setDisabled(this.index === 0); - return new ActionRowBuilder().addComponents(prev, next); } From aafefbea8d44387069dbaccca1bbfb047a698d7a Mon Sep 17 00:00:00 2001 From: Aed Date: Fri, 25 Jul 2025 15:32:28 +0100 Subject: [PATCH 09/16] Added requested changes --- bingus-bot/src/contexts/reply.ts | 44 ++++++++++------------- bingus-bot/src/contexts/replyWithList.ts | 45 ++++++++---------------- bingus-bot/src/util.ts | 2 +- 3 files changed, 33 insertions(+), 58 deletions(-) diff --git a/bingus-bot/src/contexts/reply.ts b/bingus-bot/src/contexts/reply.ts index 81ff256..17c979b 100644 --- a/bingus-bot/src/contexts/reply.ts +++ b/bingus-bot/src/contexts/reply.ts @@ -3,10 +3,8 @@ import { ApplicationCommandType, ButtonBuilder, ButtonStyle, - Client, ContextMenuCommandBuilder, EmbedBuilder, - GatewayIntentBits, MessageFlags, } from "discord.js"; import { ContextMenu } from "../index.js"; @@ -38,10 +36,7 @@ export const replyContext: ContextMenu = { .setLabel("Show message") .setStyle(ButtonStyle.Primary); - const showB = new ActionRowBuilder() - .addComponents(show); - - + const message = await interaction.editReply({ embeds: [ new EmbedBuilder() @@ -56,31 +51,28 @@ export const replyContext: ContextMenu = { .data, ], - components: [showB], + components: [new ActionRowBuilder().addComponents(show)], }); - const collector = message.createMessageComponentCollector(); - - collector.on('collect', async i => { - interaction.deleteReply(); - interaction.targetMessage.reply({ - embeds: [ - new EmbedBuilder() - .setAuthor({ - name: `Triggered by ${interaction.user.displayName}`, - iconURL: interaction.user.avatarURL() ?? undefined, - }) - .setTitle(data[0].title) - .setDescription(data[0].text) - .setColor("#65459A") - .setFooter({text: `${data[0].relevance.toFixed()}% relevant` }) - - - .data, + await message.awaitMessageComponent() + + interaction.deleteReply(); + interaction.targetMessage.reply({ + embeds: [ + new EmbedBuilder() + .setAuthor({ + name: `Triggered by ${interaction.user.displayName}`, + iconURL: interaction.user.avatarURL() ?? undefined, + }) + .setTitle(data[0].title) + .setDescription(data[0].text) + .setColor("#65459A") + .setFooter({text: `${data[0].relevance.toFixed()}% relevant` }) + .data, ], }); - }); + diff --git a/bingus-bot/src/contexts/replyWithList.ts b/bingus-bot/src/contexts/replyWithList.ts index 1e98a50..128dbec 100644 --- a/bingus-bot/src/contexts/replyWithList.ts +++ b/bingus-bot/src/contexts/replyWithList.ts @@ -46,8 +46,8 @@ export const replyListContext: ContextMenu = { .addComponents(show); - const embedList1 = new EmbedList(); - embedList1.push( + const embedList = new EmbedList(); + embedList.push( ...data.slice(0, 5).map( (res) => new EmbedBuilder() @@ -65,7 +65,7 @@ export const replyListContext: ContextMenu = { const targetChannel = interaction.targetMessage.channel - await embedList1.sendChatInput(interaction); + await embedList.sendChatInput(interaction); const message = await interaction.followUp({ @@ -74,36 +74,19 @@ export const replyListContext: ContextMenu = { }); - const collector = message.createMessageComponentCollector(); - collector.on('collect', async i => { - interaction.deleteReply(); - interaction.deleteReply(message); - const embedList = new EmbedList(); - embedList.push( - ...data.slice(0, 5).map( - (res) => - new EmbedBuilder() - .setAuthor({ - name: `Triggered by ${interaction.user.displayName}`, - iconURL: interaction.user.avatarURL() ?? undefined, - }) - .setTitle(res.title) - .setDescription(res.text) - .setColor("#65459A") - .setFooter({ text: `(${res.relevance.toFixed()}% relevant)` }) - .data, - ), + await message.awaitMessageComponent() + + interaction.deleteReply(); + interaction.deleteReply(message); + + embedList.sendChannel( + targetChannel, + interaction.user.id, + undefined, + { + messageReference: interaction.targetMessage}, ); - - embedList.sendChannel( - targetChannel, - interaction.user.id, - undefined, - { - messageReference: interaction.targetMessage}, - ); - }); } catch (error) { console.error(error); interaction.editReply("An error occurred while fetching results."); diff --git a/bingus-bot/src/util.ts b/bingus-bot/src/util.ts index ed83d3a..8d57446 100644 --- a/bingus-bot/src/util.ts +++ b/bingus-bot/src/util.ts @@ -163,7 +163,7 @@ export class EmbedList { await interaction.editReply({ components: [] }); }); - return this.getActionRow(), collector; + return collector; } } From 2d278c85a45aed6bec05766ff3b98b4d9995fc9e Mon Sep 17 00:00:00 2001 From: Aed Date: Wed, 30 Jul 2025 01:24:14 +0100 Subject: [PATCH 10/16] cleaned up button in replywithlist --- bingus-bot/src/contexts/reply.ts | 6 ++- bingus-bot/src/contexts/replyWithList.ts | 60 ++++++++++++++---------- bingus-bot/src/util.ts | 19 +++++++- 3 files changed, 58 insertions(+), 27 deletions(-) diff --git a/bingus-bot/src/contexts/reply.ts b/bingus-bot/src/contexts/reply.ts index 17c979b..921aed2 100644 --- a/bingus-bot/src/contexts/reply.ts +++ b/bingus-bot/src/contexts/reply.ts @@ -56,7 +56,11 @@ export const replyContext: ContextMenu = { await message.awaitMessageComponent() - interaction.deleteReply(); + interaction.editReply({ + content: "Replied to message!", + embeds: [], + components: [] + }); interaction.targetMessage.reply({ embeds: [ new EmbedBuilder() diff --git a/bingus-bot/src/contexts/replyWithList.ts b/bingus-bot/src/contexts/replyWithList.ts index 128dbec..2af7293 100644 --- a/bingus-bot/src/contexts/replyWithList.ts +++ b/bingus-bot/src/contexts/replyWithList.ts @@ -6,6 +6,8 @@ import { ButtonStyle, EmbedBuilder, MessageFlags, + ComponentType, + ButtonInteraction, } from "discord.js"; import { ContextMenu } from "../index.js"; import { EmbedList, fetchBingus } from "../util.js"; @@ -40,12 +42,27 @@ export const replyListContext: ContextMenu = { const show = new ButtonBuilder() .setCustomId('show') .setLabel("Show message") - .setStyle(ButtonStyle.Primary); + .setStyle(ButtonStyle.Primary) - const showB = new ActionRowBuilder() - .addComponents(show); - + + const embedListEph = new EmbedList(show); + embedListEph.push( + ...data.slice(0, 5).map( + (res) => + new EmbedBuilder() + .setAuthor({ + name: `Triggered by ${interaction.user.displayName}`, + iconURL: interaction.user.avatarURL() ?? undefined, + }) + .setTitle(res.title) + .setDescription(res.text) + .setColor("#65459A") + .setFooter({ text: `(${res.relevance.toFixed()}% relevant)` }) + .data, + ), + ); + const embedList = new EmbedList(); embedList.push( ...data.slice(0, 5).map( @@ -62,30 +79,23 @@ export const replyListContext: ContextMenu = { .data, ), ); - const targetChannel = interaction.targetMessage.channel - - await embedList.sendChatInput(interaction); - - const message = await interaction.followUp({ - flags: MessageFlags.Ephemeral, - components: [showB] - }); + const targetChannel = interaction.targetMessage.channel - - await message.awaitMessageComponent() - - interaction.deleteReply(); - interaction.deleteReply(message); - - embedList.sendChannel( - targetChannel, - interaction.user.id, - undefined, - { - messageReference: interaction.targetMessage}, - ); + const collector = await embedListEph.sendChatInput(interaction) + + collector.on("collect", async (i) => { + if (i.customId === "show") { + embedList.sendChannel( + targetChannel, + interaction.user.id, + undefined, + { + messageReference: interaction.targetMessage}, + ); + } + }); } catch (error) { console.error(error); diff --git a/bingus-bot/src/util.ts b/bingus-bot/src/util.ts index 8d57446..9148082 100644 --- a/bingus-bot/src/util.ts +++ b/bingus-bot/src/util.ts @@ -11,6 +11,7 @@ import { ReplyOptions, SendableChannels, } from "discord.js"; +import { NONAME } from "dns"; export const BINGUS_SITE = process.env.BINGUS_SITE || "https://bingus.slimevr.io"; @@ -34,11 +35,18 @@ export interface BingusFaqResponse { text: string; } + + export class EmbedList { static MAX_TIME = 300_000; embeds: APIEmbed[] = []; + _eph?: ButtonBuilder; index = 0; + constructor(eph?: ButtonBuilder){ + this._eph = eph; + } + push(...embed: APIEmbed[]): number { return this.embeds.push(...embed); } @@ -56,7 +64,7 @@ export class EmbedList { .setStyle(ButtonStyle.Secondary) .setDisabled(this.index === 0); - return new ActionRowBuilder().addComponents(prev, next); + return new ActionRowBuilder().addComponents(prev, next, ...(this._eph ? [this._eph] : [])); } get(): EmbedBuilder { @@ -73,6 +81,7 @@ export class EmbedList { content?: string, reply?: ReplyOptions, ) { + const edit = await channel.send({ content, embeds: [this.get()], @@ -101,6 +110,7 @@ export class EmbedList { return; } this.index--; + } await i.update({ @@ -151,6 +161,13 @@ export class EmbedList { return; } this.index--; + break; + case "show": + interaction.editReply({ + content: "Replied to message!", + embeds: [], + components: [] + }); } await i.update({ From 68a43bfc61347c0dbd236e452e23e89d6f3e4578 Mon Sep 17 00:00:00 2001 From: Aed Date: Thu, 31 Jul 2025 23:18:32 +0100 Subject: [PATCH 11/16] added embed to util.ts --- bingus-bot/src/contexts/reply.ts | 27 +++----------------- bingus-bot/src/contexts/replyWithList.ts | 28 +++------------------ bingus-bot/src/util.ts | 32 ++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 49 deletions(-) diff --git a/bingus-bot/src/contexts/reply.ts b/bingus-bot/src/contexts/reply.ts index 921aed2..11ff221 100644 --- a/bingus-bot/src/contexts/reply.ts +++ b/bingus-bot/src/contexts/reply.ts @@ -4,11 +4,10 @@ import { ButtonBuilder, ButtonStyle, ContextMenuCommandBuilder, - EmbedBuilder, MessageFlags, } from "discord.js"; import { ContextMenu } from "../index.js"; -import { fetchBingus } from "../util.js"; +import { fetchBingus, replyEmbed} from "../util.js"; export const replyContext: ContextMenu = { builder: new ContextMenuCommandBuilder() @@ -39,17 +38,7 @@ export const replyContext: ContextMenu = { const message = await interaction.editReply({ embeds: [ - new EmbedBuilder() - .setAuthor({ - name: `Triggered by ${interaction.user.displayName}`, - iconURL: interaction.user.avatarURL() ?? undefined, - }) - .setTitle(data[0].title) - .setDescription(data[0].text) - .setColor("#65459A") - .setFooter({ text: `${data[0].relevance.toFixed()}% relevant` }) - .data, - + replyEmbed(interaction, data) ], components: [new ActionRowBuilder().addComponents(show)], }); @@ -63,17 +52,7 @@ export const replyContext: ContextMenu = { }); interaction.targetMessage.reply({ embeds: [ - new EmbedBuilder() - .setAuthor({ - name: `Triggered by ${interaction.user.displayName}`, - iconURL: interaction.user.avatarURL() ?? undefined, - }) - .setTitle(data[0].title) - .setDescription(data[0].text) - .setColor("#65459A") - .setFooter({text: `${data[0].relevance.toFixed()}% relevant` }) - .data, - + replyEmbed(interaction, data) ], }); diff --git a/bingus-bot/src/contexts/replyWithList.ts b/bingus-bot/src/contexts/replyWithList.ts index 2af7293..835f8ca 100644 --- a/bingus-bot/src/contexts/replyWithList.ts +++ b/bingus-bot/src/contexts/replyWithList.ts @@ -1,16 +1,12 @@ import { - ActionRowBuilder, ApplicationCommandType, ButtonBuilder, ContextMenuCommandBuilder, ButtonStyle, - EmbedBuilder, MessageFlags, - ComponentType, - ButtonInteraction, } from "discord.js"; import { ContextMenu } from "../index.js"; -import { EmbedList, fetchBingus } from "../util.js"; +import { EmbedList, fetchBingus, replyEmbedList } from "../util.js"; export const replyListContext: ContextMenu = { builder: new ContextMenuCommandBuilder() @@ -50,16 +46,7 @@ export const replyListContext: ContextMenu = { embedListEph.push( ...data.slice(0, 5).map( (res) => - new EmbedBuilder() - .setAuthor({ - name: `Triggered by ${interaction.user.displayName}`, - iconURL: interaction.user.avatarURL() ?? undefined, - }) - .setTitle(res.title) - .setDescription(res.text) - .setColor("#65459A") - .setFooter({ text: `(${res.relevance.toFixed()}% relevant)` }) - .data, + replyEmbedList(interaction, res) ), ); @@ -67,16 +54,7 @@ export const replyListContext: ContextMenu = { embedList.push( ...data.slice(0, 5).map( (res) => - new EmbedBuilder() - .setAuthor({ - name: `Triggered by ${interaction.user.displayName}`, - iconURL: interaction.user.avatarURL() ?? undefined, - }) - .setTitle(res.title) - .setDescription(res.text) - .setColor("#65459A") - .setFooter({ text: `(${res.relevance.toFixed()}% relevant)` }) - .data, + replyEmbedList(interaction, res) ), ); diff --git a/bingus-bot/src/util.ts b/bingus-bot/src/util.ts index 9148082..7563d3b 100644 --- a/bingus-bot/src/util.ts +++ b/bingus-bot/src/util.ts @@ -35,6 +35,38 @@ export interface BingusFaqResponse { text: string; } +export function replyEmbed(interaction:MessageContextMenuCommandInteraction, data:BingusFaqResponse[]) { + + const embedBuilder = new EmbedBuilder() + .setAuthor({ + name: `Triggered by ${interaction.user.displayName}`, + iconURL: interaction.user.avatarURL() ?? undefined, + }) + .setTitle(data[0].title) + .setDescription(data[0].text) + .setColor("#65459A") + .setFooter({ text: `${data[0].relevance.toFixed()}% relevant` }) + .data + + return embedBuilder; +} + +export function replyEmbedList(interaction:MessageContextMenuCommandInteraction, res:BingusFaqResponse) { + + const embedBuilder = new EmbedBuilder() + .setAuthor({ + name: `Triggered by ${interaction.user.displayName}`, + iconURL: interaction.user.avatarURL() ?? undefined, + }) + .setTitle(res.title) + .setDescription(res.text) + .setColor("#65459A") + .setFooter({ text: `${res.relevance.toFixed()}% relevant` }) + .data + + return embedBuilder; +} + export class EmbedList { From e0958563902707710e74042da54dc76f0db5e4d4 Mon Sep 17 00:00:00 2001 From: Aed Date: Thu, 31 Jul 2025 23:37:35 +0100 Subject: [PATCH 12/16] combined the functions in util.ts# --- bingus-bot/src/contexts/reply.ts | 4 ++-- bingus-bot/src/contexts/replyWithList.ts | 6 +++--- bingus-bot/src/util.ts | 18 +----------------- 3 files changed, 6 insertions(+), 22 deletions(-) diff --git a/bingus-bot/src/contexts/reply.ts b/bingus-bot/src/contexts/reply.ts index 11ff221..c112f23 100644 --- a/bingus-bot/src/contexts/reply.ts +++ b/bingus-bot/src/contexts/reply.ts @@ -38,7 +38,7 @@ export const replyContext: ContextMenu = { const message = await interaction.editReply({ embeds: [ - replyEmbed(interaction, data) + replyEmbed(interaction, data[0]) ], components: [new ActionRowBuilder().addComponents(show)], }); @@ -52,7 +52,7 @@ export const replyContext: ContextMenu = { }); interaction.targetMessage.reply({ embeds: [ - replyEmbed(interaction, data) + replyEmbed(interaction, data[0]) ], }); diff --git a/bingus-bot/src/contexts/replyWithList.ts b/bingus-bot/src/contexts/replyWithList.ts index 835f8ca..7d0bd76 100644 --- a/bingus-bot/src/contexts/replyWithList.ts +++ b/bingus-bot/src/contexts/replyWithList.ts @@ -6,7 +6,7 @@ import { MessageFlags, } from "discord.js"; import { ContextMenu } from "../index.js"; -import { EmbedList, fetchBingus, replyEmbedList } from "../util.js"; +import { EmbedList, fetchBingus, replyEmbed } from "../util.js"; export const replyListContext: ContextMenu = { builder: new ContextMenuCommandBuilder() @@ -46,7 +46,7 @@ export const replyListContext: ContextMenu = { embedListEph.push( ...data.slice(0, 5).map( (res) => - replyEmbedList(interaction, res) + replyEmbed(interaction, res) ), ); @@ -54,7 +54,7 @@ export const replyListContext: ContextMenu = { embedList.push( ...data.slice(0, 5).map( (res) => - replyEmbedList(interaction, res) + replyEmbed(interaction, res) ), ); diff --git a/bingus-bot/src/util.ts b/bingus-bot/src/util.ts index 7563d3b..1243492 100644 --- a/bingus-bot/src/util.ts +++ b/bingus-bot/src/util.ts @@ -35,23 +35,7 @@ export interface BingusFaqResponse { text: string; } -export function replyEmbed(interaction:MessageContextMenuCommandInteraction, data:BingusFaqResponse[]) { - - const embedBuilder = new EmbedBuilder() - .setAuthor({ - name: `Triggered by ${interaction.user.displayName}`, - iconURL: interaction.user.avatarURL() ?? undefined, - }) - .setTitle(data[0].title) - .setDescription(data[0].text) - .setColor("#65459A") - .setFooter({ text: `${data[0].relevance.toFixed()}% relevant` }) - .data - - return embedBuilder; -} - -export function replyEmbedList(interaction:MessageContextMenuCommandInteraction, res:BingusFaqResponse) { +export function replyEmbed(interaction:MessageContextMenuCommandInteraction, res:any) { const embedBuilder = new EmbedBuilder() .setAuthor({ From 14bec348dea18f5fc6df49eb7d30b23b05935737 Mon Sep 17 00:00:00 2001 From: Aed Date: Fri, 1 Aug 2025 00:00:48 +0100 Subject: [PATCH 13/16] removed any type --- bingus-bot/src/contexts/reply.ts | 6 +++--- bingus-bot/src/util.ts | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/bingus-bot/src/contexts/reply.ts b/bingus-bot/src/contexts/reply.ts index c112f23..668bda6 100644 --- a/bingus-bot/src/contexts/reply.ts +++ b/bingus-bot/src/contexts/reply.ts @@ -35,10 +35,10 @@ export const replyContext: ContextMenu = { .setLabel("Show message") .setStyle(ButtonStyle.Primary); - + const data0 = data[0] const message = await interaction.editReply({ embeds: [ - replyEmbed(interaction, data[0]) + replyEmbed(interaction, data0) ], components: [new ActionRowBuilder().addComponents(show)], }); @@ -52,7 +52,7 @@ export const replyContext: ContextMenu = { }); interaction.targetMessage.reply({ embeds: [ - replyEmbed(interaction, data[0]) + replyEmbed(interaction, data0) ], }); diff --git a/bingus-bot/src/util.ts b/bingus-bot/src/util.ts index 1243492..db9d16f 100644 --- a/bingus-bot/src/util.ts +++ b/bingus-bot/src/util.ts @@ -35,7 +35,7 @@ export interface BingusFaqResponse { text: string; } -export function replyEmbed(interaction:MessageContextMenuCommandInteraction, res:any) { +export function replyEmbed(interaction:MessageContextMenuCommandInteraction, res:BingusFaqResponse) { const embedBuilder = new EmbedBuilder() .setAuthor({ @@ -126,6 +126,7 @@ export class EmbedList { return; } this.index--; + break; } From 9788048a860ad334b272771999ed239bc2671cd7 Mon Sep 17 00:00:00 2001 From: Aed Date: Sat, 2 Aug 2025 04:02:36 +0100 Subject: [PATCH 14/16] made replyWithList send only the one selected --- bingus-bot/src/contexts/replyWithList.ts | 31 +++++------------------- bingus-bot/src/util.ts | 28 +++++++++++++++++---- 2 files changed, 29 insertions(+), 30 deletions(-) diff --git a/bingus-bot/src/contexts/replyWithList.ts b/bingus-bot/src/contexts/replyWithList.ts index 7d0bd76..1988582 100644 --- a/bingus-bot/src/contexts/replyWithList.ts +++ b/bingus-bot/src/contexts/replyWithList.ts @@ -40,8 +40,6 @@ export const replyListContext: ContextMenu = { .setLabel("Show message") .setStyle(ButtonStyle.Primary) - - const embedListEph = new EmbedList(show); embedListEph.push( ...data.slice(0, 5).map( @@ -49,30 +47,13 @@ export const replyListContext: ContextMenu = { replyEmbed(interaction, res) ), ); - - const embedList = new EmbedList(); - embedList.push( - ...data.slice(0, 5).map( - (res) => - replyEmbed(interaction, res) - ), - ); + + const {finalIndex} = await embedListEph.sendChatInput(interaction) - - const targetChannel = interaction.targetMessage.channel - - const collector = await embedListEph.sendChatInput(interaction) - - collector.on("collect", async (i) => { - if (i.customId === "show") { - embedList.sendChannel( - targetChannel, - interaction.user.id, - undefined, - { - messageReference: interaction.targetMessage}, - ); - } + const selectedIndex = await finalIndex; + + interaction.targetMessage.reply({ + embeds: [replyEmbed(interaction, data[selectedIndex])], }); } catch (error) { diff --git a/bingus-bot/src/util.ts b/bingus-bot/src/util.ts index db9d16f..dc4a989 100644 --- a/bingus-bot/src/util.ts +++ b/bingus-bot/src/util.ts @@ -51,7 +51,9 @@ export function replyEmbed(interaction:MessageContextMenuCommandInteraction, res return embedBuilder; } - +type promiseResult = { + finalIndex: Promise; +}; export class EmbedList { static MAX_TIME = 300_000; @@ -141,10 +143,19 @@ export class EmbedList { }); } + + async sendChatInput( interaction: ChatInputCommandInteraction | MessageContextMenuCommandInteraction, publicInteraction: boolean | undefined = true, - ) { + ): Promise { + + let resolvePromise: (value: number) => void; + + const finalPromise = new Promise((resolve) => { + resolvePromise = resolve; + }); + const reply = await (interaction.deferred ? interaction.editReply({ embeds: [this.get()], @@ -162,7 +173,6 @@ export class EmbedList { ? (i) => i.user.id === interaction.user.id : undefined, }); - collector.on("collect", async (i) => { switch (i.customId) { case "next": @@ -180,6 +190,7 @@ export class EmbedList { this.index--; break; case "show": + resolvePromise(this.index); interaction.editReply({ content: "Replied to message!", embeds: [], @@ -191,16 +202,23 @@ export class EmbedList { embeds: [this.get()], components: [this.getActionRow()], }); - }); + }); collector.on("end", async () => { await interaction.editReply({ components: [] }); }); - return collector; + return {finalIndex:finalPromise}; } + + + } + + + + export interface FaqConfig { faqs: { title: string; From 4330d0110abd34e5946fabe35dde68e87a3fde64 Mon Sep 17 00:00:00 2001 From: Butterscotch! Date: Tue, 5 Aug 2025 20:40:32 -0400 Subject: [PATCH 15/16] Code reformat & clean-up --- bingus-bot/src/contexts/reply.ts | 36 +++++++++---------- bingus-bot/src/contexts/replyWithList.ts | 19 +++++----- bingus-bot/src/util.ts | 46 ++++++++---------------- 3 files changed, 39 insertions(+), 62 deletions(-) diff --git a/bingus-bot/src/contexts/reply.ts b/bingus-bot/src/contexts/reply.ts index 668bda6..d9bbba7 100644 --- a/bingus-bot/src/contexts/reply.ts +++ b/bingus-bot/src/contexts/reply.ts @@ -7,7 +7,7 @@ import { MessageFlags, } from "discord.js"; import { ContextMenu } from "../index.js"; -import { fetchBingus, replyEmbed} from "../util.js"; +import { EmbedList, fetchBingus, replyEmbed } from "../util.js"; export const replyContext: ContextMenu = { builder: new ContextMenuCommandBuilder() @@ -23,43 +23,39 @@ export const replyContext: ContextMenu = { try { await interaction.deferReply({ flags: MessageFlags.Ephemeral }); - const data = await fetchBingus(query); - if (data.length === 0) { + const data = (await fetchBingus(query))[0]; + if (!data) { await interaction.editReply("No results found."); return; } const show = new ButtonBuilder() - .setCustomId('show') - .setLabel("Show message") - .setStyle(ButtonStyle.Primary); + .setCustomId('show') + .setLabel("Show message") + .setStyle(ButtonStyle.Primary); - const data0 = data[0] const message = await interaction.editReply({ embeds: [ - replyEmbed(interaction, data0) + replyEmbed(interaction, data) ], components: [new ActionRowBuilder().addComponents(show)], }); - await message.awaitMessageComponent() + await message.awaitMessageComponent({ + time: EmbedList.MAX_TIME + }) interaction.editReply({ - content: "Replied to message!", - embeds: [], - components: [] - }); + content: "Replied to message!", + embeds: [], + components: [] + }); interaction.targetMessage.reply({ - embeds: [ - replyEmbed(interaction, data0) + embeds: [ + replyEmbed(interaction, data) ], }); - - - - - } catch (error) { console.error(error); interaction.editReply("An error occurred while fetching results."); diff --git a/bingus-bot/src/contexts/replyWithList.ts b/bingus-bot/src/contexts/replyWithList.ts index 1988582..c8fea0e 100644 --- a/bingus-bot/src/contexts/replyWithList.ts +++ b/bingus-bot/src/contexts/replyWithList.ts @@ -29,16 +29,15 @@ export const replyListContext: ContextMenu = { } const data = await fetchBingus(query); - if (data.length === 0) { await interaction.editReply("No results found."); return; } const show = new ButtonBuilder() - .setCustomId('show') - .setLabel("Show message") - .setStyle(ButtonStyle.Primary) + .setCustomId('show') + .setLabel("Show message") + .setStyle(ButtonStyle.Primary) const embedListEph = new EmbedList(show); embedListEph.push( @@ -47,14 +46,12 @@ export const replyListContext: ContextMenu = { replyEmbed(interaction, res) ), ); - - const {finalIndex} = await embedListEph.sendChatInput(interaction) - const selectedIndex = await finalIndex; - - interaction.targetMessage.reply({ - embeds: [replyEmbed(interaction, data[selectedIndex])], - }); + const selectedIndex = await embedListEph.sendChatInput(interaction) + + interaction.targetMessage.reply({ + embeds: [replyEmbed(interaction, data[selectedIndex])], + }); } catch (error) { console.error(error); diff --git a/bingus-bot/src/util.ts b/bingus-bot/src/util.ts index dc4a989..6d34e5d 100644 --- a/bingus-bot/src/util.ts +++ b/bingus-bot/src/util.ts @@ -11,7 +11,6 @@ import { ReplyOptions, SendableChannels, } from "discord.js"; -import { NONAME } from "dns"; export const BINGUS_SITE = process.env.BINGUS_SITE || "https://bingus.slimevr.io"; @@ -35,7 +34,7 @@ export interface BingusFaqResponse { text: string; } -export function replyEmbed(interaction:MessageContextMenuCommandInteraction, res:BingusFaqResponse) { +export function replyEmbed(interaction: MessageContextMenuCommandInteraction, res: BingusFaqResponse) { const embedBuilder = new EmbedBuilder() .setAuthor({ @@ -51,17 +50,13 @@ export function replyEmbed(interaction:MessageContextMenuCommandInteraction, res return embedBuilder; } -type promiseResult = { - finalIndex: Promise; -}; - export class EmbedList { - static MAX_TIME = 300_000; + static readonly MAX_TIME = 300_000; embeds: APIEmbed[] = []; _eph?: ButtonBuilder; index = 0; - constructor(eph?: ButtonBuilder){ + constructor(eph?: ButtonBuilder) { this._eph = eph; } @@ -88,9 +83,8 @@ export class EmbedList { get(): EmbedBuilder { const embed = this.embeds[this.index]; return new EmbedBuilder(embed).setFooter({ - text: `${this.index + 1}/${this.embeds.length} ${ - embed.footer?.text - }`.trim(), + text: `${this.index + 1}/${this.embeds.length} ${embed.footer?.text + }`.trim(), }); } async sendChannel( @@ -129,7 +123,6 @@ export class EmbedList { } this.index--; break; - } await i.update({ @@ -143,28 +136,25 @@ export class EmbedList { }); } - - async sendChatInput( interaction: ChatInputCommandInteraction | MessageContextMenuCommandInteraction, publicInteraction: boolean | undefined = true, - ): Promise { + ): Promise { let resolvePromise: (value: number) => void; - - const finalPromise = new Promise((resolve) => { + const indexPromise = new Promise((resolve) => { resolvePromise = resolve; }); const reply = await (interaction.deferred ? interaction.editReply({ - embeds: [this.get()], - components: [this.getActionRow()], - }) + embeds: [this.get()], + components: [this.getActionRow()], + }) : interaction.reply({ - embeds: [this.get()], - components: [this.getActionRow()], - })); + embeds: [this.get()], + components: [this.getActionRow()], + })); const collector = reply.createMessageComponentCollector({ componentType: ComponentType.Button, @@ -173,6 +163,7 @@ export class EmbedList { ? (i) => i.user.id === interaction.user.id : undefined, }); + collector.on("collect", async (i) => { switch (i.customId) { case "next": @@ -208,17 +199,10 @@ export class EmbedList { await interaction.editReply({ components: [] }); }); - return {finalIndex:finalPromise}; + return indexPromise; } - - - } - - - - export interface FaqConfig { faqs: { title: string; From 4a466c422337fa2bcb17e78334d575a325b159f8 Mon Sep 17 00:00:00 2001 From: Butterscotch! Date: Tue, 5 Aug 2025 20:46:58 -0400 Subject: [PATCH 16/16] Fix closing bracket position --- bingus-bot/src/util.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bingus-bot/src/util.ts b/bingus-bot/src/util.ts index 6d34e5d..ecf1bbc 100644 --- a/bingus-bot/src/util.ts +++ b/bingus-bot/src/util.ts @@ -193,8 +193,8 @@ export class EmbedList { embeds: [this.get()], components: [this.getActionRow()], }); - }); + collector.on("end", async () => { await interaction.editReply({ components: [] }); });