Skip to content

Commit

Permalink
Remove duplicate code for /logout and /forget
Browse files Browse the repository at this point in the history
  • Loading branch information
giorgi-o committed Feb 11, 2024
1 parent 4282988 commit 6fd6145
Showing 1 changed file with 1 addition and 37 deletions.
38 changes: 1 addition & 37 deletions discord/bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -979,43 +979,7 @@ client.on("interactionCreate", async (interaction) => {

break;
}
case "logout": {
const accountCount = getNumberOfAccounts(interaction.user.id);
if (accountCount === 0) return await interaction.reply({
embeds: [basicEmbed(s(interaction).error.NOT_REGISTERED)],
ephemeral: true
});

const targetAccount = interaction.options.get("account") && interaction.options.get("account").value;
if (targetAccount) {
const targetIndex = findTargetAccountIndex(interaction.user.id, targetAccount);

if (targetIndex === null) return await interaction.reply({
embeds: [basicEmbed(s(interaction).error.ACCOUNT_NOT_FOUND)],
ephemeral: true
});

if (targetIndex > accountCount) return await interaction.reply({
embeds: [basicEmbed(s(interaction).error.ACCOUNT_NUMBER_TOO_HIGH.f({ n: accountCount }))],
ephemeral: true
});

const usernameOfDeleted = deleteUser(interaction.user.id, targetIndex);

await interaction.reply({
embeds: [basicEmbed(s(interaction).info.SPECIFIC_ACCOUNT_DELETED.f({ n: targetIndex, u: usernameOfDeleted }, interaction))],
});
} else {
deleteWholeUser(interaction.user.id);
console.log(`${interaction.user.tag} deleted their account`);

await interaction.reply({
embeds: [basicEmbed(s(interaction).info.ACCOUNT_DELETED)],
ephemeral: true
});
}
break;
}
case "logout":
case "forget": {
const accountCount = getNumberOfAccounts(interaction.user.id);
if (accountCount === 0) return await interaction.reply({
Expand Down

0 comments on commit 6fd6145

Please sign in to comment.