This commit is contained in:
parent
5c76647027
commit
f4e97efbaa
@ -14,74 +14,8 @@ const {
|
||||
|
||||
async execute(interaction) {
|
||||
|
||||
try {
|
||||
const userId = interaction.user.id;
|
||||
const [rows] = await conn.query('SELECT meta FROM users WHERE discord_id = ?', [userId]);
|
||||
|
||||
if (!rows.length || !rows[0].meta) {
|
||||
return interaction.reply({ content: '❌ Nenhuma meta encontrada.', ephemeral: true });
|
||||
}
|
||||
|
||||
let metas = {};
|
||||
try {
|
||||
metas = JSON.parse(rows[0].meta);
|
||||
} catch (err) {
|
||||
console.error('Erro ao analisar JSON de metas:', err);
|
||||
return interaction.reply({ content: '❌ Erro ao ler as metas do utilizador.', ephemeral: true });
|
||||
}
|
||||
|
||||
const chaves = Object.keys(metas);
|
||||
if (chaves.length === 0) {
|
||||
return interaction.reply({ content: '❌ Nenhuma meta definida ainda.', ephemeral: true });
|
||||
}
|
||||
|
||||
const options = chaves.map(key => ({
|
||||
label: key,
|
||||
value: key,
|
||||
}));
|
||||
|
||||
const select = new StringSelectMenuBuilder()
|
||||
.setCustomId('selecionarRecurso')
|
||||
.setPlaceholder('Escolhe o recurso...')
|
||||
.addOptions(options);
|
||||
|
||||
const rowSelect = new ActionRowBuilder().addComponents(select);
|
||||
const rowButton = new ActionRowBuilder().addComponents(
|
||||
new ButtonBuilder()
|
||||
.setCustomId('mostrarDropdown')
|
||||
.setLabel('Escolher Recurso')
|
||||
.setStyle(1) // Usando o valor numérico para PRIMARY (1)
|
||||
);
|
||||
|
||||
await interaction.reply({
|
||||
content: '🛠️ Clica no botão para escolher o recurso:',
|
||||
components: [rowButton],
|
||||
ephemeral: true,
|
||||
});
|
||||
|
||||
// Espera pelo clique no botão
|
||||
const filter = (i) => i.customId === 'mostrarDropdown' && i.user.id === interaction.user.id;
|
||||
const collector = interaction.channel.createMessageComponentCollector({ filter, time: 15000 });
|
||||
|
||||
collector.on('collect', async (i) => {
|
||||
if (i.customId === 'mostrarDropdown') {
|
||||
await i.update({
|
||||
content: '🛠️ Agora escolhe o recurso:',
|
||||
components: [rowSelect], // Exibe o menu de seleção após clicar no botão
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
collector.on('end', (collected) => {
|
||||
if (collected.size === 0) {
|
||||
interaction.editReply({ content: '❌ O tempo para escolher o recurso expirou.' });
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Erro ao buscar usuários:', error);
|
||||
await interaction.editReply({ content: '❌ Erro ao carregar informações dos usuários.' });
|
||||
}
|
||||
// Parte adicional que recupera e exibe informações de usuários e suas metas
|
||||
|
||||
// Parte adicional que recupera e exibe informações de usuários e suas metas
|
||||
try {
|
||||
const [usersRows] = await conn.execute('SELECT u.id, u.discord_id, u.discord_username, u.nig, u.meta, c.name AS nomedocargo FROM users u JOIN choices c ON u.cargo = c.value ORDER BY c.id DESC');
|
||||
const embed = new EmbedBuilder().setColor("#00b0f4");
|
||||
@ -114,12 +48,83 @@ const {
|
||||
});
|
||||
});
|
||||
|
||||
await interaction.editReply({ embeds: [embed] });
|
||||
await interaction.reply({ embeds: [embed] });
|
||||
|
||||
} catch (error) {
|
||||
console.error('Erro ao buscar usuários:', error);
|
||||
await interaction.reply({ content: '❌ Erro ao carregar informações dos usuários.' });
|
||||
}
|
||||
|
||||
|
||||
|
||||
try {
|
||||
const userId = interaction.user.id;
|
||||
const [rows] = await conn.query('SELECT meta FROM users WHERE discord_id = ?', [userId]);
|
||||
|
||||
if (!rows.length || !rows[0].meta) {
|
||||
return interaction.editReply({ content: '❌ Nenhuma meta encontrada.', ephemeral: true });
|
||||
}
|
||||
|
||||
let metas = {};
|
||||
try {
|
||||
metas = JSON.parse(rows[0].meta);
|
||||
} catch (err) {
|
||||
console.error('Erro ao analisar JSON de metas:', err);
|
||||
return interaction.editReply({ content: '❌ Erro ao ler as metas do utilizador.', ephemeral: true });
|
||||
}
|
||||
|
||||
const chaves = Object.keys(metas);
|
||||
if (chaves.length === 0) {
|
||||
return interaction.editReply({ content: '❌ Nenhuma meta definida ainda.', ephemeral: true });
|
||||
}
|
||||
|
||||
const options = chaves.map(key => ({
|
||||
label: key,
|
||||
value: key,
|
||||
}));
|
||||
|
||||
const select = new StringSelectMenuBuilder()
|
||||
.setCustomId('selecionarRecurso')
|
||||
.setPlaceholder('Escolhe o recurso...')
|
||||
.addOptions(options);
|
||||
|
||||
const rowSelect = new ActionRowBuilder().addComponents(select);
|
||||
const rowButton = new ActionRowBuilder().addComponents(
|
||||
new ButtonBuilder()
|
||||
.setCustomId('mostrarDropdown')
|
||||
.setLabel('Escolher Recurso')
|
||||
.setStyle(1) // Usando o valor numérico para PRIMARY (1)
|
||||
);
|
||||
|
||||
await interaction.editReply({
|
||||
content: '🛠️ Clica no botão para escolher o recurso:',
|
||||
components: [rowButton],
|
||||
ephemeral: true,
|
||||
});
|
||||
|
||||
// Espera pelo clique no botão
|
||||
const filter = (i) => i.customId === 'mostrarDropdown' && i.user.id === interaction.user.id;
|
||||
const collector = interaction.channel.createMessageComponentCollector({ filter, time: 15000 });
|
||||
|
||||
collector.on('collect', async (i) => {
|
||||
if (i.customId === 'mostrarDropdown') {
|
||||
await i.update({
|
||||
content: '🛠️ Agora escolhe o recurso:',
|
||||
components: [rowSelect], // Exibe o menu de seleção após clicar no botão
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
collector.on('end', (collected) => {
|
||||
if (collected.size === 0) {
|
||||
interaction.editReply({ content: '❌ O tempo para escolher o recurso expirou.' });
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Erro ao buscar usuários:', error);
|
||||
await interaction.editReply({ content: '❌ Erro ao carregar informações dos usuários.' });
|
||||
}
|
||||
|
||||
},
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user