This commit is contained in:
parent
e82b8b05d2
commit
fde47d8b77
@ -26,51 +26,56 @@ module.exports = {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
const AsciiTable = require('ascii-table');
|
try {
|
||||||
|
const [rows] = await conn.execute('SELECT discord_id, discord_username, cargo FROM users');
|
||||||
|
|
||||||
|
if (rows.length === 0) {
|
||||||
|
await interaction.editReply('Nenhum membro encontrado.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const table = new AsciiTable()
|
// Primeiro, calcula o tamanho máximo de cada coluna
|
||||||
.setHeading('discord_id', 'discord_username', 'cargo');
|
let maxDiscordIdLength = 'Discord ID'.length;
|
||||||
|
let maxUsernameLength = 'Username'.length;
|
||||||
|
let maxCargoLength = 'Cargo'.length;
|
||||||
|
|
||||||
try {
|
rows.forEach(row => {
|
||||||
// Realizando a consulta ao banco de dados
|
maxDiscordIdLength = Math.max(maxDiscordIdLength, String(row.discord_id).length);
|
||||||
const [rows] = await conn.execute('SELECT discord_id, discord_username, cargo FROM users'); // Altere para a sua consulta
|
maxUsernameLength = Math.max(maxUsernameLength, row.discord_username.length);
|
||||||
|
maxCargoLength = Math.max(maxCargoLength, row.cargo.length);
|
||||||
|
});
|
||||||
|
|
||||||
// Adicionando as linhas de dados à tabela
|
// Cria cabeçalho
|
||||||
rows.forEach(row => {
|
const header =
|
||||||
table.addRow(row.discord_id, `<@${row.discord_username}>`, row.cargo);
|
padRight('Discord ID', maxDiscordIdLength) + ' | ' +
|
||||||
});
|
padRight('Username', maxUsernameLength) + ' | ' +
|
||||||
|
padRight('Cargo', maxCargoLength);
|
||||||
|
|
||||||
let tabelaString = table.toString();
|
const separator =
|
||||||
|
'-'.repeat(maxDiscordIdLength) + '-|-' +
|
||||||
|
'-'.repeat(maxUsernameLength) + '-|-' +
|
||||||
|
'-'.repeat(maxCargoLength);
|
||||||
|
|
||||||
// Filtrando: remover linhas que começam com '+' ou '\'
|
// Monta as linhas
|
||||||
let linhas = tabelaString.split('\n').filter(linha => {
|
const linhas = rows.map(row =>
|
||||||
return !linha.startsWith('+') && !linha.startsWith('\'') && !linha.startsWith('.');
|
padRight(String(row.discord_id), maxDiscordIdLength) + ' | ' +
|
||||||
});
|
padRight(row.discord_username, maxUsernameLength) + ' | ' +
|
||||||
|
padRight(row.cargo, maxCargoLength)
|
||||||
|
);
|
||||||
|
|
||||||
let tabelaSemBorda = linhas.join('\n');
|
const tabelaFinal = [header, separator, ...linhas].join('\n');
|
||||||
|
|
||||||
// Criando o embed para mostrar a tabela
|
await interaction.editReply(`\`\`\`fix\n${tabelaFinal}\n\`\`\``);
|
||||||
// const embed = new EmbedBuilder()
|
|
||||||
// .setTitle('📋 Informações dos Membros')
|
|
||||||
// .setColor('Green')
|
|
||||||
// .setDescription(`
|
|
||||||
// \`\`\`
|
|
||||||
// ${tabelaSemBorda}
|
|
||||||
// \`\`\`
|
|
||||||
// `)
|
|
||||||
// .setFooter({ text: 'Adicionado à base de dados ✅' });
|
|
||||||
|
|
||||||
// await interaction.editReply({ embeds: [embed] });
|
} catch (error) {
|
||||||
|
console.error('Erro ao acessar o banco de dados:', error);
|
||||||
|
await interaction.editReply({ content: 'Erro ao carregar os dados dos membros!' });
|
||||||
|
}
|
||||||
|
|
||||||
|
// Função para preencher à direita
|
||||||
await interaction.editReply(`\`\`\`${tabelaSemBorda}\`\`\``);
|
function padRight(text, length) {
|
||||||
|
return text + ' '.repeat(length - text.length);
|
||||||
|
}
|
||||||
} catch (error) {
|
|
||||||
console.error('Erro ao acessar o banco de dados:', error);
|
|
||||||
await interaction.editReply({ content: 'Erro ao carregar os dados dos membros!' });
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user