From 1c4c0f5872ff51a3d82b83ef4dacb4421d4abd9e Mon Sep 17 00:00:00 2001 From: Raphael Date: Mon, 18 Aug 2025 14:57:23 +0200 Subject: [PATCH] style(norme/eslint): now edited the husky rules before commiting --- eslint.config.js | 104 ++-- package.json | 8 +- src/commands/administration/logs.ts | 505 +++++++++---------- src/commands/custom/set.ts | 640 +++++++++++++------------ src/commands/rank/buyer.ts | 489 +++++++++---------- src/commands/rank/owner.ts | 467 +++++++++--------- src/commands/rank/whitelist.ts | 483 ++++++++++--------- src/commands/utils/deleteCategories.ts | 132 ++--- src/commands/utils/info.ts | 277 +++++------ src/commands/utils/ping.ts | 30 +- src/events/client/guildCreate.ts | 86 ++-- src/events/client/ready.ts | 156 +++--- src/events/interaction/interaction.ts | 68 +-- src/index.ts | 209 ++++---- src/internal/deploy-command.ts | 72 +-- src/lib/prisma.ts | 2 +- 16 files changed, 1883 insertions(+), 1845 deletions(-) diff --git a/eslint.config.js b/eslint.config.js index 981836f..5b8cab6 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -1,55 +1,55 @@ -import js from "@eslint/js"; -import ts from "typescript-eslint"; +import js from '@eslint/js'; +import ts from 'typescript-eslint'; export default [ - js.configs.recommended, - ...ts.configs.recommended, - { - languageOptions: { - ecmaVersion: "latest", - }, - rules: { - "arrow-spacing": ["warn", { before: true, after: true }], - "brace-style": ["error", "stroustrup", { allowSingleLine: true }], - "comma-dangle": ["error", "always-multiline"], - "comma-spacing": "error", - "comma-style": "error", - curly: ["error", "multi-line", "consistent"], - "dot-location": ["error", "property"], - "handle-callback-err": "off", - indent: ["error", "tab"], - "keyword-spacing": "error", - "max-nested-callbacks": ["error", { max: 4 }], - "max-statements-per-line": ["error", { max: 2 }], - "no-console": "off", - "no-empty-function": "error", - "no-floating-decimal": "error", - "no-inline-comments": "error", - "no-lonely-if": "error", - "no-multi-spaces": "error", - "no-multiple-empty-lines": ["error", { max: 2, maxEOF: 1, maxBOF: 0 }], - "no-shadow": ["error", { allow: ["err", "resolve", "reject"] }], - "no-trailing-spaces": ["error"], - "no-var": "error", - "no-undef": "off", - "object-curly-spacing": ["error", "always"], - "prefer-const": "error", - quotes: ["error", "single"], - semi: ["error", "always"], - "space-before-blocks": "error", - "space-before-function-paren": [ - "error", - { - anonymous: "never", - named: "never", - asyncArrow: "always", - }, - ], - "space-in-parens": "error", - "space-infix-ops": "error", - "space-unary-ops": "error", - "spaced-comment": "error", - yoda: "error", - }, - }, + js.configs.recommended, + ...ts.configs.recommended, + { + languageOptions: { + ecmaVersion: 'latest', + }, + rules: { + 'arrow-spacing': ['warn', { before: true, after: true }], + 'brace-style': ['error', 'stroustrup', { allowSingleLine: true }], + 'comma-dangle': ['error', 'always-multiline'], + 'comma-spacing': 'error', + 'comma-style': 'error', + curly: ['error', 'multi-line', 'consistent'], + 'dot-location': ['error', 'property'], + 'handle-callback-err': 'off', + indent: ['error', 'tab'], + 'keyword-spacing': 'error', + 'max-nested-callbacks': ['error', { max: 4 }], + 'max-statements-per-line': ['error', { max: 2 }], + 'no-console': 'off', + 'no-empty-function': 'error', + 'no-floating-decimal': 'error', + 'no-inline-comments': 'error', + 'no-lonely-if': 'error', + 'no-multi-spaces': 'error', + 'no-multiple-empty-lines': ['error', { max: 2, maxEOF: 1, maxBOF: 0 }], + 'no-shadow': ['error', { allow: ['err', 'resolve', 'reject'] }], + 'no-trailing-spaces': ['error'], + 'no-var': 'error', + 'no-undef': 'off', + 'object-curly-spacing': ['error', 'always'], + 'prefer-const': 'error', + quotes: ['error', 'single'], + semi: ['error', 'always'], + 'space-before-blocks': 'error', + 'space-before-function-paren': [ + 'error', + { + anonymous: 'never', + named: 'never', + asyncArrow: 'always', + }, + ], + 'space-in-parens': 'error', + 'space-infix-ops': 'error', + 'space-unary-ops': 'error', + 'spaced-comment': 'error', + yoda: 'error', + }, + }, ]; diff --git a/package.json b/package.json index 7068ea2..5e9208b 100644 --- a/package.json +++ b/package.json @@ -9,12 +9,8 @@ }, "private": true, "lint-staged": { - "*.{ts,js,cts,mts}": [ - "eslint --fix", - "prettier --write" - ], - "*.{json,md,yml,yaml}": [ - "prettier --write" + "*": [ + "eslint --fix" ] }, "devDependencies": { diff --git a/src/commands/administration/logs.ts b/src/commands/administration/logs.ts index 7f01161..b26315d 100644 --- a/src/commands/administration/logs.ts +++ b/src/commands/administration/logs.ts @@ -1,93 +1,95 @@ -import { prisma } from "../../lib/prisma.ts"; +import { prisma } from '../../lib/prisma.ts'; import { - ActionRowBuilder, - ChannelType, - PermissionsBitField, - ComponentType, - StringSelectMenuBuilder, - StringSelectMenuInteraction, - StringSelectMenuOptionBuilder, - SlashCommandBuilder, - MessageFlags, - SlashCommandBuilder, - EmbedBuilder, -} from "discord.js"; -import emoji from "../../../assets/emoji.json" assert { type: "json" }; + ActionRowBuilder, + ChannelType, + PermissionsBitField, + ComponentType, + StringSelectMenuBuilder, + StringSelectMenuInteraction, + StringSelectMenuOptionBuilder, + SlashCommandBuilder, + MessageFlags, + SlashCommandBuilder, + EmbedBuilder, +} from 'discord.js'; +import emoji from '../../../assets/emoji.json' assert { type: 'json' }; export default { - data: new SlashCommandBuilder() - .setName("logs") - .setDescription("edit the logs configuration") - .addStringOption((option) => - option - .setName("action") - .setDescription("What is the action you to perform") - .setRequired(true) - .addChoices( - { - name: "Show", - value: "logs_show", - }, - { - name: "Auto-configuration", - value: "logs_auto", - }, - { - name: "Configuration", - value: "logs_config", - }, - ), - ), - async execute(interaction: CommandInteraction) { - let guildData: Guild; - try { - guildData = await prisma.guild.findUnique({ - where: { - id: interaction.guild.id, - }, - }); - } catch (err) { - console.error( - `\t⚠️ | Cannot get the database connection!\n\t\t(${err}).`, - ); - await interaction.reply({ - content: `${emoji.answer.error} | Cannot connect to the database`, - flags: MessageFlags.Ephemeral, - }); - return; - } - let userData: User; - try { - userData = await prisma.user.findUnique({ - where: { - id: interaction.user.id, - }, - }); - } catch (err) { - throw `\t⚠️ | Cannot get the database connection!\n\t\t(${err}).`; - await interaction.reply({ - content: `${emoji.answer.error} | Cannot connect to the database`, - flags: MessageFlags.Ephemeral, - }); - return; - } - const choice: string = interaction.options.getString("action"); - switch (choice) { - case "logs_show": { - if (!userData.isOwner) { - await interaction.reply({ - content: `${emoji.answer.no} | This command is only for owner`, - flags: MessageFlags.Ephemeral, - }); - return; - } - if (guildData.logEnable) { - const logsData: EmbedBuilder = new EmbedBuilder() - .setTitle(`Logs for ${interaction.guild.name}`) - .setColor(`${guildData.color}`) - .setFooter({ - text: guildData.footer, - }).setDescription(` + data: new SlashCommandBuilder() + .setName('logs') + .setDescription('edit the logs configuration') + .addStringOption((option) => + option + .setName('action') + .setDescription('What is the action you to perform') + .setRequired(true) + .addChoices( + { + name: 'Show', + value: 'logs_show', + }, + { + name: 'Auto-configuration', + value: 'logs_auto', + }, + { + name: 'Configuration', + value: 'logs_config', + }, + ), + ), + async execute(interaction: CommandInteraction) { + let guildData: Guild; + try { + guildData = await prisma.guild.findUnique({ + where: { + id: interaction.guild.id, + }, + }); + } + catch (err) { + console.error( + `\t⚠️ | Cannot get the database connection!\n\t\t(${err}).`, + ); + await interaction.reply({ + content: `${emoji.answer.error} | Cannot connect to the database`, + flags: MessageFlags.Ephemeral, + }); + return; + } + let userData: User; + try { + userData = await prisma.user.findUnique({ + where: { + id: interaction.user.id, + }, + }); + } + catch (err) { + throw `\t⚠️ | Cannot get the database connection!\n\t\t(${err}).`; + await interaction.reply({ + content: `${emoji.answer.error} | Cannot connect to the database`, + flags: MessageFlags.Ephemeral, + }); + return; + } + const choice: string = interaction.options.getString('action'); + switch (choice) { + case 'logs_show': { + if (!userData.isOwner) { + await interaction.reply({ + content: `${emoji.answer.no} | This command is only for owner`, + flags: MessageFlags.Ephemeral, + }); + return; + } + if (guildData.logEnable) { + const logsData: EmbedBuilder = new EmbedBuilder() + .setTitle(`Logs for ${interaction.guild.name}`) + .setColor(`${guildData.color}`) + .setFooter({ + text: guildData.footer, + }).setDescription(` ${guildData.logCategory ? `${emoji.answer.yes} | Categories` : `${emoji.answer.no} | Categories`} ${guildData.logBot ? `${emoji.answer.yes} | Bot` : `${emoji.answer.no} | Bot`} ${guildData.logChannels ? `${emoji.answer.yes} | Channels` : `${emoji.answer.no} | Channels`} @@ -97,185 +99,186 @@ export default { ${guildData.logServer ? `${emoji.answer.yes} | Server` : `${emoji.answer.no} | Server`} `); - await interaction.reply({ - embeds: [logsData], - }); - } else { - await interaction.reply({ - content: `${emoji.answer.no} | The log is disable on the server`, - flags: MessageFlags.Ephemeral, - }); - } - return; - } - case "logs_auto": { - if (!userData.isOwner) { - await interaction.reply({ - content: `${emoji.answer.no} | This command is only for owner`, - flags: MessageFlags.Ephemeral, - }); - return; - } - if (guildData.logEnable) { - await interaction.reply({ - content: `${emoji.answer.error} | The log is already setup on this server`, - flags: MessageFlags.Ephemeral, - }); - return; - } + await interaction.reply({ + embeds: [logsData], + }); + } + else { + await interaction.reply({ + content: `${emoji.answer.no} | The log is disable on the server`, + flags: MessageFlags.Ephemeral, + }); + } + return; + } + case 'logs_auto': { + if (!userData.isOwner) { + await interaction.reply({ + content: `${emoji.answer.no} | This command is only for owner`, + flags: MessageFlags.Ephemeral, + }); + return; + } + if (guildData.logEnable) { + await interaction.reply({ + content: `${emoji.answer.error} | The log is already setup on this server`, + flags: MessageFlags.Ephemeral, + }); + return; + } - const roles = interaction.guild?.roles.cache - .filter((role) => !role.managed && role.id !== interaction.guild?.id) - .sort((a, b) => b.position - a.position); + const roles = interaction.guild?.roles.cache + .filter((role) => !role.managed && role.id !== interaction.guild?.id) + .sort((a, b) => b.position - a.position); - const menu = new StringSelectMenuBuilder() - .setCustomId("role_select") - .setPlaceholder("Choose the role that will have logs access") - .setMinValues(1) - .setMaxValues(Math.min(roles.size, 25)) - .addOptions( - roles.map((role) => - new StringSelectMenuOptionBuilder() - .setLabel(role.name) - .setValue(role.id), - ), - ); + const menu = new StringSelectMenuBuilder() + .setCustomId('role_select') + .setPlaceholder('Choose the role that will have logs access') + .setMinValues(1) + .setMaxValues(Math.min(roles.size, 25)) + .addOptions( + roles.map((role) => + new StringSelectMenuOptionBuilder() + .setLabel(role.name) + .setValue(role.id), + ), + ); - const roleSelection = + const roleSelection = new ActionRowBuilder().addComponents(menu); - const permSelector: EmbedBuilder = new EmbedBuilder() - .setTitle("Which role will have access") - .setColor(`${guildData.color}`) - .setFooter({ - text: guildData.footer, - }); + const permSelector: EmbedBuilder = new EmbedBuilder() + .setTitle('Which role will have access') + .setColor(`${guildData.color}`) + .setFooter({ + text: guildData.footer, + }); - const msg = await interaction.reply({ - embeds: [permSelector], - components: [roleSelection], - flags: MessageFlags.fetchReply, - }); - const collector = msg.createMessageComponentCollector({ - componentType: ComponentType.StringSelect, - time: 60_000, - max: 25, - }); - collector.on( - "collect", - async (selectInteraction: StringSelectMenuInteraction) => { - if (selectInteraction.user.id !== interaction.user.id) { - selectInteraction.reply({ - content: `${emoji.answer.no} | You cannot use this selector !`, - ephemeral: true, - }); - return; - } - const selectedRoles = selectInteraction.values; - const permissionOverwrites = [ - { - id: interaction.guild.roles.everyone.id, - deny: [ - PermissionsBitField.Flags.ViewChannel, - PermissionsBitField.Flags.SendMessages, - ], - }, - ...selectedRoles.map((id) => ({ - id, - allow: [PermissionsBitField.Flags.ViewChannel], - })), - ]; + const msg = await interaction.reply({ + embeds: [permSelector], + components: [roleSelection], + flags: MessageFlags.fetchReply, + }); + const collector = msg.createMessageComponentCollector({ + componentType: ComponentType.StringSelect, + time: 60_000, + max: 25, + }); + collector.on( + 'collect', + async (selectInteraction: StringSelectMenuInteraction) => { + if (selectInteraction.user.id !== interaction.user.id) { + selectInteraction.reply({ + content: `${emoji.answer.no} | You cannot use this selector !`, + ephemeral: true, + }); + return; + } + const selectedRoles = selectInteraction.values; + const permissionOverwrites = [ + { + id: interaction.guild.roles.everyone.id, + deny: [ + PermissionsBitField.Flags.ViewChannel, + PermissionsBitField.Flags.SendMessages, + ], + }, + ...selectedRoles.map((id) => ({ + id, + allow: [PermissionsBitField.Flags.ViewChannel], + })), + ]; - const category = (await interaction.guild.channels.create({ - name: "Logs", - type: ChannelType.GuildCategory, - permissionOverwrites, - })) as CategoryChannel; + const category = (await interaction.guild.channels.create({ + name: 'Logs', + type: ChannelType.GuildCategory, + permissionOverwrites, + })) as CategoryChannel; - const logBot = (await interaction.guild.channels.create({ - name: "bot-logs", - type: ChannelType.GuildText, - parent: category, - permissionOverwrites, - })) as TextChannel; + const logBot = (await interaction.guild.channels.create({ + name: 'bot-logs', + type: ChannelType.GuildText, + parent: category, + permissionOverwrites, + })) as TextChannel; - const logChannels = (await interaction.guild.channels.create({ - name: "channel-logs", - type: ChannelType.GuildText, - parent: category, - permissionOverwrites, - })) as TextChannel; + const logChannels = (await interaction.guild.channels.create({ + name: 'channel-logs', + type: ChannelType.GuildText, + parent: category, + permissionOverwrites, + })) as TextChannel; - const logMember = (await interaction.guild.channels.create({ - name: "member-logs", - type: ChannelType.GuildText, - parent: category, - permissionOverwrites, - })) as TextChannel; + const logMember = (await interaction.guild.channels.create({ + name: 'member-logs', + type: ChannelType.GuildText, + parent: category, + permissionOverwrites, + })) as TextChannel; - const logMod = (await interaction.guild.channels.create({ - name: "mod-logs", - type: ChannelType.GuildText, - parent: category, - permissionOverwrites, - })) as TextChannel; + const logMod = (await interaction.guild.channels.create({ + name: 'mod-logs', + type: ChannelType.GuildText, + parent: category, + permissionOverwrites, + })) as TextChannel; - const logMsg = (await interaction.guild.channels.create({ - name: "message-logs", - type: ChannelType.GuildText, - parent: category, - permissionOverwrites, - })) as TextChannel; + const logMsg = (await interaction.guild.channels.create({ + name: 'message-logs', + type: ChannelType.GuildText, + parent: category, + permissionOverwrites, + })) as TextChannel; - const logServer = (await interaction.guild.channels.create({ - name: "server-logs", - type: ChannelType.GuildText, - parent: category, - permissionOverwrites, - })) as TextChannel; + const logServer = (await interaction.guild.channels.create({ + name: 'server-logs', + type: ChannelType.GuildText, + parent: category, + permissionOverwrites, + })) as TextChannel; - await prisma.guild.update({ - where: { - id: interaction.guild.id, - }, - data: { - logEnable: true, - logCategory: category.id, - logBot: logBot.id, - logChannels: logChannels.id, - logMember: logMember.id, - logMod: logMod.id, - logMsg: logMsg.id, - logServer: logServer.id, - }, - }); - const mentionList = selectedRoles - .map((id) => `- <@&${id}>`) - .join("\n"); - const autoConfig = new EmbedBuilder() - .setTitle("The logs category is created") - .setDescription( - ` + await prisma.guild.update({ + where: { + id: interaction.guild.id, + }, + data: { + logEnable: true, + logCategory: category.id, + logBot: logBot.id, + logChannels: logChannels.id, + logMember: logMember.id, + logMod: logMod.id, + logMsg: logMsg.id, + logServer: logServer.id, + }, + }); + const mentionList = selectedRoles + .map((id) => `- <@&${id}>`) + .join('\n'); + const autoConfig = new EmbedBuilder() + .setTitle('The logs category is created') + .setDescription( + ` This following roles will have access to the logs. ${mentionList} `, - ) - .setColor(`${guildData.color}`) - .setFooter({ - text: guildData.footer, - }); - await selectInteraction.update({ - embeds: [autoConfig], - components: [], - }); - return; - }, - ); - break; - } - default: - console.error(`no choice on logs command ${choice}`); - return; - } - }, + ) + .setColor(`${guildData.color}`) + .setFooter({ + text: guildData.footer, + }); + await selectInteraction.update({ + embeds: [autoConfig], + components: [], + }); + return; + }, + ); + break; + } + default: + console.error(`no choice on logs command ${choice}`); + return; + } + }, }; diff --git a/src/commands/custom/set.ts b/src/commands/custom/set.ts index 27fd334..e88c04a 100644 --- a/src/commands/custom/set.ts +++ b/src/commands/custom/set.ts @@ -1,322 +1,326 @@ -import { prisma } from "../../lib/prisma.ts"; +import { prisma } from '../../lib/prisma.ts'; import { - ActivityType, - PresenceUpdateStatus, - MessageFlags, - SlashCommandBuilder, -} from "discord.js"; -import emoji from "../../../assets/emoji.json" assert { type: "json" }; + ActivityType, + PresenceUpdateStatus, + MessageFlags, + SlashCommandBuilder, +} from 'discord.js'; +import emoji from '../../../assets/emoji.json' assert { type: 'json' }; export default { - data: new SlashCommandBuilder() - .setName("set") - .setDescription("edit the default behavour of the bot") - .addSubcommand((subcommand) => - subcommand - .setName("color") - .setDescription("Change the default color for the embed") - .addStringOption((option) => - option - .setName("color") - .setDescription("The new color by default") - .setRequired(true), - ), - ) - .addSubcommand((subcommand) => - subcommand - .setName("footer") - .setDescription("Change the default footer for the embed") - .addStringOption((option) => - option - .setName("text") - .setDescription("The new text by default of the bot") - .setRequired(true), - ), - ) - .addSubcommand((subcommand) => - subcommand - .setName("pp") - .setDescription("Change the bot profile picture") - .addStringOption((option) => - option - .setName("link") - .setDescription("The new link to the new profile picture") - .setRequired(true), - ), - ) - .addSubcommand((subcommand) => - subcommand - .setName("status") - .setDescription("Change the status of the bot") - .addStringOption((option) => - option - .setName("status") - .setDescription("The new status used by the bot") - .setRequired(true), - ) - .addStringOption((option) => - option - .setName("presence") - .setDescription("The new presence of the bot") - .setRequired(true) - .addChoices( - { - name: "Online", - value: "online", - }, - { - name: "Do not disturb", - value: "dnd", - }, - { - name: "Idle", - value: "idle", - }, - { - name: "Invisible", - value: "invisible", - }, - ), - ) - .addStringOption((option) => - option - .setName("type") - .setDescription("The type of the new activity") - .setRequired(true) - .addChoices( - { - name: "Playing", - value: "play", - }, - { - name: "Watching", - value: "watch", - }, - { - name: "Listening", - value: "listen", - }, - { - name: "Competing", - value: "competing", - }, - { - name: "Streaming", - value: "stream", - }, - ), - ), - ), - async execute(interaction: CommandInteraction) { - let userData: User; - try { - userData = await prisma.user.findUnique({ - where: { - id: interaction.user.id, - }, - }); - } catch (err) { - console.error( - `\t⚠️ | Cannot get the database connection!\n\t\t(${err}).`, - ); - await interaction.reply({ - content: `${emoji.answer.error} | Cannot connect to the database`, - flags: MessageFlags.Ephemeral, - }); - return; - } - const subcommand: string = interaction.options.getSubcommand(); - switch (subcommand) { - case "color": { - if (!userData.isOwner) { - await interaction.reply({ - content: `${emoji.answer.no} | This command is only for owner`, - flags: MessageFlags.Ephemeral, - }); - return; - } - const newColor: string = interaction.options.getString("color"); - if (!/^#[0-9A-Fa-f]{6}$/.test(newColor)) { - await interaction.reply({ - content: `${emoji.answer.no} | You have to give a color with the syntax: \`#000000\`.`, - flags: MessageFlags.Ephemeral, - }); - return; - } - await prisma.guild.upsert({ - where: { - id: interaction.guild.id, - }, - update: { - color: newColor, - }, - create: { - id: interaction.guild.id, - color: newColor, - }, - }); - await interaction.reply({ - content: `${emoji.answer.yes} | The default color for embed will be now changed by \`${newColor}\``, - flags: MessageFlags.Ephemeral, - }); - return; - } - case "footer": { - if (!userData.isOwner) { - await interaction.reply({ - content: `${emoji.answer.no} | This command is only for owner`, - flags: MessageFlags.Ephemeral, - }); - return; - } - const newFooter: string = interaction.options.getString("text"); - if (newFooter.length > 2048) { - await interaction.reply({ - content: `${emoji.answer.no} | The maximum lenght for the footer is 2048`, - flags: MessageFlags.Ephemeral, - }); - return; - } - await prisma.guild.upsert({ - where: { - id: interaction.guild.id, - }, - update: { - footer: newFooter, - }, - create: { - id: interaction.guild.id, - footer: newFooter, - }, - }); - await interaction.reply({ - content: `${emoji.answer.yes} | The default footer for embed will be now changed by \`${newFooter}\`.`, - flags: MessageFlags.Ephemeral, - }); - return; - } - case "pp": { - if (!userData.isBuyer) { - await interaction.reply({ - content: `${emoji.answer.no} | This command is only for buyer`, - flags: MessageFlags.Ephemeral, - }); - return; - } - const newPicture: string = interaction.options.getString("link"); - try { - interaction.client.user.setAvatar(newPicture); - } catch (err) { - await interaction.reply({ - content: `${emoji.answer.no} | Error during changing the bot profile picture`, - flags: MessageFlags.Ephemeral, - }); - console.error( - `\t⚠️ | Cannot change the bot profile picture!\n\t\t(${err}).`, - ); - } - await interaction.reply({ - content: `${emoji.answer.yes} | The picture profile of the bot is now updated.`, - flags: MessageFlags.Ephemeral, - }); - return; - } - case "status": { - if (!userData.isBuyer) { - await interaction.reply({ - content: `${emoji.answer.no} | This command is only for buyer`, - flags: MessageFlags.Ephemeral, - }); - return; - } - const newStatus: string = interaction.options.getString("status"); - const tmpType: string = interaction.options.getString("type"); - let newType: ActivityType; - switch (tmpType) { - case "play": - newType = ActivityType.Playing; - break; - case "listen": - newType = ActivityType.Listening; - break; - case "watch": - newType = ActivityType.Watching; - break; - case "stream": - newType = ActivityType.Streaming; - break; - case "competing": - newType = ActivityType.Competing; - break; - } - const tmpPresence: string = interaction.options.getString("presence"); - let newPresence: PresenceUpdateStatus; - switch (tmpPresence) { - case "online": - newPresence = PresenceUpdateStatus.Online; - break; - case "idle": - newPresence = PresenceUpdateStatus.Idle; - break; - case "dnd": - newPresence = PresenceUpdateStatus.DoNotDisturb; - break; - case "invisible": - newPresence = PresenceUpdateStatus.Invisible; - break; - } - try { - await prisma.bot.upsert({ - where: { - id: 1, - }, - update: { - status: newStatus, - type: tmpType, - presence: newPresence, - }, - create: { - id: 1, - status: newStatus, - type: tmpType, - presence: newPresence, - }, - }); - if (tmpType === "steam") { - interaction.client.user.setPresence({ - status: newPresence, - activities: [ - { - name: newStatus, - type: newType, - url: "https://twitch.tv/EniumRaphael", - }, - ], - }); - } else { - interaction.client.user.setPresence({ - status: newPresence, - activities: [ - { - name: newStatus, - type: newType, - }, - ], - }); - } - } catch (err) { - await interaction.reply({ - content: `${emoji.answer.no} | Cannot change the status\n\n\t${err}`, - flags: MessageFlags.Ephemeral, - }); - return; - } - await interaction.reply({ - content: `${emoji.answer.yes} | The new activity is now \`${newStatus}\``, - flags: MessageFlags.Ephemeral, - }); - return; - } - } - }, + data: new SlashCommandBuilder() + .setName('set') + .setDescription('edit the default behavour of the bot') + .addSubcommand((subcommand) => + subcommand + .setName('color') + .setDescription('Change the default color for the embed') + .addStringOption((option) => + option + .setName('color') + .setDescription('The new color by default') + .setRequired(true), + ), + ) + .addSubcommand((subcommand) => + subcommand + .setName('footer') + .setDescription('Change the default footer for the embed') + .addStringOption((option) => + option + .setName('text') + .setDescription('The new text by default of the bot') + .setRequired(true), + ), + ) + .addSubcommand((subcommand) => + subcommand + .setName('pp') + .setDescription('Change the bot profile picture') + .addStringOption((option) => + option + .setName('link') + .setDescription('The new link to the new profile picture') + .setRequired(true), + ), + ) + .addSubcommand((subcommand) => + subcommand + .setName('status') + .setDescription('Change the status of the bot') + .addStringOption((option) => + option + .setName('status') + .setDescription('The new status used by the bot') + .setRequired(true), + ) + .addStringOption((option) => + option + .setName('presence') + .setDescription('The new presence of the bot') + .setRequired(true) + .addChoices( + { + name: 'Online', + value: 'online', + }, + { + name: 'Do not disturb', + value: 'dnd', + }, + { + name: 'Idle', + value: 'idle', + }, + { + name: 'Invisible', + value: 'invisible', + }, + ), + ) + .addStringOption((option) => + option + .setName('type') + .setDescription('The type of the new activity') + .setRequired(true) + .addChoices( + { + name: 'Playing', + value: 'play', + }, + { + name: 'Watching', + value: 'watch', + }, + { + name: 'Listening', + value: 'listen', + }, + { + name: 'Competing', + value: 'competing', + }, + { + name: 'Streaming', + value: 'stream', + }, + ), + ), + ), + async execute(interaction: CommandInteraction) { + let userData: User; + try { + userData = await prisma.user.findUnique({ + where: { + id: interaction.user.id, + }, + }); + } + catch (err) { + console.error( + `\t⚠️ | Cannot get the database connection!\n\t\t(${err}).`, + ); + await interaction.reply({ + content: `${emoji.answer.error} | Cannot connect to the database`, + flags: MessageFlags.Ephemeral, + }); + return; + } + const subcommand: string = interaction.options.getSubcommand(); + switch (subcommand) { + case 'color': { + if (!userData.isOwner) { + await interaction.reply({ + content: `${emoji.answer.no} | This command is only for owner`, + flags: MessageFlags.Ephemeral, + }); + return; + } + const newColor: string = interaction.options.getString('color'); + if (!/^#[0-9A-Fa-f]{6}$/.test(newColor)) { + await interaction.reply({ + content: `${emoji.answer.no} | You have to give a color with the syntax: \`#000000\`.`, + flags: MessageFlags.Ephemeral, + }); + return; + } + await prisma.guild.upsert({ + where: { + id: interaction.guild.id, + }, + update: { + color: newColor, + }, + create: { + id: interaction.guild.id, + color: newColor, + }, + }); + await interaction.reply({ + content: `${emoji.answer.yes} | The default color for embed will be now changed by \`${newColor}\``, + flags: MessageFlags.Ephemeral, + }); + return; + } + case 'footer': { + if (!userData.isOwner) { + await interaction.reply({ + content: `${emoji.answer.no} | This command is only for owner`, + flags: MessageFlags.Ephemeral, + }); + return; + } + const newFooter: string = interaction.options.getString('text'); + if (newFooter.length > 2048) { + await interaction.reply({ + content: `${emoji.answer.no} | The maximum lenght for the footer is 2048`, + flags: MessageFlags.Ephemeral, + }); + return; + } + await prisma.guild.upsert({ + where: { + id: interaction.guild.id, + }, + update: { + footer: newFooter, + }, + create: { + id: interaction.guild.id, + footer: newFooter, + }, + }); + await interaction.reply({ + content: `${emoji.answer.yes} | The default footer for embed will be now changed by \`${newFooter}\`.`, + flags: MessageFlags.Ephemeral, + }); + return; + } + case 'pp': { + if (!userData.isBuyer) { + await interaction.reply({ + content: `${emoji.answer.no} | This command is only for buyer`, + flags: MessageFlags.Ephemeral, + }); + return; + } + const newPicture: string = interaction.options.getString('link'); + try { + interaction.client.user.setAvatar(newPicture); + } + catch (err) { + await interaction.reply({ + content: `${emoji.answer.no} | Error during changing the bot profile picture`, + flags: MessageFlags.Ephemeral, + }); + console.error( + `\t⚠️ | Cannot change the bot profile picture!\n\t\t(${err}).`, + ); + } + await interaction.reply({ + content: `${emoji.answer.yes} | The picture profile of the bot is now updated.`, + flags: MessageFlags.Ephemeral, + }); + return; + } + case 'status': { + if (!userData.isBuyer) { + await interaction.reply({ + content: `${emoji.answer.no} | This command is only for buyer`, + flags: MessageFlags.Ephemeral, + }); + return; + } + const newStatus: string = interaction.options.getString('status'); + const tmpType: string = interaction.options.getString('type'); + let newType: ActivityType; + switch (tmpType) { + case 'play': + newType = ActivityType.Playing; + break; + case 'listen': + newType = ActivityType.Listening; + break; + case 'watch': + newType = ActivityType.Watching; + break; + case 'stream': + newType = ActivityType.Streaming; + break; + case 'competing': + newType = ActivityType.Competing; + break; + } + const tmpPresence: string = interaction.options.getString('presence'); + let newPresence: PresenceUpdateStatus; + switch (tmpPresence) { + case 'online': + newPresence = PresenceUpdateStatus.Online; + break; + case 'idle': + newPresence = PresenceUpdateStatus.Idle; + break; + case 'dnd': + newPresence = PresenceUpdateStatus.DoNotDisturb; + break; + case 'invisible': + newPresence = PresenceUpdateStatus.Invisible; + break; + } + try { + await prisma.bot.upsert({ + where: { + id: 1, + }, + update: { + status: newStatus, + type: tmpType, + presence: newPresence, + }, + create: { + id: 1, + status: newStatus, + type: tmpType, + presence: newPresence, + }, + }); + if (tmpType === 'steam') { + interaction.client.user.setPresence({ + status: newPresence, + activities: [ + { + name: newStatus, + type: newType, + url: 'https://twitch.tv/EniumRaphael', + }, + ], + }); + } + else { + interaction.client.user.setPresence({ + status: newPresence, + activities: [ + { + name: newStatus, + type: newType, + }, + ], + }); + } + } + catch (err) { + await interaction.reply({ + content: `${emoji.answer.no} | Cannot change the status\n\n\t${err}`, + flags: MessageFlags.Ephemeral, + }); + return; + } + await interaction.reply({ + content: `${emoji.answer.yes} | The new activity is now \`${newStatus}\``, + flags: MessageFlags.Ephemeral, + }); + return; + } + } + }, }; diff --git a/src/commands/rank/buyer.ts b/src/commands/rank/buyer.ts index 30b9da2..03dd53b 100644 --- a/src/commands/rank/buyer.ts +++ b/src/commands/rank/buyer.ts @@ -1,247 +1,254 @@ -import { EmbedBuilder, MessageFlags, SlashCommandBuilder } from "discord.js"; -import { prisma } from "../../lib/prisma.ts"; -import emoji from "../../../assets/emoji.json" assert { type: "json" }; +import { EmbedBuilder, MessageFlags, SlashCommandBuilder } from 'discord.js'; +import { prisma } from '../../lib/prisma.ts'; +import emoji from '../../../assets/emoji.json' assert { type: 'json' }; export default { - data: new SlashCommandBuilder() - .setName("buyer") - .setDescription("Interact with the buyers") - .addSubcommand((subcommand) => - subcommand - .setName("add") - .setDescription("Add a user on the buyer list") - .addUserOption((option) => - option - .setName("target") - .setDescription("The user who will be added to the list") - .setRequired(true), - ), - ) - .addSubcommand((subcommand) => - subcommand - .setName("delete") - .setDescription("Delete a user on the buyer list") - .addUserOption((option) => - option - .setName("target") - .setDescription("The user who will be deleted to the list") - .setRequired(true), - ), - ) - .addSubcommand((subcommand) => - subcommand.setName("list").setDescription("The list of the buyer"), - ), - async execute(interaction: CommandInteraction) { - const subcommand = interaction.options.getSubcommand(); - let userData: User; - try { - userData = await prisma.user.findUnique({ - where: { - id: interaction.user.id, - }, - }); - } catch (err) { - console.error( - `\t⚠️ | Cannot get the database connection!\n\t\t(${err}).`, - ); - await interaction.reply({ - content: `${emoji.answer.error} | Cannot connect to the database`, - flags: MessageFlags.Ephemeral, - }); - return; - } - let guildData: Guild; - try { - guildData = await prisma.guild.findUnique({ - where: { - id: interaction.guild.id, - }, - }); - } catch (err) { - console.error( - `\t⚠️ | Cannot get the database connection!\n\t\t(${err}).`, - ); - await interaction.reply({ - content: `${emoji.answer.error} | Cannot connect to the database`, - flags: MessageFlags.Ephemeral, - }); - return; - } - const target: GuildMember = interaction.options.getUser("target"); - switch (subcommand) { - case "add": - if (!userData.isDev) { - await interaction.reply({ - content: `${emoji.answer.no} | This command is only for the developper of the bot`, - flags: MessageFlags.Ephemeral, - }); - return; - } - try { - await prisma.bot.update({ - where: { - id: 1, - }, - data: { - buyers: { - connect: { - id: target.id, - }, - }, - owners: { - connect: { - id: target.id, - }, - }, - }, - }); - await prisma.user.upsert({ - where: { - id: target.id, - }, - update: { - isBuyer: true, - isOwner: true, - }, - create: { - id: target.id, - isBuyer: true, - isOwner: true, - }, - }); - } catch (err) { - console.error( - `⚠️ | Error when adding ${target.username} to the buyer list\n\t${err}`, - ); - await interaction.reply({ - content: `${emoji.answer.error} | Error when adding ${target.username} to the owner list`, - flags: MessageFlags.Ephemeral, - }); - return; - } - await interaction.reply({ - content: `${emoji.answer.yes} | ${target.username} has been added to the buyer list`, - flags: MessageFlags.Ephemeral, - }); - return; - case "delete": - if (!userData.isDev) { - await interaction.reply({ - content: `${emoji.answer.no} | This command is only for buyer`, - flags: MessageFlags.Ephemeral, - }); - return; - } else if (interaction.user.id === target.id) { - await interaction.reply({ - content: `${emoji.answer.no} | You cannot removing yourself from the buyer list`, - flags: MessageFlags.Ephemeral, - }); - return; - } - try { - await prisma.bot.update({ - where: { - id: 1, - }, - data: { - buyers: { - disconnect: { - id: target.id, - }, - }, - owners: { - disconnect: { - id: target.id, - }, - }, - }, - }); - await prisma.user.upsert({ - where: { - id: target.id, - }, - update: { - isBuyer: false, - isOwner: false, - }, - create: { - id: target.id, - isBuyer: false, - isOwner: false, - }, - }); - } catch (err) { - console.error( - `⚠️ | Error when removing ${target.username} to the buyer list\n\t${err}`, - ); - return; - } - await interaction.reply({ - content: `${emoji.answer.yes} | ${target.username} has been removing to the buyer list`, - flags: MessageFlags.Ephemeral, - }); - return; - case "list": - if (!userData.isBuyer) { - await interaction.reply({ - content: `${emoji.answer.no} | This command is only for buyer`, - flags: MessageFlags.Ephemeral, - }); - return; - } - try { - const bot = await prisma.bot.findUnique({ - where: { - id: 1, - }, - include: { - buyers: true, - }, - }); + data: new SlashCommandBuilder() + .setName('buyer') + .setDescription('Interact with the buyers') + .addSubcommand((subcommand) => + subcommand + .setName('add') + .setDescription('Add a user on the buyer list') + .addUserOption((option) => + option + .setName('target') + .setDescription('The user who will be added to the list') + .setRequired(true), + ), + ) + .addSubcommand((subcommand) => + subcommand + .setName('delete') + .setDescription('Delete a user on the buyer list') + .addUserOption((option) => + option + .setName('target') + .setDescription('The user who will be deleted to the list') + .setRequired(true), + ), + ) + .addSubcommand((subcommand) => + subcommand.setName('list').setDescription('The list of the buyer'), + ), + async execute(interaction: CommandInteraction) { + const subcommand = interaction.options.getSubcommand(); + let userData: User; + try { + userData = await prisma.user.findUnique({ + where: { + id: interaction.user.id, + }, + }); + } + catch (err) { + console.error( + `\t⚠️ | Cannot get the database connection!\n\t\t(${err}).`, + ); + await interaction.reply({ + content: `${emoji.answer.error} | Cannot connect to the database`, + flags: MessageFlags.Ephemeral, + }); + return; + } + let guildData: Guild; + try { + guildData = await prisma.guild.findUnique({ + where: { + id: interaction.guild.id, + }, + }); + } + catch (err) { + console.error( + `\t⚠️ | Cannot get the database connection!\n\t\t(${err}).`, + ); + await interaction.reply({ + content: `${emoji.answer.error} | Cannot connect to the database`, + flags: MessageFlags.Ephemeral, + }); + return; + } + const target: GuildMember = interaction.options.getUser('target'); + switch (subcommand) { + case 'add': + if (!userData.isDev) { + await interaction.reply({ + content: `${emoji.answer.no} | This command is only for the developper of the bot`, + flags: MessageFlags.Ephemeral, + }); + return; + } + try { + await prisma.bot.update({ + where: { + id: 1, + }, + data: { + buyers: { + connect: { + id: target.id, + }, + }, + owners: { + connect: { + id: target.id, + }, + }, + }, + }); + await prisma.user.upsert({ + where: { + id: target.id, + }, + update: { + isBuyer: true, + isOwner: true, + }, + create: { + id: target.id, + isBuyer: true, + isOwner: true, + }, + }); + } + catch (err) { + console.error( + `⚠️ | Error when adding ${target.username} to the buyer list\n\t${err}`, + ); + await interaction.reply({ + content: `${emoji.answer.error} | Error when adding ${target.username} to the owner list`, + flags: MessageFlags.Ephemeral, + }); + return; + } + await interaction.reply({ + content: `${emoji.answer.yes} | ${target.username} has been added to the buyer list`, + flags: MessageFlags.Ephemeral, + }); + return; + case 'delete': + if (!userData.isDev) { + await interaction.reply({ + content: `${emoji.answer.no} | This command is only for buyer`, + flags: MessageFlags.Ephemeral, + }); + return; + } + else if (interaction.user.id === target.id) { + await interaction.reply({ + content: `${emoji.answer.no} | You cannot removing yourself from the buyer list`, + flags: MessageFlags.Ephemeral, + }); + return; + } + try { + await prisma.bot.update({ + where: { + id: 1, + }, + data: { + buyers: { + disconnect: { + id: target.id, + }, + }, + owners: { + disconnect: { + id: target.id, + }, + }, + }, + }); + await prisma.user.upsert({ + where: { + id: target.id, + }, + update: { + isBuyer: false, + isOwner: false, + }, + create: { + id: target.id, + isBuyer: false, + isOwner: false, + }, + }); + } + catch (err) { + console.error( + `⚠️ | Error when removing ${target.username} to the buyer list\n\t${err}`, + ); + return; + } + await interaction.reply({ + content: `${emoji.answer.yes} | ${target.username} has been removing to the buyer list`, + flags: MessageFlags.Ephemeral, + }); + return; + case 'list': + if (!userData.isBuyer) { + await interaction.reply({ + content: `${emoji.answer.no} | This command is only for buyer`, + flags: MessageFlags.Ephemeral, + }); + return; + } + try { + const bot = await prisma.bot.findUnique({ + where: { + id: 1, + }, + include: { + buyers: true, + }, + }); - if (!bot || bot.buyers.length === 0) { - await interaction.reply({ - content: `${emoji.answer.error} | There is no buyer registered.`, - flags: MessageFlags.Ephemeral, - }); - break; - } + if (!bot || bot.buyers.length === 0) { + await interaction.reply({ + content: `${emoji.answer.error} | There is no buyer registered.`, + flags: MessageFlags.Ephemeral, + }); + break; + } - const buyerList = await Promise.all( - bot.buyers.map(async (buyer) => { - try { - const user = await interaction.client.users.fetch(buyer.id); - return `- ${user.username} (\`${user.id}\`)\n`; - } catch (err) { - console.warn(`⚠️ | ${buyer.id} : ${err}`); - return null; - } - }), - ); + const buyerList = await Promise.all( + bot.buyers.map(async (buyer) => { + try { + const user = await interaction.client.users.fetch(buyer.id); + return `- ${user.username} (\`${user.id}\`)\n`; + } + catch (err) { + console.warn(`⚠️ | ${buyer.id} : ${err}`); + return null; + } + }), + ); - const toSend: EmbedBuilder = new EmbedBuilder() - .setTitle(`${emoji.badge.buyer} | Buyer list`) - .setColor(guildData.color) - .setFooter({ - text: guildData.footer, - }) - .setDescription(buyerList.filter(Boolean).join("")); - await interaction.reply({ - embeds: [toSend], - flags: MessageFlags.Ephemeral, - }); - } catch (err) { - console.error( - `⚠️ | error when fetching infromation from the database: ${err}`, - ); - await interaction.reply({ - content: `${emoji.answer.error} | Cannot fetch the infromation of the database.`, - flags: MessageFlags.Ephemeral, - }); - return; - } - break; - return; - } - }, + const toSend: EmbedBuilder = new EmbedBuilder() + .setTitle(`${emoji.badge.buyer} | Buyer list`) + .setColor(guildData.color) + .setFooter({ + text: guildData.footer, + }) + .setDescription(buyerList.filter(Boolean).join('')); + await interaction.reply({ + embeds: [toSend], + flags: MessageFlags.Ephemeral, + }); + } + catch (err) { + console.error( + `⚠️ | error when fetching infromation from the database: ${err}`, + ); + await interaction.reply({ + content: `${emoji.answer.error} | Cannot fetch the infromation of the database.`, + flags: MessageFlags.Ephemeral, + }); + return; + } + break; + return; + } + }, }; diff --git a/src/commands/rank/owner.ts b/src/commands/rank/owner.ts index 6f69c21..4add063 100644 --- a/src/commands/rank/owner.ts +++ b/src/commands/rank/owner.ts @@ -1,236 +1,243 @@ -import { EmbedBuilder, MessageFlags, SlashCommandBuilder } from "discord.js"; -import { prisma } from "../../lib/prisma.ts"; -import emoji from "../../../assets/emoji.json" assert { type: "json" }; +import { EmbedBuilder, MessageFlags, SlashCommandBuilder } from 'discord.js'; +import { prisma } from '../../lib/prisma.ts'; +import emoji from '../../../assets/emoji.json' assert { type: 'json' }; export default { - data: new SlashCommandBuilder() - .setName("owner") - .setDescription("Interact with the owners") - .addSubcommand((subcommand) => - subcommand - .setName("add") - .setDescription("Add a user on the owner list") - .addUserOption((option) => - option - .setName("target") - .setDescription("The user who will be added to the list") - .setRequired(true), - ), - ) - .addSubcommand((subcommand) => - subcommand - .setName("delete") - .setDescription("Delete a user on the owner list") - .addUserOption((option) => - option - .setName("target") - .setDescription("The user who will be deleted to the list") - .setRequired(true), - ), - ) - .addSubcommand((subcommand) => - subcommand.setName("list").setDescription("The list of the owner"), - ), - async execute(interaction: CommandInteraction) { - const subcommand = interaction.options.getSubcommand(); - let userData: User; - try { - userData = await prisma.user.findUnique({ - where: { - id: interaction.user.id, - }, - }); - } catch (err) { - console.error( - `\t⚠️ | Cannot get the database connection!\n\t\t(${err}).`, - ); - await interaction.reply({ - content: `${emoji.answer.error} | Cannot connect to the database`, - flags: MessageFlags.Ephemeral, - }); - return; - } - let guildData: Guild; - try { - guildData = await prisma.guild.findUnique({ - where: { - id: interaction.guild.id, - }, - }); - } catch (err) { - console.error( - `\t⚠️ | Cannot get the database connection!\n\t\t(${err}).`, - ); - await interaction.reply({ - content: `${emoji.answer.error} | Cannot connect to the database`, - flags: MessageFlags.Ephemeral, - }); - return; - } - const target: GuildMember = interaction.options.getUser("target"); - switch (subcommand) { - case "add": - if (!userData.isBuyer) { - await interaction.reply({ - content: `${emoji.answer.no} | This command is only for buyer`, - flags: MessageFlags.Ephemeral, - }); - return; - } - try { - await prisma.bot.update({ - where: { - id: 1, - }, - data: { - owners: { - connect: { - id: target.id, - }, - }, - }, - }); - await prisma.user.upsert({ - where: { - id: target.id, - }, - update: { - isOwner: true, - }, - create: { - id: target.id, - isOwner: true, - }, - }); - } catch (err) { - console.error( - `⚠️ | Error when adding ${target.username} to the owner list\n\t${err}`, - ); - await interaction.reply({ - content: `${emoji.answer.error} | Error when adding ${target.username} to the owner list`, - flags: MessageFlags.Ephemeral, - }); - return; - } - await interaction.reply({ - content: `${emoji.answer.yes} | ${target.username} has been added to the owner list`, - flags: MessageFlags.Ephemeral, - }); - return; - case "delete": - if (!userData.isBuyer) { - await interaction.reply({ - content: `${emoji.answer.no} | This command is only for buyer`, - flags: MessageFlags.Ephemeral, - }); - return; - } else if (interaction.user.id === target.id) { - await interaction.reply({ - content: `${emoji.answer.no} | You cannot removing yourself from the owner list`, - flags: MessageFlags.Ephemeral, - }); - return; - } - try { - await prisma.bot.update({ - where: { - id: 1, - }, - data: { - owners: { - disconnect: { - id: target.id, - }, - }, - }, - }); - await prisma.user.upsert({ - where: { - id: target.id, - }, - update: { - isOwner: false, - }, - create: { - id: target.id, - isOwner: false, - }, - }); - } catch (err) { - console.error( - `⚠️ | Error when removing ${target.username} to the owner list\n\t${err}`, - ); - await interaction.reply({ - content: `${emoji.answer.error} | Cannot removing the user from the owner list`, - flags: MessageFlags.Ephemeral, - }); - return; - } - await interaction.reply({ - content: `${emoji.answer.yes} | ${target.username} has been removing to the owner list`, - flags: MessageFlags.Ephemeral, - }); - return; - case "list": - if (!userData.isOwner) { - await interaction.reply({ - content: `${emoji.answer.no} | This command is only for owner`, - flags: MessageFlags.Ephemeral, - }); - return; - } - try { - const bot = await prisma.bot.findUnique({ - where: { - id: 1, - }, - include: { - owners: true, - }, - }); + data: new SlashCommandBuilder() + .setName('owner') + .setDescription('Interact with the owners') + .addSubcommand((subcommand) => + subcommand + .setName('add') + .setDescription('Add a user on the owner list') + .addUserOption((option) => + option + .setName('target') + .setDescription('The user who will be added to the list') + .setRequired(true), + ), + ) + .addSubcommand((subcommand) => + subcommand + .setName('delete') + .setDescription('Delete a user on the owner list') + .addUserOption((option) => + option + .setName('target') + .setDescription('The user who will be deleted to the list') + .setRequired(true), + ), + ) + .addSubcommand((subcommand) => + subcommand.setName('list').setDescription('The list of the owner'), + ), + async execute(interaction: CommandInteraction) { + const subcommand = interaction.options.getSubcommand(); + let userData: User; + try { + userData = await prisma.user.findUnique({ + where: { + id: interaction.user.id, + }, + }); + } + catch (err) { + console.error( + `\t⚠️ | Cannot get the database connection!\n\t\t(${err}).`, + ); + await interaction.reply({ + content: `${emoji.answer.error} | Cannot connect to the database`, + flags: MessageFlags.Ephemeral, + }); + return; + } + let guildData: Guild; + try { + guildData = await prisma.guild.findUnique({ + where: { + id: interaction.guild.id, + }, + }); + } + catch (err) { + console.error( + `\t⚠️ | Cannot get the database connection!\n\t\t(${err}).`, + ); + await interaction.reply({ + content: `${emoji.answer.error} | Cannot connect to the database`, + flags: MessageFlags.Ephemeral, + }); + return; + } + const target: GuildMember = interaction.options.getUser('target'); + switch (subcommand) { + case 'add': + if (!userData.isBuyer) { + await interaction.reply({ + content: `${emoji.answer.no} | This command is only for buyer`, + flags: MessageFlags.Ephemeral, + }); + return; + } + try { + await prisma.bot.update({ + where: { + id: 1, + }, + data: { + owners: { + connect: { + id: target.id, + }, + }, + }, + }); + await prisma.user.upsert({ + where: { + id: target.id, + }, + update: { + isOwner: true, + }, + create: { + id: target.id, + isOwner: true, + }, + }); + } + catch (err) { + console.error( + `⚠️ | Error when adding ${target.username} to the owner list\n\t${err}`, + ); + await interaction.reply({ + content: `${emoji.answer.error} | Error when adding ${target.username} to the owner list`, + flags: MessageFlags.Ephemeral, + }); + return; + } + await interaction.reply({ + content: `${emoji.answer.yes} | ${target.username} has been added to the owner list`, + flags: MessageFlags.Ephemeral, + }); + return; + case 'delete': + if (!userData.isBuyer) { + await interaction.reply({ + content: `${emoji.answer.no} | This command is only for buyer`, + flags: MessageFlags.Ephemeral, + }); + return; + } + else if (interaction.user.id === target.id) { + await interaction.reply({ + content: `${emoji.answer.no} | You cannot removing yourself from the owner list`, + flags: MessageFlags.Ephemeral, + }); + return; + } + try { + await prisma.bot.update({ + where: { + id: 1, + }, + data: { + owners: { + disconnect: { + id: target.id, + }, + }, + }, + }); + await prisma.user.upsert({ + where: { + id: target.id, + }, + update: { + isOwner: false, + }, + create: { + id: target.id, + isOwner: false, + }, + }); + } + catch (err) { + console.error( + `⚠️ | Error when removing ${target.username} to the owner list\n\t${err}`, + ); + await interaction.reply({ + content: `${emoji.answer.error} | Cannot removing the user from the owner list`, + flags: MessageFlags.Ephemeral, + }); + return; + } + await interaction.reply({ + content: `${emoji.answer.yes} | ${target.username} has been removing to the owner list`, + flags: MessageFlags.Ephemeral, + }); + return; + case 'list': + if (!userData.isOwner) { + await interaction.reply({ + content: `${emoji.answer.no} | This command is only for owner`, + flags: MessageFlags.Ephemeral, + }); + return; + } + try { + const bot = await prisma.bot.findUnique({ + where: { + id: 1, + }, + include: { + owners: true, + }, + }); - if (!bot || bot.owners.length === 0) { - await interaction.reply({ - content: `${emoji.answer.error} | There is no owner registered.`, - flags: MessageFlags.Ephemeral, - }); - break; - } + if (!bot || bot.owners.length === 0) { + await interaction.reply({ + content: `${emoji.answer.error} | There is no owner registered.`, + flags: MessageFlags.Ephemeral, + }); + break; + } - const ownerList = await Promise.all( - bot.owners.map(async (owner) => { - try { - const user = await interaction.client.users.fetch(owner.id); - return `- ${user.username} (\`${user.id}\`)\n`; - } catch (err) { - console.warn(`⚠️ | ${owner.id} : ${err}`); - return null; - } - }), - ); + const ownerList = await Promise.all( + bot.owners.map(async (owner) => { + try { + const user = await interaction.client.users.fetch(owner.id); + return `- ${user.username} (\`${user.id}\`)\n`; + } + catch (err) { + console.warn(`⚠️ | ${owner.id} : ${err}`); + return null; + } + }), + ); - const toSend: EmbedBuilder = new EmbedBuilder() - .setTitle(`${emoji.badge.owner} | Owner list`) - .setColor(guildData.color) - .setFooter({ - text: guildData.footer, - }) - .setDescription(ownerList.filter(Boolean).join("")); - await interaction.reply({ - embeds: [toSend], - flags: MessageFlags.Ephemeral, - }); - } catch (err) { - console.error( - `⚠️ | error when fetching infromation from the database: ${err}`, - ); - await interaction.reply({ - content: `${emoji.answer.error} | Cannot fetch the infromation of the database.`, - flags: MessageFlags.Ephemeral, - }); - } - break; - return; - } - }, + const toSend: EmbedBuilder = new EmbedBuilder() + .setTitle(`${emoji.badge.owner} | Owner list`) + .setColor(guildData.color) + .setFooter({ + text: guildData.footer, + }) + .setDescription(ownerList.filter(Boolean).join('')); + await interaction.reply({ + embeds: [toSend], + flags: MessageFlags.Ephemeral, + }); + } + catch (err) { + console.error( + `⚠️ | error when fetching infromation from the database: ${err}`, + ); + await interaction.reply({ + content: `${emoji.answer.error} | Cannot fetch the infromation of the database.`, + flags: MessageFlags.Ephemeral, + }); + } + break; + return; + } + }, }; diff --git a/src/commands/rank/whitelist.ts b/src/commands/rank/whitelist.ts index 0f11426..44af477 100644 --- a/src/commands/rank/whitelist.ts +++ b/src/commands/rank/whitelist.ts @@ -1,244 +1,251 @@ -import { EmbedBuilder, MessageFlags, SlashCommandBuilder } from "discord.js"; -import { prisma } from "../../lib/prisma.ts"; -import emoji from "../../../assets/emoji.json" assert { type: "json" }; +import { EmbedBuilder, MessageFlags, SlashCommandBuilder } from 'discord.js'; +import { prisma } from '../../lib/prisma.ts'; +import emoji from '../../../assets/emoji.json' assert { type: 'json' }; export default { - data: new SlashCommandBuilder() - .setName("whitelist") - .setDescription("Interact with the whitelist") - .addSubcommand((subcommand) => - subcommand - .setName("add") - .setDescription("Add a user on the whitelist") - .addUserOption((option) => - option - .setName("target") - .setDescription("The user who will be added to the whitelist") - .setRequired(true), - ), - ) - .addSubcommand((subcommand) => - subcommand - .setName("delete") - .setDescription("Delete a user on the whitelist") - .addUserOption((option) => - option - .setName("target") - .setDescription("The user who will be deleted to the whitelist") - .setRequired(true), - ), - ) - .addSubcommand((subcommand) => - subcommand.setName("list").setDescription("Show the whitelist"), - ), - async execute(interaction: CommandInteraction) { - const subcommand = interaction.options.getSubcommand(); - let userData: User; - try { - userData = await prisma.user.findUnique({ - where: { - id: interaction.user.id, - }, - }); - } catch (err) { - console.error( - `\t⚠️ | Whitelist => Cannot get the database connection!\n\t\t(${err}).`, - ); - await interaction.reply({ - content: `${emoji.answer.error} | Cannot connect to the database`, - flags: MessageFlags.Ephemeral, - }); - return; - } - let guildData: Guild; - try { - guildData = await prisma.guild.findUnique({ - where: { - id: interaction.guild.id, - }, - }); - } catch (err) { - console.error( - `\t⚠️ | Cannot get the database connection!\n\t\t(${err}).`, - ); - await interaction.reply({ - content: `${emoji.answer.error} | Cannot connect to the database`, - flags: MessageFlags.Ephemeral, - }); - return; - } - const target: GuildMember = interaction.options.getUser("target"); - switch (subcommand) { - case "add": - if (!userData.isOwner) { - await interaction.reply({ - content: `${emoji.answer.no} | This command is only for owner`, - flags: MessageFlags.Ephemeral, - }); - return; - } - try { - await prisma.guildUser.upsert({ - where: { - userId_guildId: { - userId: target.id, - guildId: interaction.guild.id, - }, - }, - update: { - isWlUser: true, - }, - create: { - userId: target.id, - guildId: interaction.guild.id, - isWlUser: true, - }, - }); - await prisma.guild.update({ - where: { - id: interaction.guild.id, - }, - data: { - WlUsers: { - connect: { - id: target.id, - }, - }, - }, - }); - } catch (err) { - console.error( - `⚠️ | Error when adding ${target.username} to the whitelist\n\t${err}`, - ); - await interaction.reply({ - content: `${emoji.answer.error} | Error when adding ${target.username} to the whitelist`, - flags: MessageFlags.Ephemeral, - }); - return; - } - await interaction.reply({ - content: `${emoji.answer.yes} | ${target.username} has been added to the whitelist`, - flags: MessageFlags.Ephemeral, - }); - return; - case "delete": - if (!userData.isOwner) { - await interaction.reply({ - content: `${emoji.answer.no} | This command is only for owner`, - flags: MessageFlags.Ephemeral, - }); - return; - } else if (interaction.user.id === target.id) { - await interaction.reply({ - content: `${emoji.answer.no} | You cannot removing yourself from the whitelist`, - flags: MessageFlags.Ephemeral, - }); - return; - } - try { - await prisma.guildUser.upsert({ - where: { - userId_guildId: { - userId: target.id, - guildId: interaction.guild.id, - }, - }, - update: { - isWlUser: false, - }, - create: { - userId: target.id, - guildId: interaction.guild.id, - isWlUser: false, - }, - }); - await prisma.guild.update({ - where: { - id: interaction.guild.id, - }, - data: { - WlUsers: { - disconnect: { - id: target.id, - }, - }, - }, - }); - } catch (err) { - console.error( - `⚠️ | Error when removing ${target.username} to the username\n\t${err}`, - ); - await interaction.reply({ - content: `${emoji.answer.error} | Cannot remove ${target.username} from the whitelist`, - flags: MessageFlags.Ephemeral, - }); - return; - } - await interaction.reply({ - content: `${emoji.answer.yes} | ${target.username} has been removing to the whitelist`, - flags: MessageFlags.Ephemeral, - }); - return; - case "list": - if (!userData.isOwner) { - await interaction.reply({ - content: `${emoji.answer.no} | This command is only for owner`, - flags: MessageFlags.Ephemeral, - }); - return; - } - try { - const guild = await prisma.guild.findUnique({ - where: { - id: interaction.guild.id, - }, - include: { - WlUsers: true, - }, - }); + data: new SlashCommandBuilder() + .setName('whitelist') + .setDescription('Interact with the whitelist') + .addSubcommand((subcommand) => + subcommand + .setName('add') + .setDescription('Add a user on the whitelist') + .addUserOption((option) => + option + .setName('target') + .setDescription('The user who will be added to the whitelist') + .setRequired(true), + ), + ) + .addSubcommand((subcommand) => + subcommand + .setName('delete') + .setDescription('Delete a user on the whitelist') + .addUserOption((option) => + option + .setName('target') + .setDescription('The user who will be deleted to the whitelist') + .setRequired(true), + ), + ) + .addSubcommand((subcommand) => + subcommand.setName('list').setDescription('Show the whitelist'), + ), + async execute(interaction: CommandInteraction) { + const subcommand = interaction.options.getSubcommand(); + let userData: User; + try { + userData = await prisma.user.findUnique({ + where: { + id: interaction.user.id, + }, + }); + } + catch (err) { + console.error( + `\t⚠️ | Whitelist => Cannot get the database connection!\n\t\t(${err}).`, + ); + await interaction.reply({ + content: `${emoji.answer.error} | Cannot connect to the database`, + flags: MessageFlags.Ephemeral, + }); + return; + } + let guildData: Guild; + try { + guildData = await prisma.guild.findUnique({ + where: { + id: interaction.guild.id, + }, + }); + } + catch (err) { + console.error( + `\t⚠️ | Cannot get the database connection!\n\t\t(${err}).`, + ); + await interaction.reply({ + content: `${emoji.answer.error} | Cannot connect to the database`, + flags: MessageFlags.Ephemeral, + }); + return; + } + const target: GuildMember = interaction.options.getUser('target'); + switch (subcommand) { + case 'add': + if (!userData.isOwner) { + await interaction.reply({ + content: `${emoji.answer.no} | This command is only for owner`, + flags: MessageFlags.Ephemeral, + }); + return; + } + try { + await prisma.guildUser.upsert({ + where: { + userId_guildId: { + userId: target.id, + guildId: interaction.guild.id, + }, + }, + update: { + isWlUser: true, + }, + create: { + userId: target.id, + guildId: interaction.guild.id, + isWlUser: true, + }, + }); + await prisma.guild.update({ + where: { + id: interaction.guild.id, + }, + data: { + WlUsers: { + connect: { + id: target.id, + }, + }, + }, + }); + } + catch (err) { + console.error( + `⚠️ | Error when adding ${target.username} to the whitelist\n\t${err}`, + ); + await interaction.reply({ + content: `${emoji.answer.error} | Error when adding ${target.username} to the whitelist`, + flags: MessageFlags.Ephemeral, + }); + return; + } + await interaction.reply({ + content: `${emoji.answer.yes} | ${target.username} has been added to the whitelist`, + flags: MessageFlags.Ephemeral, + }); + return; + case 'delete': + if (!userData.isOwner) { + await interaction.reply({ + content: `${emoji.answer.no} | This command is only for owner`, + flags: MessageFlags.Ephemeral, + }); + return; + } + else if (interaction.user.id === target.id) { + await interaction.reply({ + content: `${emoji.answer.no} | You cannot removing yourself from the whitelist`, + flags: MessageFlags.Ephemeral, + }); + return; + } + try { + await prisma.guildUser.upsert({ + where: { + userId_guildId: { + userId: target.id, + guildId: interaction.guild.id, + }, + }, + update: { + isWlUser: false, + }, + create: { + userId: target.id, + guildId: interaction.guild.id, + isWlUser: false, + }, + }); + await prisma.guild.update({ + where: { + id: interaction.guild.id, + }, + data: { + WlUsers: { + disconnect: { + id: target.id, + }, + }, + }, + }); + } + catch (err) { + console.error( + `⚠️ | Error when removing ${target.username} to the username\n\t${err}`, + ); + await interaction.reply({ + content: `${emoji.answer.error} | Cannot remove ${target.username} from the whitelist`, + flags: MessageFlags.Ephemeral, + }); + return; + } + await interaction.reply({ + content: `${emoji.answer.yes} | ${target.username} has been removing to the whitelist`, + flags: MessageFlags.Ephemeral, + }); + return; + case 'list': + if (!userData.isOwner) { + await interaction.reply({ + content: `${emoji.answer.no} | This command is only for owner`, + flags: MessageFlags.Ephemeral, + }); + return; + } + try { + const guild = await prisma.guild.findUnique({ + where: { + id: interaction.guild.id, + }, + include: { + WlUsers: true, + }, + }); - if (!guild || guild.WlUsers.length === 0) { - await interaction.reply({ - content: `${emoji.answer.error} | There is no whitelisted user.`, - flags: MessageFlags.Ephemeral, - }); - break; - } + if (!guild || guild.WlUsers.length === 0) { + await interaction.reply({ + content: `${emoji.answer.error} | There is no whitelisted user.`, + flags: MessageFlags.Ephemeral, + }); + break; + } - const WlUsers = await Promise.all( - guild.WlUsers.map(async (whitelist) => { - try { - const user = await interaction.client.users.fetch(whitelist.id); - return `- ${user.username} (\`${user.id}\`)\n`; - } catch (err) { - console.warn(`⚠️ | ${whitelist.id} : ${err}`); - return null; - } - }), - ); + const WlUsers = await Promise.all( + guild.WlUsers.map(async (whitelist) => { + try { + const user = await interaction.client.users.fetch(whitelist.id); + return `- ${user.username} (\`${user.id}\`)\n`; + } + catch (err) { + console.warn(`⚠️ | ${whitelist.id} : ${err}`); + return null; + } + }), + ); - const toSend: EmbedBuilder = new EmbedBuilder() - .setTitle("🗞️ | Whitelist") - .setColor(guildData.color) - .setFooter({ - text: guildData.footer, - }) - .setDescription(WlUsers.filter(Boolean).join("")); - await interaction.reply({ - embeds: [toSend], - flags: MessageFlags.Ephemeral, - }); - } catch (err) { - console.error( - `⚠️ | Whitelist => error when fetching infromation from the database: ${err}`, - ); - await interaction.reply({ - content: `${emoji.answer.error} | Cannot fetch the infromation of the database.`, - flags: MessageFlags.Ephemeral, - }); - } - break; - return; - } - }, + const toSend: EmbedBuilder = new EmbedBuilder() + .setTitle('🗞️ | Whitelist') + .setColor(guildData.color) + .setFooter({ + text: guildData.footer, + }) + .setDescription(WlUsers.filter(Boolean).join('')); + await interaction.reply({ + embeds: [toSend], + flags: MessageFlags.Ephemeral, + }); + } + catch (err) { + console.error( + `⚠️ | Whitelist => error when fetching infromation from the database: ${err}`, + ); + await interaction.reply({ + content: `${emoji.answer.error} | Cannot fetch the infromation of the database.`, + flags: MessageFlags.Ephemeral, + }); + } + break; + return; + } + }, }; diff --git a/src/commands/utils/deleteCategories.ts b/src/commands/utils/deleteCategories.ts index 608da8f..528d96c 100644 --- a/src/commands/utils/deleteCategories.ts +++ b/src/commands/utils/deleteCategories.ts @@ -1,68 +1,70 @@ -import { MessageFlags, ChannelType, SlashCommandBuilder } from "discord.js"; -import emoji from "../../../assets/emoji.json" assert { type: "json" }; -import { prisma } from "../../lib/prisma.ts"; +import { MessageFlags, ChannelType, SlashCommandBuilder } from 'discord.js'; +import emoji from '../../../assets/emoji.json' assert { type: 'json' }; +import { prisma } from '../../lib/prisma.ts'; export default { - data: new SlashCommandBuilder() - .setName("deletecat") - .setDescription("Delete the categorie given in parameter") - .addChannelOption((opt) => - opt - .setName("category") - .setDescription("Choose the categorie you want to delete") - .setRequired(true) - .addChannelTypes(ChannelType.GuildCategory), - ), - async execute(interaction: CommandInteraction) { - let userData: User; - try { - userData = await prisma.user.findUnique({ - where: { - id: interaction.user.id, - }, - }); - } catch (err) { - console.error( - `\t⚠️ | Whitelist => Cannot get the database connection!\n\t\t(${err}).`, - ); - await interaction.reply({ - content: `${emoji.answer.error} | Cannot connect to the database`, - flags: MessageFlags.Ephemeral, - }); - console.error(`Cannot connect to the database:\n\t${err}`); - return; - } - if (!userData.isOwner) { - await interaction.reply({ - content: `${emoji.answer.no} | This command is only for owner`, - flags: MessageFlags.Ephemeral, - }); - return; - } - const category: GuildCategory = interaction.options.getChannel( - "category", - true, - ); - try { - for (const channel of category.children.cache.values()) { - await channel.delete( - `Delete cat of ${channel.name} (by ${interaction.username})`, - ); - } - await category.delete( - `Delete cat of ${category.name} (by ${interaction.username})`, - ); - await interaction.reply({ - content: `${emoji.answer.yes} | Suppressed the ${category.name}`, - flags: MessageFlags.Ephemeral, - }); - } catch (err) { - await interaction.reply({ - content: `${emoji.answer.error} | Cannot suppress the category's channels`, - flags: MessageFlags.Ephemeral, - }); - console.error(`Cannot suppress the category's channel:\n\t${err}`); - return; - } - }, + data: new SlashCommandBuilder() + .setName('deletecat') + .setDescription('Delete the categorie given in parameter') + .addChannelOption((opt) => + opt + .setName('category') + .setDescription('Choose the categorie you want to delete') + .setRequired(true) + .addChannelTypes(ChannelType.GuildCategory), + ), + async execute(interaction: CommandInteraction) { + let userData: User; + try { + userData = await prisma.user.findUnique({ + where: { + id: interaction.user.id, + }, + }); + } + catch (err) { + console.error( + `\t⚠️ | Whitelist => Cannot get the database connection!\n\t\t(${err}).`, + ); + await interaction.reply({ + content: `${emoji.answer.error} | Cannot connect to the database`, + flags: MessageFlags.Ephemeral, + }); + console.error(`Cannot connect to the database:\n\t${err}`); + return; + } + if (!userData.isOwner) { + await interaction.reply({ + content: `${emoji.answer.no} | This command is only for owner`, + flags: MessageFlags.Ephemeral, + }); + return; + } + const category: GuildCategory = interaction.options.getChannel( + 'category', + true, + ); + try { + for (const channel of category.children.cache.values()) { + await channel.delete( + `Delete cat of ${channel.name} (by ${interaction.username})`, + ); + } + await category.delete( + `Delete cat of ${category.name} (by ${interaction.username})`, + ); + await interaction.reply({ + content: `${emoji.answer.yes} | Suppressed the ${category.name}`, + flags: MessageFlags.Ephemeral, + }); + } + catch (err) { + await interaction.reply({ + content: `${emoji.answer.error} | Cannot suppress the category's channels`, + flags: MessageFlags.Ephemeral, + }); + console.error(`Cannot suppress the category's channel:\n\t${err}`); + return; + } + }, }; diff --git a/src/commands/utils/info.ts b/src/commands/utils/info.ts index 4493067..bb28836 100644 --- a/src/commands/utils/info.ts +++ b/src/commands/utils/info.ts @@ -1,29 +1,29 @@ -import { prisma } from "../../lib/prisma.ts"; +import { prisma } from '../../lib/prisma.ts'; import { - userMention, - roleMention, - MessageFlags, - SlashCommandBuilder, - EmbedBuilder, -} from "discord.js"; -import emoji from "../../../assets/emoji.json" assert { type: "json" }; + userMention, + roleMention, + MessageFlags, + SlashCommandBuilder, + EmbedBuilder, +} from 'discord.js'; +import emoji from '../../../assets/emoji.json' assert { type: 'json' }; function getGuildRoles(guild: Guild): string { - const roles = guild.roles.cache - .filter((role) => role.id !== guild.id) - .sort((a, b) => b.position - a.position) - .map((role) => roleMention(role.id)); + const roles = guild.roles.cache + .filter((role) => role.id !== guild.id) + .sort((a, b) => b.position - a.position) + .map((role) => roleMention(role.id)); - return roles.length > 0 ? roles.join(", ") : "No role"; + return roles.length > 0 ? roles.join(', ') : 'No role'; } 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)}`); + 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(", ") : "No role"; + return roles.length > 0 ? roles.join(', ') : 'No role'; } function getUserBadges(userData: { @@ -32,105 +32,108 @@ function getUserBadges(userData: { isBuyer?: boolean; isOwner?: boolean; }): string { - const badges: string[] = []; + const badges: string[] = []; - if (userData.isDev) badges.push(`${emoji.badge.dev}`); - if (userData.isEnium) badges.push(`${emoji.badge.enium}`); - if (userData.isPwn) badges.push(`${emoji.badge.dash}`); - if (userData.isBuyer) badges.push(`${emoji.badge.buyer}`); - if (userData.isOwner) badges.push(`${emoji.badge.owner}`); + if (userData.isDev) badges.push(`${emoji.badge.dev}`); + if (userData.isEnium) badges.push(`${emoji.badge.enium}`); + if (userData.isPwn) badges.push(`${emoji.badge.dash}`); + if (userData.isBuyer) badges.push(`${emoji.badge.buyer}`); + if (userData.isOwner) badges.push(`${emoji.badge.owner}`); - return badges.length > 0 ? badges.join(" ") : "Aucun badge"; + return badges.length > 0 ? badges.join(' ') : 'Aucun badge'; } export default { - data: new SlashCommandBuilder() - .setName("info") - .setDescription( - "Show the infromation of one of these categories (user, server, bot)", - ) - .addSubcommand((subcommand) => - subcommand - .setName("user") - .setDescription("Show the infromation of one user") - .addUserOption((option) => - option - .setName("target") - .setDescription("The user to show the infromation"), - ), - ) - .addSubcommand((subcommand) => - subcommand - .setName("server") - .setDescription("Show the infromation 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⚠️ | Cannot get the database connection!\n\t\t(${err}).`, - ); - await interaction.reply({ - content: `${emoji.answer.error} | Cannot connect to the database`, - flags: MessageFlags.Ephemeral, - }); - return; - } - 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⚠️ | Cannot get the database connection!\n\t\t(${err}).`, - ); - await interaction.reply({ - content: `${emoji.answer.error} | Cannot connect to the database`, - flags: MessageFlags.Ephemeral, - }); - } - let targetServer: GuildMember; + data: new SlashCommandBuilder() + .setName('info') + .setDescription( + 'Show the infromation of one of these categories (user, server, bot)', + ) + .addSubcommand((subcommand) => + subcommand + .setName('user') + .setDescription('Show the infromation of one user') + .addUserOption((option) => + option + .setName('target') + .setDescription('The user to show the infromation'), + ), + ) + .addSubcommand((subcommand) => + subcommand + .setName('server') + .setDescription('Show the infromation 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⚠️ | Cannot get the database connection!\n\t\t(${err}).`, + ); + await interaction.reply({ + content: `${emoji.answer.error} | Cannot connect to the database`, + flags: MessageFlags.Ephemeral, + }); + return; + } + 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⚠️ | Cannot get the database connection!\n\t\t(${err}).`, + ); + await interaction.reply({ + content: `${emoji.answer.error} | Cannot connect to the database`, + flags: MessageFlags.Ephemeral, + }); + } + let targetServer: GuildMember; - try { - targetServer = await interaction.guild.members.fetch(targetGlobal.id); - } catch (err) { - console.error(`\t⚠️ | Cannot get the targetServer!\n\t\t(${err}).`); - await interaction.reply({ - content: `${emoji.answer.error} | Cannot get the guild profile of the user`, - flags: MessageFlags.Ephemeral, - }); - return; - } - const userResult: EmbedBuilder = new EmbedBuilder() - .setTitle(`${targetGlobal.displayName}'s information`) - .setColor(`${guildData.color}`) - .setThumbnail( - `${targetGlobal.displayAvatarURL({ dynamic: true, size: 2048 })}`, - ) - .setFooter({ - text: guildData.footer, - }) - .setImage( - targetGlobal.bannerURL({ - size: 2048, - dynamic: true, - }), - ).setDescription(` + try { + targetServer = await interaction.guild.members.fetch(targetGlobal.id); + } + catch (err) { + console.error(`\t⚠️ | Cannot get the targetServer!\n\t\t(${err}).`); + await interaction.reply({ + content: `${emoji.answer.error} | Cannot get the guild profile of the user`, + flags: MessageFlags.Ephemeral, + }); + return; + } + const userResult: EmbedBuilder = new EmbedBuilder() + .setTitle(`${targetGlobal.displayName}'s information`) + .setColor(`${guildData.color}`) + .setThumbnail( + `${targetGlobal.displayAvatarURL({ dynamic: true, size: 2048 })}`, + ) + .setFooter({ + text: guildData.footer, + }) + .setImage( + targetGlobal.bannerURL({ + size: 2048, + dynamic: true, + }), + ).setDescription(` **👤 | Username:** ${targetGlobal.username} **🆔 | ID:** @@ -146,30 +149,30 @@ export default { **🛬 | 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: 2048 })) - .setFooter({ - text: guildData.footer, - }) - .setImage(guild.bannerURL({ dynamic: true, size: 2048 })) - .setDescription(` + 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: 2048 })) + .setFooter({ + text: guildData.footer, + }) + .setImage(guild.bannerURL({ dynamic: true, size: 2048 })) + .setDescription(` **🆔 | ID:** ${guild.id} **🖊️ | Description:** - ${guild.description || "No description given."} + ${guild.description || 'No description given.'} **🔗 | VanityLink:** - ${guild.vanityURLCode || "No custom link."} + ${guild.vanityURLCode || 'No custom link.'} **🆕 | Creation Date:** @@ -187,11 +190,11 @@ export default { There is ${guild.roles.cache.size - 1} on __${guild.name}__ ${getGuildRoles(guild)} `); - await interaction.reply({ - embeds: [serverResult], - flags: MessageFlags.Ephemeral, - }); - } - } - }, + await interaction.reply({ + embeds: [serverResult], + flags: MessageFlags.Ephemeral, + }); + } + } + }, }; diff --git a/src/commands/utils/ping.ts b/src/commands/utils/ping.ts index aa3ab60..316c89c 100644 --- a/src/commands/utils/ping.ts +++ b/src/commands/utils/ping.ts @@ -1,19 +1,19 @@ -import { MessageFlags, SlashCommandBuilder } from "discord.js"; -import emoji from "../../../assets/emoji.json" assert { type: "json" }; +import { MessageFlags, SlashCommandBuilder } from 'discord.js'; +import emoji from '../../../assets/emoji.json' assert { type: 'json' }; export default { - data: new SlashCommandBuilder() - .setName("ping") - .setDescription("Show your latency"), - async execute(interaction: CommandInteraction) { - const time: number = Date.now(); - await interaction.reply({ - content: `${emoji.answer.loading} | Calculating your ping !`, - flags: MessageFlags.Ephemeral, - }); + data: new SlashCommandBuilder() + .setName('ping') + .setDescription('Show your latency'), + async execute(interaction: CommandInteraction) { + const time: number = Date.now(); + await interaction.reply({ + content: `${emoji.answer.loading} | Calculating your ping !`, + flags: MessageFlags.Ephemeral, + }); - await interaction.editReply({ - content: `⏱️ | Response latency: **${Date.now() - time}**ms`, - }); - }, + await interaction.editReply({ + content: `⏱️ | Response latency: **${Date.now() - time}**ms`, + }); + }, }; diff --git a/src/events/client/guildCreate.ts b/src/events/client/guildCreate.ts index 2eadf69..4af721f 100644 --- a/src/events/client/guildCreate.ts +++ b/src/events/client/guildCreate.ts @@ -1,48 +1,48 @@ -import { Events } from "discord.js"; -import { prisma } from "../../lib/prisma.ts"; +import { Events } from 'discord.js'; +import { prisma } from '../../lib/prisma.ts'; export default { - name: Events.GuildCreate, - async execute(guild) { - await prisma.guild.upsert({ - where: { - id: guild.id, - }, - update: {}, - create: { - id: guild.id, - }, - }); + name: Events.GuildCreate, + async execute(guild) { + await prisma.guild.upsert({ + where: { + id: guild.id, + }, + update: {}, + create: { + id: guild.id, + }, + }); - const members = await guild.members.fetch(); - for (const [memberId] of members) { - await prisma.user.upsert({ - where: { - id: memberId, - }, - update: {}, - create: { - id: memberId, - }, - }); + const members = await guild.members.fetch(); + for (const [memberId] of members) { + await prisma.user.upsert({ + where: { + id: memberId, + }, + update: {}, + create: { + id: memberId, + }, + }); - await prisma.guildUser.upsert({ - where: { - userId_guildId: { - userId: memberId, - guildId: guild.id, - }, - }, - update: {}, - create: { - userId: memberId, - guildId: guild.id, - }, - }); - i++; - } - console.log( - `✅ | Guild ${guild.name} synchronisée avec ${members.size} membres.`, - ); - }, + await prisma.guildUser.upsert({ + where: { + userId_guildId: { + userId: memberId, + guildId: guild.id, + }, + }, + update: {}, + create: { + userId: memberId, + guildId: guild.id, + }, + }); + i++; + } + console.log( + `✅ | Guild ${guild.name} synchronisée avec ${members.size} membres.`, + ); + }, }; diff --git a/src/events/client/ready.ts b/src/events/client/ready.ts index e346e3c..f489bae 100644 --- a/src/events/client/ready.ts +++ b/src/events/client/ready.ts @@ -1,80 +1,82 @@ -import { ActivityType, PresenceUpdateStatus, Events } from "discord.js"; -import { prisma } from "../../lib/prisma.ts"; +import { ActivityType, PresenceUpdateStatus, Events } from 'discord.js'; +import { prisma } from '../../lib/prisma.ts'; export default { - name: Events.ClientReady, - once: true, - async execute(client) { - try { - const botData: Bot = await prisma.bot.findUnique({ - where: { - id: 1, - }, - }); - const newStatus: string = botData.status; - const tmpType: string = botData.type; - let newType: ActivityType; - switch (tmpType) { - case "play": - newType = ActivityType.Playing; - break; - case "listen": - newType = ActivityType.Listening; - break; - case "watch": - newType = ActivityType.Watching; - break; - case "stream": - newType = ActivityType.Streaming; - break; - case "comptet": - newType = ActivityType.Competing; - break; - } - const tmpPresence: string = botData.presence; - let newPresence: PresenceUpdateStatus; - switch (tmpPresence) { - case "online": - newPresence = PresenceUpdateStatus.Online; - break; - case "idle": - newPresence = PresenceUpdateStatus.Idle; - break; - case "dnd": - newPresence = PresenceUpdateStatus.DoNotDisturb; - break; - case "invisible": - newPresence = PresenceUpdateStatus.Invisible; - break; - } - if (botData.type === "steam") { - client.user.setPresence({ - status: newPresence, - activities: [ - { - name: newStatus, - type: newType, - url: "https://twich.tv/EniumRaphael", - }, - ], - }); - } else { - client.user.setPresence({ - status: newPresence, - activities: [ - { - name: newStatus, - type: newType, - }, - ], - }); - } - } catch (err) { - console.error( - `\t⚠️ | Cannot get the database connection!\n\t\t(${err}).`, - ); - return; - } - console.log(`✅ | ${client.user.username} is now running under TTS bot`); - }, + name: Events.ClientReady, + once: true, + async execute(client) { + try { + const botData: Bot = await prisma.bot.findUnique({ + where: { + id: 1, + }, + }); + const newStatus: string = botData.status; + const tmpType: string = botData.type; + let newType: ActivityType; + switch (tmpType) { + case 'play': + newType = ActivityType.Playing; + break; + case 'listen': + newType = ActivityType.Listening; + break; + case 'watch': + newType = ActivityType.Watching; + break; + case 'stream': + newType = ActivityType.Streaming; + break; + case 'comptet': + newType = ActivityType.Competing; + break; + } + const tmpPresence: string = botData.presence; + let newPresence: PresenceUpdateStatus; + switch (tmpPresence) { + case 'online': + newPresence = PresenceUpdateStatus.Online; + break; + case 'idle': + newPresence = PresenceUpdateStatus.Idle; + break; + case 'dnd': + newPresence = PresenceUpdateStatus.DoNotDisturb; + break; + case 'invisible': + newPresence = PresenceUpdateStatus.Invisible; + break; + } + if (botData.type === 'steam') { + client.user.setPresence({ + status: newPresence, + activities: [ + { + name: newStatus, + type: newType, + url: 'https://twich.tv/EniumRaphael', + }, + ], + }); + } + else { + client.user.setPresence({ + status: newPresence, + activities: [ + { + name: newStatus, + type: newType, + }, + ], + }); + } + } + catch (err) { + console.error( + `\t⚠️ | Cannot get the database connection!\n\t\t(${err}).`, + ); + return; + } + console.log(`✅ | ${client.user.username} is now running under TTS bot`); + }, }; diff --git a/src/events/interaction/interaction.ts b/src/events/interaction/interaction.ts index f21fce9..7d5d7e4 100644 --- a/src/events/interaction/interaction.ts +++ b/src/events/interaction/interaction.ts @@ -1,36 +1,38 @@ -import { Events, MessageFlags } from "discord.js"; -import emoji from "../../../assets/emoji.json" assert { type: "json" }; +import { Events, MessageFlags } from 'discord.js'; +import emoji from '../../../assets/emoji.json' assert { type: 'json' }; export default { - name: Events.InteractionCreate, - async execute(interaction) { - if (!interaction.isChatInputCommand()) return; - const command = interaction.client.commands.get(interaction.commandName); - if (!command) { - console.error(`⚠️ | Can't execute ${interaction.commandName}`); - await interaction.reply({ - content: `${emoji.answer.error} | Cannot execute the command ${interaction.commandName}`, - flags: MessageFlags.Ephemeral, - }); - return; - } - try { - await command.execute(interaction); - } catch (error) { - console.error( - `⚠️ | Error when occured this command ${interaction.commandName}\n\t${error}`, - ); - if (interaction.replied || interaction.deferred) { - await interaction.followUp({ - content: `${emoji.answer.error} | ${interaction.commandName} seems have a problem, thanks report that to the support (After Print)`, - flags: MessageFlags.Ephemeral, - }); - } else { - await interaction.reply({ - content: `${emoji.answer.error} | ${interaction.commandName} seems have a problem, thanks report that to the support (Before Print)`, - flags: MessageFlags.Ephemeral, - }); - } - } - }, + name: Events.InteractionCreate, + async execute(interaction) { + if (!interaction.isChatInputCommand()) return; + const command = interaction.client.commands.get(interaction.commandName); + if (!command) { + console.error(`⚠️ | Can't execute ${interaction.commandName}`); + await interaction.reply({ + content: `${emoji.answer.error} | Cannot execute the command ${interaction.commandName}`, + flags: MessageFlags.Ephemeral, + }); + return; + } + try { + await command.execute(interaction); + } + catch (error) { + console.error( + `⚠️ | Error when occured this command ${interaction.commandName}\n\t${error}`, + ); + if (interaction.replied || interaction.deferred) { + await interaction.followUp({ + content: `${emoji.answer.error} | ${interaction.commandName} seems have a problem, thanks report that to the support (After Print)`, + flags: MessageFlags.Ephemeral, + }); + } + else { + await interaction.reply({ + content: `${emoji.answer.error} | ${interaction.commandName} seems have a problem, thanks report that to the support (Before Print)`, + flags: MessageFlags.Ephemeral, + }); + } + } + }, }; diff --git a/src/index.ts b/src/index.ts index 0e852cb..ce840aa 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,129 +1,132 @@ -import fs from "node:fs"; -import path from "node:path"; -import "dotenv/config"; -import { Client, Collection, GatewayIntentBits } from "discord.js"; -import { PrismaClient } from "@prisma/client"; +import fs from 'node:fs'; +import path from 'node:path'; +import 'dotenv/config'; +import { Client, Collection, GatewayIntentBits } from 'discord.js'; +import { PrismaClient } from '@prisma/client'; const prisma = new PrismaClient(); const client = new Client({ - intents: [ - GatewayIntentBits.Guilds, - GatewayIntentBits.GuildMessages, - GatewayIntentBits.MessageContent, - GatewayIntentBits.GuildMembers, - ], + intents: [ + GatewayIntentBits.Guilds, + GatewayIntentBits.GuildMessages, + GatewayIntentBits.MessageContent, + GatewayIntentBits.GuildMembers, + ], }); client.login(process.env.DSC_TOKEN); client.commands = new Collection(); -const commandFolderPath = path.join(__dirname, "commands"); +const commandFolderPath = path.join(__dirname, 'commands'); const commandFolders = fs.readdirSync(commandFolderPath); -console.log("\n🔍 | Commands search:"); +console.log('\n🔍 | Commands search:'); for (const folder of commandFolders) { - const commandsPath = path.join(commandFolderPath, folder); - const commandFiles = fs - .readdirSync(commandsPath) - .filter((file) => file.endsWith(".js") || file.endsWith(".ts")); - for (const file of commandFiles) { - const fullCommandPath = path.join(commandsPath, file); - try { - const commandModule = await import(fullCommandPath); - const command = commandModule.default || commandModule; - if ("data" in command && "execute" in command) { - client.commands.set(command.data.name, command); - console.log(`\t✅ | ${command.data.name}`); - } - } catch (err) { - console.error(`\t⚠️ | Command at ${file}\n\t\t(${err}).`); - } - } + const commandsPath = path.join(commandFolderPath, folder); + const commandFiles = fs + .readdirSync(commandsPath) + .filter((file) => file.endsWith('.js') || file.endsWith('.ts')); + for (const file of commandFiles) { + const fullCommandPath = path.join(commandsPath, file); + try { + const commandModule = await import(fullCommandPath); + const command = commandModule.default || commandModule; + if ('data' in command && 'execute' in command) { + client.commands.set(command.data.name, command); + console.log(`\t✅ | ${command.data.name}`); + } + } + catch (err) { + console.error(`\t⚠️ | Command at ${file}\n\t\t(${err}).`); + } + } } -console.log("\n\n"); +console.log('\n\n'); -const eventFolderPath = path.join(__dirname, "events"); +const eventFolderPath = path.join(__dirname, 'events'); const eventFolders = fs.readdirSync(eventFolderPath); -console.log("\n🔍 | Events search:"); +console.log('\n🔍 | Events search:'); for (const folder of eventFolders) { - const eventsPath = path.join(eventFolderPath, folder); - const eventFiles = fs - .readdirSync(eventsPath) - .filter((file) => file.endsWith(".js") || file.endsWith(".ts")); - for (const file of eventFiles) { - const fullEventPath = path.join(eventsPath, file); - try { - const eventModule = await import(fullEventPath); - const event = eventModule.default || eventModule; - if ("name" in event && "execute" in event) { - if (event.once) { - client.once(event.name, (...args) => event.execute(...args)); - } else { - client.on(event.name, (...args) => event.execute(...args)); - } - console.log(`\t✅ | ${event.name}`); - } - } catch (err) { - console.error(`\t⚠️ | Event at ${file}\n\t\t(${err}).`); - } - } + const eventsPath = path.join(eventFolderPath, folder); + const eventFiles = fs + .readdirSync(eventsPath) + .filter((file) => file.endsWith('.js') || file.endsWith('.ts')); + for (const file of eventFiles) { + const fullEventPath = path.join(eventsPath, file); + try { + const eventModule = await import(fullEventPath); + const event = eventModule.default || eventModule; + if ('name' in event && 'execute' in event) { + if (event.once) { + client.once(event.name, (...args) => event.execute(...args)); + } + else { + client.on(event.name, (...args) => event.execute(...args)); + } + console.log(`\t✅ | ${event.name}`); + } + } + catch (err) { + console.error(`\t⚠️ | Event at ${file}\n\t\t(${err}).`); + } + } } -console.log("\n\n"); +console.log('\n\n'); -client.once("ready", async () => { - console.log(`🤖 | Connecté en tant que ${client.user?.tag}`); +client.once('ready', async () => { + console.log(`🤖 | Connecté en tant que ${client.user?.tag}`); - await prisma.bot.upsert({ - where: { - id: 1, - }, - update: {}, - create: {}, - }); - for (const [guildId, guild] of client.guilds.cache) { - await prisma.guild.upsert({ - where: { - id: guildId, - }, - update: {}, - create: { - id: guildId, - }, - }); + await prisma.bot.upsert({ + where: { + id: 1, + }, + update: {}, + create: {}, + }); + for (const [guildId, guild] of client.guilds.cache) { + await prisma.guild.upsert({ + where: { + id: guildId, + }, + update: {}, + create: { + id: guildId, + }, + }); - const members = await guild.members.fetch(); + const members = await guild.members.fetch(); - for (const [memberId] of members) { - await prisma.user.upsert({ - where: { - id: memberId, - }, - update: {}, - create: { - id: memberId, - }, - }); + for (const [memberId] of members) { + await prisma.user.upsert({ + where: { + id: memberId, + }, + update: {}, + create: { + id: memberId, + }, + }); - await prisma.guildUser.upsert({ - where: { - userId_guildId: { - userId: memberId, - guildId: guildId, - }, - }, - update: {}, - create: { - userId: memberId, - guildId: guildId, - }, - }); - } + await prisma.guildUser.upsert({ + where: { + userId_guildId: { + userId: memberId, + guildId: guildId, + }, + }, + update: {}, + create: { + userId: memberId, + guildId: guildId, + }, + }); + } - console.log( - `✅ | Guild ${guild.name} synchronisée avec ${members.size} membres.`, - ); - } + console.log( + `✅ | Guild ${guild.name} synchronisée avec ${members.size} membres.`, + ); + } }); diff --git a/src/internal/deploy-command.ts b/src/internal/deploy-command.ts index 0eabce8..d9d1d5b 100644 --- a/src/internal/deploy-command.ts +++ b/src/internal/deploy-command.ts @@ -1,52 +1,54 @@ -import { REST, Routes } from "discord.js"; -import { Client, Collection, GatewayIntentBits } from "discord.js"; -import "dotenv/config"; -import fs from "node:fs"; -import path from "node:path"; +import { REST, Routes } from 'discord.js'; +import { Client, Collection, GatewayIntentBits } from 'discord.js'; +import 'dotenv/config'; +import fs from 'node:fs'; +import path from 'node:path'; const client = new Client({ - intents: [GatewayIntentBits.Guilds], + intents: [GatewayIntentBits.Guilds], }); client.commands = new Collection(); const commands = []; -const foldersPath = path.join(__dirname, "../commands"); +const foldersPath = path.join(__dirname, '../commands'); const commandFolders = fs.readdirSync(foldersPath); for (const folder of commandFolders) { - const commandsPath = path.join(foldersPath, folder); - const commandFiles = fs - .readdirSync(commandsPath) - .filter((file) => file.endsWith(".ts") || file.endsWith(".js")); - for (const file of commandFiles) { - const filesPath = path.join(commandsPath, file); - const commandModule = await import(filesPath); - const command = commandModule.default || commandModule; - if ("data" in command && "execute" in command) { - commands.push(command.data.toJSON()); - } else { - console.log( - '⚠️ | A Command is missing a required "data" or "execute" property.', - ); - } - } + const commandsPath = path.join(foldersPath, folder); + const commandFiles = fs + .readdirSync(commandsPath) + .filter((file) => file.endsWith('.ts') || file.endsWith('.js')); + for (const file of commandFiles) { + const filesPath = path.join(commandsPath, file); + const commandModule = await import(filesPath); + const command = commandModule.default || commandModule; + if ('data' in command && 'execute' in command) { + commands.push(command.data.toJSON()); + } + else { + console.log( + '⚠️ | A Command is missing a required "data" or "execute" property.', + ); + } + } } const rest = new REST().setToken(process.env.DSC_TOKEN); (async () => { - try { - console.log(`🔍 | ${commands.length} commands found.`); - const data = await rest.put( - Routes.applicationCommands(process.env.CLIENT_ID), - { - body: commands, - }, - ); - console.log(`✅ | ${data.length} is now reloaded`); - } catch (error) { - console.error(error); - } + try { + console.log(`🔍 | ${commands.length} commands found.`); + const data = await rest.put( + Routes.applicationCommands(process.env.CLIENT_ID), + { + body: commands, + }, + ); + console.log(`✅ | ${data.length} is now reloaded`); + } + catch (error) { + console.error(error); + } })(); diff --git a/src/lib/prisma.ts b/src/lib/prisma.ts index 901f3a0..9b6c4ce 100644 --- a/src/lib/prisma.ts +++ b/src/lib/prisma.ts @@ -1,3 +1,3 @@ -import { PrismaClient } from "@prisma/client"; +import { PrismaClient } from '@prisma/client'; export const prisma = new PrismaClient();