Skip to content

Commit c0fa94a

Browse files
committed
Help button
1 parent c202f89 commit c0fa94a

File tree

4 files changed

+58
-1
lines changed

4 files changed

+58
-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+
}

src/events/interactionCreate/button/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ import type { PermanentButtonInteraction } from '@/types';
55
import * as approveSubmission from './approveSubmission';
66
import * as createApplication from './createSubmission';
77
import * as denySubmission from './denySubmission';
8+
import * as helpSubmission from './helpSubmission';
89

910
const buttonInteractions = new Map<string, PermanentButtonInteraction>();
1011

1112
for (const ButtonInteraction of Object.values({
1213
...approveSubmission,
1314
...createApplication,
1415
...denySubmission,
16+
...helpSubmission,
1517
})) {
1618
if (typeof ButtonInteraction === 'function') {
1719
const buttonInteraction = new ButtonInteraction();

0 commit comments

Comments
 (0)