Skip to content
This repository was archived by the owner on Oct 9, 2025. It is now read-only.
Draft
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
53 changes: 38 additions & 15 deletions src/interactions/RulesScreening.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,24 +258,47 @@ export default class RulesScreeningInteraction {
return;
}

await db.hubRulesAcceptance.create({
data: {
userId,
hubId,
},
});
try {
await db.hubRulesAcceptance.upsert({
where: {
userId_hubId: {
userId,
hubId
}
},
update: {}, // No updates - preserve the original acceptedAt timestamp
create: {
userId,
hubId
}
});

await interaction.deleteReply();
await interaction.deleteReply();

const locale = await fetchUserLocale(interaction.user.id);
const embed = new InfoEmbed().setDescription(
t('rules.hubAccepted', locale, {
emoji: getEmoji('tick_icon', interaction.client),
}),
);
const locale = await fetchUserLocale(interaction.user.id);
const embed = new InfoEmbed().setDescription(
t('rules.hubAccepted', locale, {
emoji: getEmoji('tick_icon', interaction.client),
}),
);

await interaction.followUp({ embeds: [embed], components: [], flags: ['Ephemeral'] });
await this.redis.del(`${RedisKeys.RulesShown}:${interaction.user.id}:${hubId}`);
if (!interaction.replied) {
await interaction.followUp({ embeds: [embed], components: [], flags: ['Ephemeral'] });
await this.redis.del(`${RedisKeys.RulesShown}:${interaction.user.id}:${hubId}`);
}
} catch (error) {
Logger.error('Error while accepting hub rules:', error);
// Don't attempt to reply if the interaction was already replied to
if (!interaction.replied) {
const locale = await fetchUserLocale(interaction.user.id);
await interaction.followUp({
content: t('errors.generalError', locale, {
emoji: getEmoji('x_icon', interaction.client)
}),
flags: ['Ephemeral']
});
}
}
Comment on lines +285 to +301
Copy link

Copilot AI Apr 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The repeated check for '!interaction.replied' in both the main execution path and the error handling block could lead to subtle logic issues if the interaction state changes unexpectedly. Consider consolidating this logic to ensure the interaction is only replied to once.

Suggested change
if (!interaction.replied) {
await interaction.followUp({ embeds: [embed], components: [], flags: ['Ephemeral'] });
await this.redis.del(`${RedisKeys.RulesShown}:${interaction.user.id}:${hubId}`);
}
} catch (error) {
Logger.error('Error while accepting hub rules:', error);
// Don't attempt to reply if the interaction was already replied to
if (!interaction.replied) {
const locale = await fetchUserLocale(interaction.user.id);
await interaction.followUp({
content: t('errors.generalError', locale, {
emoji: getEmoji('x_icon', interaction.client)
}),
flags: ['Ephemeral']
});
}
}
await this.safeReply(interaction, {
embeds: [embed],
components: [],
flags: ['Ephemeral'],
});
await this.redis.del(`${RedisKeys.RulesShown}:${interaction.user.id}:${hubId}`);
} catch (error) {
Logger.error('Error while accepting hub rules:', error);
// Don't attempt to reply if the interaction was already replied to
const locale = await fetchUserLocale(interaction.user.id);
await this.safeReply(interaction, {
content: t('errors.generalError', locale, {
emoji: getEmoji('x_icon', interaction.client),
}),
flags: ['Ephemeral'],
});

Copilot uses AI. Check for mistakes.

}

@RegisterInteractionHandler('rulesScreen', 'decline')
Expand Down
Loading