Skip to content

Commit 46c4703

Browse files
committed
Help button
1 parent c202f89 commit 46c4703

File tree

3 files changed

+56
-1
lines changed

3 files changed

+56
-1
lines changed

src/commands/utility/button.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export class ButtonCommand implements Command {
7373
}
7474

7575
await interaction.channel.send({
76-
content: message,
76+
content: message.replaceAll('\\n', '\n'),
7777
components: [row],
7878
});
7979

src/configuration.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const toml = TOML.parse(readFileSync(configFile, 'utf8')) as {
2525
submission: {
2626
questions: string[];
2727
role: string;
28+
help_thread: string;
2829
};
2930
};
3031

@@ -45,6 +46,7 @@ const configuration = {
4546
submission: {
4647
questions: toml.submission.questions,
4748
role: toml.submission.role,
49+
helpThread: toml.submission.help_thread,
4850
},
4951
};
5052

@@ -133,3 +135,10 @@ if (
133135
) {
134136
throw 'Config: application.role is required';
135137
}
138+
139+
if (
140+
typeof configuration.submission.helpThread !== 'string' ||
141+
configuration.submission.helpThread.length === 0
142+
) {
143+
throw 'Config: application.help_thread is required';
144+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { type ButtonInteraction, MessageFlags, TextChannel } from 'discord.js';
2+
3+
import configuration from '@/configuration';
4+
import type { PermanentButtonInteraction } from '@/types';
5+
6+
export const customId = 'submissionHelpButton';
7+
8+
export class HelpSubmissionButton implements PermanentButtonInteraction {
9+
public customId = customId;
10+
public async execute(interaction: ButtonInteraction) {
11+
if (!(interaction.channel instanceof TextChannel)) return;
12+
13+
const threadManager = await interaction.channel.threads.fetch();
14+
15+
const thread = threadManager.threads.find(
16+
(thread) => thread.id === configuration.submission.helpThread
17+
);
18+
19+
if (thread) {
20+
const members = await thread.members.fetch();
21+
22+
if (!members.some((member) => member.id === interaction.user.id)) {
23+
await thread.members.add(interaction.user);
24+
25+
await interaction.reply({
26+
content: `Yardım alt başlığına eklendin: ${thread}`,
27+
flags: MessageFlags.Ephemeral,
28+
});
29+
30+
return;
31+
}
32+
33+
await interaction.reply({
34+
content: `Zaten yardım alt başlığında bulunuyorsun: ${thread}`,
35+
flags: MessageFlags.Ephemeral,
36+
});
37+
38+
return;
39+
}
40+
41+
await interaction.reply({
42+
content: 'Bu seçenek şu anda kullanılamıyor.',
43+
flags: MessageFlags.Ephemeral,
44+
});
45+
}
46+
}

0 commit comments

Comments
 (0)