From 6678a3e6dcc7784a3eca3c44d72389f0c6eb5f2b Mon Sep 17 00:00:00 2001 From: Raphael Date: Sun, 27 Jul 2025 22:50:31 +0200 Subject: [PATCH] style(command/info): moving the old userinfo to info /w sub command --- src/commands/information/user.ts | 91 ------------------ src/commands/utils/info.ts | 158 +++++++++++++++++++++++++++++++ 2 files changed, 158 insertions(+), 91 deletions(-) delete mode 100644 src/commands/information/user.ts create mode 100644 src/commands/utils/info.ts diff --git a/src/commands/information/user.ts b/src/commands/information/user.ts deleted file mode 100644 index 691d8a4..0000000 --- a/src/commands/information/user.ts +++ /dev/null @@ -1,91 +0,0 @@ -import { prisma } from '../../lib/prisma.ts'; -import { MessageFlags, SlashCommandBuilder, EmbedBuilder } from 'discord.js'; - -function getUserRoles(target: GuildMember): string { - const roles = target.roles.cache - .filter(role => role.id !== target.guild.id) - .sort((a, b) => b.position - a.position) - .map(role => `<@&${role.id}>`); - - return roles.length > 0 ? roles.join(', ') : 'Aucun rôle'; -} - -function getUserBadges(userData: { - isDev?: boolean; - isEnium?: boolean; - isBuyer?: boolean; - isOwner?: boolean; -}): string { - const badges: string[] = []; - - if (userData.isDev) - badges.push("<:dev:1398755085441564772>"); - if (userData.isEnium) - badges.push("<:enium_staff:1398755055930179586>"); - if (userData.isPwn) - badges.push("<:dash:1398755072317325403>"); - if (userData.isBuyer) - badges.push(""); - if (userData.isOwner) - badges.push(""); - - return badges.length > 0 ? badges.join(" ") : "Aucun badge"; -} - -export default { - data: new SlashCommandBuilder() - .setName('userinfo') - .setDescription('Show the information of the user') - .addUserOption(option => - option.setName('target') - .setDescription('The user to get the information') - ), - async execute(interaction: CommandInteraction) { - const targetGlobal: GuildMember = interaction.options.getUser('target') || interaction.user; - let userData: User; - try { - userData = await prisma.user.findUnique({ - where: { - id: targetGlobal.id - } - }); - } catch (err) { - console.error(`\t⚠️ | USERINFO => Cannot get the database connection!\n\t\t(${err}).`); - } - let targetServer: GuildMember; - - try { - targetServer = await interaction.guild.members.fetch(targetGlobal.id); - } catch (err) { - console.error(`\t⚠️ | USERINFO => Cannot get the targetServer!\n\t\t(${err}).`); - return ; - } - - let toSend: EmbedBuilder = new EmbedBuilder() - .setTitle(`${targetGlobal.displayName}'s information`) - .setColor(`${targetServer.displayHexColor}`) - .setThumbnail(`${targetGlobal.displayAvatarURL()}`) - .setDescription(` - **👤 | Username:** - ${targetGlobal.username} - **🆔 | ID:** - ${targetGlobal.id} - - **🔰 | Roles:** - ${getUserRoles(targetServer)} - **🎖️ | Badges:** - ${getUserBadges(userData)} - - **🍼 | Account Creation:** - () - **🛬 | Server Join:** - () - `) - await interaction.reply({ - embeds: [ - toSend - ], - flags: MessageFlags.Ephemeral - }); - } -} diff --git a/src/commands/utils/info.ts b/src/commands/utils/info.ts new file mode 100644 index 0000000..e8b0a19 --- /dev/null +++ b/src/commands/utils/info.ts @@ -0,0 +1,158 @@ +import { prisma } from '../../lib/prisma.ts'; +import { userMention, roleMention, MessageFlags, SlashCommandBuilder, EmbedBuilder } from 'discord.js'; + +function getUserRoles(target: GuildMember): string { + const roles = target.roles.cache + .filter(role => role.id !== target.guild.id) + .sort((a, b) => b.position - a.position) + .map(role => `${roleMention(role.id)}`); + + return roles.length > 0 ? roles.join(', ') : 'Aucun rôle'; +} + +function getUserBadges(userData: { + isDev?: boolean; + isEnium?: boolean; + isBuyer?: boolean; + isOwner?: boolean; +}): string { + const badges: string[] = []; + + if (userData.isDev) + badges.push("<:dev:1398755085441564772>"); + if (userData.isEnium) + badges.push("<:enium_staff:1398755055930179586>"); + if (userData.isPwn) + badges.push("<:dash:1398755072317325403>"); + if (userData.isBuyer) + badges.push(""); + if (userData.isOwner) + badges.push(""); + + return badges.length > 0 ? badges.join(" ") : "Aucun badge"; +} + +export default { + data: new SlashCommandBuilder() + .setName('info') + .setDescription('Show the information of one of these cathegories (user, server, bot)') + .addSubcommand(subcommand => subcommand + .setName('user') + .setDescription('Show the information of one user') + .addUserOption(option => + option.setName('target') + .setDescription('The user to show the information') + ) + ) + .addSubcommand(subcommand => subcommand + .setName('server') + .setDescription('Show the information of the server') + ), + async execute(interaction: CommandInteraction) { + let guildData: Guild; + try { + guildData = await prisma.guild.findUnique({ + where: { + id: interaction.guild.id + } + }); + } catch (err) { + console.error(`\t⚠️ | INFO => Cannot get the database connection!\n\t\t(${err}).`); + } + const subcommand: string = interaction.options.getSubcommand(); + switch (subcommand) { + case 'user': + const targetGlobal: GuildMember = interaction.options.getUser('target') || interaction.user; + await targetGlobal.fetch(); + let userData: User; + try { + userData = await prisma.user.findUnique({ + where: { + id: targetGlobal.id + } + }); + } catch (err) { + console.error(`\t⚠️ | USERINFO => Cannot get the database connection!\n\t\t(${err}).`); + } + let targetServer: GuildMember; + + try { + targetServer = await interaction.guild.members.fetch(targetGlobal.id); + } catch (err) { + console.error(`\t⚠️ | USERINFO => Cannot get the targetServer!\n\t\t(${err}).`); + return ; + } + const userResult: EmbedBuilder = new EmbedBuilder() + .setTitle(`${targetGlobal.displayName}'s information`) + .setColor(`${targetServer.displayHexColor}`) + .setThumbnail(`${targetGlobal.displayAvatarURL()}`) + .setFooter({ + text: guildData.footer + }) + .setImage(targetGlobal.bannerURL({ + size: 1024, + dynamic: true + })) + .setDescription(` + **👤 | Username:** + ${targetGlobal.username} + **🆔 | ID:** + ${targetGlobal.id} + + **🔰 | Roles:** + ${getUserRoles(targetServer)} + **🎖️ | Badges:** + ${getUserBadges(userData)} + + **🍼 | Account Creation:** + () + **🛬 | Server Join:** + () + `) + await interaction.reply({ + embeds: [ + userResult + ], + flags: MessageFlags.Ephemeral + }); + return; + case 'server': + const guild: Guild = interaction.guild; + const serverResult: EmbedBuilder = new EmbedBuilder() + .setTitle(`${guild.name} Informations`) + .setColor(guildData.color) + .setThumbnail(guild.iconURL({dynamic: true, size: 1024})) + .setFooter({ + text: guildData.footer + }) + .setImage(guild.bannerURL({dynamic: false, size: 2048})) + .setDescription(` + **🆔 | ID:** + ${guild.id} + + **🖊️ | Description:** + ${guild.description || "No description given."} + **🔗 | VanityLink:** + ${guild.vanityURLCode || "No custom link."} + + **🆕 | Creation Date:** + + **👑 | Server owner** + ${userMention(guild.ownerId)} + + **🫂 | All Members:** + ${guild.members.cache.size} + **🗣️ | Users:** + ${guild.members.cache.filter((m) => !m.user.bot).size} + **🤖 | Bots:** + ${guild.members.cache.filter((m) => m.user.bot).size} + `) + await interaction.reply({ + embeds: [ + serverResult + ], + flags: MessageFlags.Ephemeral + }); + } + } +}