AeThex-Bot-Master/aethex-bot/commands/verify-status.js
sirpiglr 73ff5bcce3 Add verification status command and improve verification process
Implement upsert for verification codes to fix race conditions, add a webhook listener for role assignment upon verification, introduce error handling for service unavailability, and create a new `/verify-status` command.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: aed2e46d-25bb-4b73-81a1-bb9e8437c261
Replit-Commit-Checkpoint-Type: intermediate_checkpoint
Replit-Commit-Event-Id: 9196f58c-47c2-4081-b01f-74e1fcdae7cd
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/3bdfff67-975a-46ad-9845-fbb6b4a4c4b5/aed2e46d-25bb-4b73-81a1-bb9e8437c261/3tJ1Z1J
Replit-Helium-Checkpoint-Created: true
2025-12-13 10:05:53 +00:00

105 lines
3.6 KiB
JavaScript

const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
module.exports = {
data: new SlashCommandBuilder()
.setName('verify-status')
.setDescription('Check your account verification status'),
async execute(interaction, supabase, client) {
if (!supabase) {
return interaction.reply({
content: 'This feature requires database configuration.',
ephemeral: true
});
}
await interaction.deferReply({ ephemeral: true });
try {
const { data: link } = await supabase
.from('discord_links')
.select('user_id, linked_at')
.eq('discord_id', interaction.user.id)
.maybeSingle();
const { data: pending } = await supabase
.from('discord_verifications')
.select('verification_code, expires_at')
.eq('discord_id', interaction.user.id)
.maybeSingle();
if (link) {
const linkedDate = new Date(link.linked_at).toLocaleDateString('en-US', {
year: 'numeric',
month: 'long',
day: 'numeric'
});
const embed = new EmbedBuilder()
.setColor(0x00ff00)
.setTitle('✅ Verified Account')
.setDescription('Your Discord account is linked to AeThex.')
.addFields(
{ name: '🔗 AeThex User ID', value: `\`${link.user_id}\``, inline: true },
{ name: '📅 Linked Since', value: linkedDate, inline: true }
)
.setFooter({ text: 'Use /unlink to remove this connection' });
return interaction.editReply({ embeds: [embed] });
}
if (pending) {
const expiresAt = new Date(pending.expires_at);
const now = new Date();
const expired = expiresAt < now;
if (expired) {
const embed = new EmbedBuilder()
.setColor(0xff9500)
.setTitle('⏰ Verification Expired')
.setDescription('Your previous verification code has expired.')
.addFields(
{ name: '💡 Next Step', value: 'Run `/verify` to generate a new code.' }
);
return interaction.editReply({ embeds: [embed] });
}
const remainingMs = expiresAt - now;
const remainingMins = Math.ceil(remainingMs / 60000);
const embed = new EmbedBuilder()
.setColor(0x7289da)
.setTitle('⏳ Verification Pending')
.setDescription('You have a pending verification code.')
.addFields(
{ name: '📝 Code', value: `\`${pending.verification_code}\``, inline: true },
{ name: '⏱️ Expires In', value: `${remainingMins} minute${remainingMins !== 1 ? 's' : ''}`, inline: true },
{ name: '💡 Next Step', value: 'Visit [aethex.dev/discord-verify](https://aethex.dev/discord-verify) to complete verification.' }
);
return interaction.editReply({ embeds: [embed] });
}
const embed = new EmbedBuilder()
.setColor(0xff5555)
.setTitle('❌ Not Verified')
.setDescription('Your Discord account is not linked to AeThex.')
.addFields(
{ name: '💡 Get Started', value: 'Run `/verify` to link your account and unlock exclusive features!' }
);
return interaction.editReply({ embeds: [embed] });
} catch (error) {
console.error('Verify status error:', error);
const embed = new EmbedBuilder()
.setColor(0xff0000)
.setTitle('❌ Error')
.setDescription('Failed to check verification status. Please try again.');
return interaction.editReply({ embeds: [embed] });
}
}
};