diff --git a/src/commands/prefix/Developers/eval.js b/src/commands/prefix/Developers/eval.js new file mode 100644 index 00000000..89b561eb --- /dev/null +++ b/src/commands/prefix/Developers/eval.js @@ -0,0 +1,23 @@ +const { Message } = require("discord.js"); +const ExtendedClient = require("../../../class/ExtendedClient"); + +module.exports = { + structure: { + name: "eval", + description: "Execute some codes!", + aliases: ["e"], + cooldown: 0, + }, + /** + * @param {ExtendedClient} client + * @param {Message} message + * @param {[String]} args + */ + run: async (client, message, args) => { + const evaled = eval(args.join(" ")); + + await message.reply({ + content: String(evaled), + }); + }, +}; diff --git a/src/commands/slash/Developers/eval.js b/src/commands/slash/Developers/eval.js index b61b7899..b4c37b20 100644 --- a/src/commands/slash/Developers/eval.js +++ b/src/commands/slash/Developers/eval.js @@ -35,6 +35,6 @@ module.exports = { .setTitle("Code executed") .setDescription(`The return output was:\n${executedEvalValue}`); - await interaction.reply({ embeds: [embed] }); + await interaction.editReply({ embeds: [embed] }); }, }; diff --git a/src/commands/slash/Nsfw/nsfw.js b/src/commands/slash/Nsfw/nsfw.js new file mode 100644 index 00000000..a7b283a2 --- /dev/null +++ b/src/commands/slash/Nsfw/nsfw.js @@ -0,0 +1,25 @@ +const { + ChatInputCommandInteraction, + SlashCommandBuilder, + EmbedBuilder, +} = require("discord.js"); +const ExtendedClient = require("../../../class/ExtendedClient"); +const config = require("../../../config"); +const GuildSchema = require("../../../schemas/GuildSchema"); + +module.exports = { + structure: new SlashCommandBuilder() + .setName("nsfw") + .setDescription("Nsfw command."), + /** + * @param {ExtendedClient} client + * @param {ChatInputCommandInteraction} interaction + * @param {[]} args + */ + options: { + nsfw: true, + }, + run: async (client, interaction, args) => { + await interaction.reply({ content: "NSFW Command!" }); + }, +}; diff --git a/src/events/Guild/interactionCreate.js b/src/events/Guild/interactionCreate.js index c2371141..14e579f6 100644 --- a/src/events/Guild/interactionCreate.js +++ b/src/events/Guild/interactionCreate.js @@ -44,6 +44,16 @@ module.exports = { }); } } + + if (command.options?.nsfw) { + if (!interaction.channel.nsfw) { + return interaction.reply({ + content: "NSFW Command. Execute this command on a NSFW Channel.", + ephemeral: true, + }); + } + } + if (command.options?.cooldown) { const cooldownFunction = () => { let data = cooldown.get(interaction.user.id); diff --git a/src/events/Guild/messageCreate.js b/src/events/Guild/messageCreate.js index fb6f047d..47335b5b 100644 --- a/src/events/Guild/messageCreate.js +++ b/src/events/Guild/messageCreate.js @@ -1,99 +1,119 @@ -const { ChannelType, Message } = require('discord.js'); -const config = require('../../config'); -const { log } = require('../../functions'); -const GuildSchema = require('../../schemas/GuildSchema'); -const ExtendedClient = require('../../class/ExtendedClient'); +const { ChannelType, Message } = require("discord.js"); +const config = require("../../config"); +const { log } = require("../../functions"); +const GuildSchema = require("../../schemas/GuildSchema"); +const ExtendedClient = require("../../class/ExtendedClient"); const cooldown = new Map(); module.exports = { - event: 'messageCreate', - /** - * - * @param {ExtendedClient} client - * @param {Message} message - * @returns - */ - run: async (client, message) => { - if (message.author.bot || message.channel.type === ChannelType.DM) return; - - if (!config.handler.commands.prefix) return; - - let prefix = config.handler.prefix; - - if (config.handler?.mongodb?.toggle) { - try { - const guildData = await GuildSchema.findOne({ guild: message.guildId }); - - if (guildData && guildData?.prefix) prefix = guildData.prefix; - } catch { - prefix = config.handler.prefix; - }; - }; - - if (!message.content.startsWith(prefix)) return; - - const args = message.content.slice(prefix.length).trim().split(/ +/g); - const commandInput = args.shift().toLowerCase(); - - if (!commandInput.length) return; - - let command = client.collection.prefixcommands.get(commandInput) || client.collection.prefixcommands.get(client.collection.aliases.get(commandInput)); - - if (command) { - try { - if (command.structure?.permissions && !message.member.permissions.has(command.structure?.permissions)) { - await message.reply({ - content: 'You do not have the permission to use this command.' - }); - - return; - }; + event: "messageCreate", + /** + * + * @param {ExtendedClient} client + * @param {Message} message + * @returns + */ + run: async (client, message) => { + if (message.author.bot || message.channel.type === ChannelType.DM) return; + + if (!config.handler.commands.prefix) return; + + let prefix = config.handler.prefix; + + if (config.handler?.mongodb?.toggle) { + try { + const guildData = await GuildSchema.findOne({ guild: message.guildId }); + + if (guildData && guildData?.prefix) prefix = guildData.prefix; + } catch { + prefix = config.handler.prefix; + } + } + + if (!message.content.startsWith(prefix)) return; + + const args = message.content.slice(prefix.length).trim().split(/ +/g); + const commandInput = args.shift().toLowerCase(); + + if (!commandInput.length) return; + + let command = + client.collection.prefixcommands.get(commandInput) || + client.collection.prefixcommands.get( + client.collection.aliases.get(commandInput) + ); + + if (command) { + try { + if ( + command.structure?.permissions && + !message.member.permissions.has(command.structure?.permissions) + ) { + await message.reply({ + content: "You do not have the permission to use this command.", + }); + + return; + } - if (command.structure?.cooldown) { - const cooldownFunction = () => { - let data = cooldown.get(message.author.id); + if (command.structure?.developers) { + if (!config.users.developers.includes(message.author.id)) { + setTimeout(async () => { + await message.reply({ + content: "You are not authorized to use this command.", + }); + }, 5 * 1000); + } - data.push(commandInput); + return; + } - cooldown.set(message.author.id, data); + if (command.structure?.cooldown) { + const cooldownFunction = () => { + let data = cooldown.get(message.author.id); - setTimeout(() => { - let data = cooldown.get(message.author.id); + data.push(commandInput); - data = data.filter((v) => v !== commandInput); + cooldown.set(message.author.id, data); - if (data.length <= 0) { - cooldown.delete(message.author.id); - } else { - cooldown.set(message.author.id, data); - }; - }, command.structure?.cooldown); - }; + setTimeout(() => { + let data = cooldown.get(message.author.id); - if (cooldown.has(message.author.id)) { - let data = cooldown.get(message.author.id); + data = data.filter((v) => v !== commandInput); - if (data.some((v) => v === commandInput)) { - await message.reply({ - content: 'Slow down buddy! You\'re too fast to use this command.' - }); + if (data.length <= 0) { + cooldown.delete(message.author.id); + } else { + cooldown.set(message.author.id, data); + } + }, command.structure?.cooldown); + }; - return; - } else { - cooldownFunction(); - }; - } else { - cooldown.set(message.author.id, [commandInput]); + if (cooldown.has(message.author.id)) { + let data = cooldown.get(message.author.id); - cooldownFunction(); - }; - }; + if (data.some((v) => v === commandInput)) { + await message.reply({ + content: + "Slow down buddy! You're too fast to use this command.", + }); - command.run(client, message, args); - } catch (error) { - log(error, 'err'); + return; + } else { + cooldownFunction(); } + } else { + cooldown.set(message.author.id, [commandInput]); + + cooldownFunction(); + } } - }, + + command.run(client, message, args); + } catch (error) { + log(error, "err"); + } + } + }, }; diff --git a/src/functions/index.js b/src/functions/index.js index df152992..6bbfc6ed 100644 --- a/src/functions/index.js +++ b/src/functions/index.js @@ -1,55 +1,35 @@ -const chalk = require('chalk'); +const chalk = require("chalk"); /** - * - * @param {string} string - * @param {'info' | 'err' | 'warn' | 'done' | undefined} style + * Logs a message with optional styling. + * + * @param {string} string - The message to log. + * @param {'info' | 'err' | 'warn' | 'done' | undefined} style - The style of the log. */ const log = (string, style) => { - switch (style) { - case 'info': { - console.log(chalk.blue('[INFO] ' + string)); - - break; - }; - - case 'err': { - console.error(chalk.red('[ERROR] ' + string)); - - break; - }; - - case 'warn': { - console.warn(chalk.yellow('[WARNING] ' + string)); - - break; - }; - - case 'done': { - console.log(chalk.green('[SUCCESS] ' + string)); - - break; - }; - - default: { - console.log(string); - - break; - }; - }; + const styles = { + info: { prefix: chalk.blue("[INFO]"), logFunction: console.log }, + err: { prefix: chalk.red("[ERROR]"), logFunction: console.error }, + warn: { prefix: chalk.yellow("[WARNING]"), logFunction: console.warn }, + done: { prefix: chalk.green("[SUCCESS]"), logFunction: console.log }, + }; + + const selectedStyle = styles[style] || { logFunction: console.log }; + selectedStyle.logFunction(`${selectedStyle.prefix || ""} ${string}`); }; /** - * - * @param {number} time - * @param {import('discord.js').TimestampStylesString} style - * @returns {``} + * Formats a timestamp. + * + * @param {number} time - The timestamp in milliseconds. + * @param {import('discord.js').TimestampStylesString} style - The timestamp style. + * @returns {string} - The formatted timestamp. */ const time = (time, style) => { - return ``; + return ``; }; module.exports = { - log, - time -}; \ No newline at end of file + log, + time, +};