From eae3d07182857b16999c79d48913f972d96612aa Mon Sep 17 00:00:00 2001 From: RileCraft <48475792+RileCraft@users.noreply.github.com> Date: Fri, 9 Feb 2024 19:24:42 +0530 Subject: [PATCH] V9.0.6 Release --- README.md | 5 +++-- bot.js | 3 +++ package-lock.json | 13 +++++++++++-- package.json | 3 ++- src/structures/commandOptions/channelCooldown.js | 14 ++------------ src/structures/commandOptions/globalCooldown.js | 14 ++------------ src/structures/commandOptions/guildCooldown.js | 14 ++------------ 7 files changed, 25 insertions(+), 41 deletions(-) diff --git a/README.md b/README.md index bbc241d..bf83628 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@


- + @@ -12,10 +12,11 @@ The Discord Bot Template provides a solid foundation for creating feature-rich Discord bots using Discord.js. It includes various managers for handling message commands, buttons, select menus, slash commands, context menus, and modal forms. The template offers customization options, colorful logging, and a simple code structure. ## Changelog -### IMPORTANT UPDATE 9.0.5 +### IMPORTANT UPDATE 9.0.6 - **Fixed Windows Support and SlashCommands & ContextMenus not Registering.** - Fixed subDirectories not working for commands. +- Added dependency of `simple-json-db` for the cooldown system as i rage quit and can't do it with `fs` myself. - Latest Discord.js adaptation. - Following JavaScript Naming Convention. - Removed `node-recursive-directory` dependency. diff --git a/bot.js b/bot.js index 13f1fcc..6e2a3d5 100644 --- a/bot.js +++ b/bot.js @@ -7,6 +7,7 @@ import { MessageCMDManager } from "./src/structures/managers/messageCommands.js" import { ModalManager } from "./src/structures/managers/modalForms.js"; import { SelectMenuManager } from "./src/structures/managers/selectMenus.js"; import { SlashManager } from "./src/structures/managers/slashCommands.js"; +import JSONdb from "simple-json-db"; const __dirname = dirname(import.meta.url); export const rootPath = __dirname; @@ -29,6 +30,8 @@ export const rootPath = __dirname; partials: [Partials.Channel] }); + client.cooldownDB = new JSONdb("./cooldownDB.json"); + client.messageCommands = new Map(); client.messageCommands_Aliases = new Map(); client.events = new Map(); diff --git a/package-lock.json b/package-lock.json index 700dea8..e2f78eb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,16 +1,17 @@ { "name": "discordbot-template", - "version": "9.0.0", + "version": "9.0.5", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "discordbot-template", - "version": "9.0.0", + "version": "9.0.5", "license": "MIT", "dependencies": { "discord.js": "^14.14.1", "ms": "^2.1.3", + "simple-json-db": "^2.0.0", "tasai": "^1.0.0", "undici-types": "^5.26.5" } @@ -230,6 +231,14 @@ "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==" }, + "node_modules/simple-json-db": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/simple-json-db/-/simple-json-db-2.0.0.tgz", + "integrity": "sha512-oTh7gFQzqAe0E8RN3EkisPo0CojkzcKCKibTcJncg0yt47hWTaNwwjX/FsxfXSTDxfMjBFXFVnZe/EskAlJr7w==", + "engines": { + "node": ">=10.0" + } + }, "node_modules/tasai": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/tasai/-/tasai-1.0.0.tgz", diff --git a/package.json b/package.json index e2c5936..d499f30 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "discordbot-template", - "version": "9.0.5", + "version": "9.0.6", "description": "Just your average discord bot handler.", "main": "bot.js", "type": "module", @@ -17,6 +17,7 @@ "dependencies": { "discord.js": "^14.14.1", "ms": "^2.1.3", + "simple-json-db": "^2.0.0", "tasai": "^1.0.0", "undici-types": "^5.26.5" } diff --git a/src/structures/commandOptions/channelCooldown.js b/src/structures/commandOptions/channelCooldown.js index f01c1ef..50c0a5c 100755 --- a/src/structures/commandOptions/channelCooldown.js +++ b/src/structures/commandOptions/channelCooldown.js @@ -1,24 +1,14 @@ import { EmbedBuilder } from "discord.js"; -import { appendFileSync, readFileSync } from "fs"; -import { join } from "path"; -import { rootPath } from "../../../bot.js"; export const channelCooldownFN = async (client, message, command, interactionType) => { if (!command.channelCooldown || isNaN(command.channelCooldown) || !message.guild) return true; const dbData = `channelCoolown.${message.channel.id}.${interactionType}.${command.name}.${message.member.id}`; const currentTime = Date.now(); - let storedTime; - - try { - storedTime = Number(readFileSync(join(rootPath, "CooldownDB.txt"), { encoding: 'utf8', flag: 'r' }).split("\n").filter((stuff) => stuff === dbData)[0].split(".")[4]); - } - catch { - storedTime = 0; - }; + const storedTime = client.cooldownDB?.get(dbData) ?? 0; if (Math.floor(currentTime - storedTime) >= command.channelCooldown || !storedTime) { - appendFileSync(join(rootPath, "CooldownDB.txt"), `${dbData}.${currentTime}`); + client.cooldownDB?.set(dbData, currentTime); return true; } else { diff --git a/src/structures/commandOptions/globalCooldown.js b/src/structures/commandOptions/globalCooldown.js index 6878f8d..b4b91d4 100755 --- a/src/structures/commandOptions/globalCooldown.js +++ b/src/structures/commandOptions/globalCooldown.js @@ -1,24 +1,14 @@ import { EmbedBuilder } from "discord.js"; -import { appendFileSync, readFileSync } from "fs"; -import { join } from "path"; -import { rootPath } from "../../../bot.js"; export const globalCooldownFN = async (client, message, command, interactionType) => { if (!command.guildCooldown || isNaN(command.guildCooldown)) return true; const dbData = `globalCooldown.${interactionType}.${command.name}.${message.member.id}`; const currentTime = Date.now(); - let storedTime; - - try { - storedTime = Number(readFileSync(join(rootPath, "CooldownDB.txt"), { encoding: 'utf8', flag: 'r' }).split("\n").filter((stuff) => stuff === dbData)[0].split(".")[4]); - } - catch { - storedTime = 0; - }; + const storedTime = client.cooldownDB?.get(dbData) ?? 0; if (Math.floor(currentTime - storedTime) >= command.guildCooldown || !storedTime) { - appendFileSync(join(rootPath, "CooldownDB.txt"), `${dbData}.${currentTime}`); + client.cooldownDB?.set(dbData, currentTime); return true; } else { diff --git a/src/structures/commandOptions/guildCooldown.js b/src/structures/commandOptions/guildCooldown.js index 93a3330..ff46b9d 100755 --- a/src/structures/commandOptions/guildCooldown.js +++ b/src/structures/commandOptions/guildCooldown.js @@ -1,24 +1,14 @@ import { EmbedBuilder } from "discord.js"; -import { join } from "path"; -import { rootPath } from "../../../bot.js"; -import { appendFileSync, readFileSync } from "fs"; export const guildCooldownFN = async (client, message, command, interactionType) => { if (!command.guildCooldown || isNaN(command.guildCooldown) || !message.guild) return true; const dbData = `guildCooldown.${message.guild.id}.${interactionType}.${command.name}.${message.member.id}`; const currentTime = Date.now(); - let storedTime; - - try { - storedTime = Number(readFileSync(join(rootPath, "CooldownDB.txt"), { encoding: 'utf8', flag: 'r' }).split("\n").filter((stuff) => stuff === dbData)[0].split(".")[5]); - } - catch { - storedTime = 0; - }; + const storedTime = client.cooldownDB?.get(dbData) ?? 0; if (Math.floor(currentTime - storedTime) >= command.guildCooldown || !storedTime) { - appendFileSync(join(rootPath, "CooldownDB.txt"), `${dbData}.${currentTime}`); + client.cooldownDB?.set(dbData, currentTime); return true; } else {