Skip to content

Commit e1c5fa5

Browse files
committed
Add another option for ask command
1 parent 546fc51 commit e1c5fa5

File tree

5 files changed

+1778
-5333
lines changed

5 files changed

+1778
-5333
lines changed

bingus-bot/src/commands/ask.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import { Command } from "../index.js";
88
import { EmbedList, fetchBingus, fetchBingusData } from "../util.js";
99

1010
async function getFaqConfig() {
11-
return (await fetchBingusData()).faqs.flatMap(
12-
(x) => x.matched_questions.filter((x) => x.length > 0 && x.length <= 100),
13-
)
11+
return (await fetchBingusData()).faqs.flatMap((x) =>
12+
x.matched_questions.filter((x) => x.length > 0 && x.length <= 100),
13+
);
1414
}
1515

1616
let faqConfig = await getFaqConfig();
@@ -40,6 +40,10 @@ export const askCommand: Command = {
4040
name: "Visible",
4141
value: "VISIBLE",
4242
},
43+
{
44+
name: "Visible but only you can interact with it",
45+
value: "KINDA_VISIBLE",
46+
},
4347
{
4448
name: "Only first answer",
4549
value: "FIRST",
@@ -54,7 +58,9 @@ export const askCommand: Command = {
5458
console.log(`User ${interaction.user} asked about "${query}"`);
5559

5660
try {
57-
await interaction.deferReply({ flags: customOption === null ? MessageFlags.Ephemeral : undefined });
61+
await interaction.deferReply({
62+
flags: customOption === null ? MessageFlags.Ephemeral : undefined,
63+
});
5864
const data = await fetchBingus(query);
5965

6066
if (data.length === 0) {
@@ -69,7 +75,8 @@ export const askCommand: Command = {
6975
.setTitle(data[0].title)
7076
.setDescription(data[0].text)
7177
.setColor("#65459A")
72-
.setFooter({ text: `${data[0].relevance.toFixed()}% relevant` }).data,
78+
.setFooter({ text: `${data[0].relevance.toFixed()}% relevant` })
79+
.data,
7380
],
7481
});
7582

@@ -84,11 +91,12 @@ export const askCommand: Command = {
8491
.setTitle(res.title)
8592
.setDescription(res.text)
8693
.setColor("#65459A")
87-
.setFooter({ text: `(${res.relevance.toFixed()}% relevant)` }).data,
94+
.setFooter({ text: `(${res.relevance.toFixed()}% relevant)` })
95+
.data,
8896
),
8997
);
9098

91-
await embedList.sendChatInput(interaction);
99+
await embedList.sendChatInput(interaction, customOption === "KINDA_VISIBLE");
92100
} catch (error) {
93101
console.error(error);
94102
interaction.editReply("An error occurred while fetching results.");

bingus-bot/src/index.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ import {
1212
SlashCommandOptionsOnlyBuilder,
1313
UserContextMenuCommandInteraction,
1414
} from "discord.js";
15-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
16-
// @ts-ignore
17-
import auth from "../auth.json" assert { type: "json" };
15+
import auth from "../auth.json" with { type: "json" };
1816
import {
1917
BINGUS_EMOJI,
2018
EmbedList,

bingus-bot/src/util.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,10 @@ export class EmbedList {
114114
});
115115
}
116116

117-
async sendChatInput(interaction: ChatInputCommandInteraction) {
117+
async sendChatInput(
118+
interaction: ChatInputCommandInteraction,
119+
publicInteraction: boolean | undefined = true,
120+
) {
118121
const reply = await (interaction.deferred
119122
? interaction.editReply({
120123
embeds: [this.get()],
@@ -128,7 +131,9 @@ export class EmbedList {
128131
const collector = reply.createMessageComponentCollector({
129132
componentType: ComponentType.Button,
130133
time: EmbedList.MAX_TIME,
131-
// filter: (i) => i.user.id === interaction.user.id,
134+
filter: publicInteraction
135+
? (i) => i.user.id === interaction.user.id
136+
: undefined,
132137
});
133138

134139
collector.on("collect", async (i) => {

0 commit comments

Comments
 (0)