Skip to content
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
2 changes: 2 additions & 0 deletions .env.production
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ REPEL_LOG_CHANNEL_ID=1403558160144531589
ADVENT_OF_CODE_CHANNEL_ID=1047623689488830495
SHOWCASE_CHANNEL_ID=1517161718818541658
SHOWCASE_LOG_CHANNEL_ID=1517565847982444634
SHOWCASE_RULES_CHANNEL_ID=1517948527098073158


# Role IDs (from your dev server)
REPEL_ROLE_ID=1002411741776461844
Expand Down
1 change: 1 addition & 0 deletions .env.test
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ ADVENT_OF_CODE_CHANNEL_ID=your_advent_of_code_forum_channel_id_here
REPEL_LOG_CHANNEL_ID=your-repel-log-channel-id
SHOWCASE_CHANNEL_ID=your-showcase-forum-channel-id
SHOWCASE_LOG_CHANNEL_ID=your-showcase-log-channel-id
SHOWCASE_RULES_CHANNEL_ID=your-showcase-rules-channel-id

# Role IDs (from your dev server)
REPEL_ROLE_ID=your-repel-role-id
Expand Down
1 change: 1 addition & 0 deletions src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const config = {
adventOfCode: requireEnv('ADVENT_OF_CODE_CHANNEL_ID'),
showcase: requireEnv('SHOWCASE_CHANNEL_ID'),
showcaseLogs: requireEnv('SHOWCASE_LOG_CHANNEL_ID'),
showcaseRules: requireEnv('SHOWCASE_RULES_CHANNEL_ID'),
},
onboarding: {
channelId: optionalEnv('ONBOARDING_CHANNEL_ID'),
Expand Down
40 changes: 13 additions & 27 deletions src/features/showcase/send-pinned-message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {
ActionRowBuilder,
ButtonBuilder,
ButtonStyle,
ChannelFlags,
type MessageActionRowComponentBuilder,
MessageFlags,
PermissionFlagsBits,
Expand All @@ -22,20 +21,15 @@ export const sendShowcasePinnedMessage = createSlashCommand({
execute: async (interaction) => {
await interaction.deferReply({ flags: MessageFlags.Ephemeral });
const showcaseChannel = interaction.guild?.channels.cache.get(
config.channelIds.showcase
config.channelIds.showcaseRules
);
if (showcaseChannel === undefined || !showcaseChannel.isThreadOnly()) {
if (showcaseChannel === undefined || !showcaseChannel.isTextBased()) {
await interaction.editReply({
content: 'Showcase channel not found or is not a forum channel.',
});
return;
}

const activeThreads = await showcaseChannel.threads.fetchActive();
const pinnedThread = activeThreads.threads.find((thread) =>
thread.flags.has(ChannelFlags.Pinned)
);

const guideLines = [
'Welcome to the Showcase channel! Please read the rules and guidelines before posting your content. Make sure to follow the format and include all necessary information. Happy sharing!',
'',
Expand All @@ -59,33 +53,25 @@ export const sendShowcasePinnedMessage = createSlashCommand({
.setStyle(ButtonStyle.Primary)
);

if (pinnedThread) {
if (!pinnedThread.locked) {
await pinnedThread.setLocked(true);
}
const message = await pinnedThread.fetchStarterMessage();
if (message !== null) {
await message.edit({
content: guideLines,
components: [actionRow],
});
}
const message = (
await showcaseChannel.messages.fetch({ limit: 1 })
).first();
if (message !== undefined) {
await message.edit({
content: guideLines,
components: [actionRow],
});

await interaction.editReply({
content: 'Showcase pinned message updated successfully.',
});
return;
}

const thread = await showcaseChannel.threads.create({
name: 'Rules and Guidelines',
message: {
content: guideLines,
components: [actionRow],
},
await showcaseChannel.send({
content: guideLines,
components: [actionRow],
});
void thread.pin();
void thread.setLocked(true);

await interaction.editReply({
content: 'Showcase pinned message sent successfully.',
Expand Down
Loading