Skip to content

Commit

Permalink
Merge pull request #86 from RileCraft/Unstable
Browse files Browse the repository at this point in the history
V9.0.6 Release
  • Loading branch information
RileCraft authored Feb 9, 2024
2 parents 8343ab3 + eae3d07 commit ede1c98
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 41 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<p align="center">
<img src="https://media.discordapp.net/attachments/774290264764055582/1093484780525469757/A_banner_for_a_discord_bots_template_made_using_discord.js.png" height="200" width="400"><br>
<img src="https://img.shields.io/badge/version-9.0.5-05122A?style=for-the-badge">
<img src="https://img.shields.io/badge/version-9.0.6-05122A?style=for-the-badge">
<a href="https://discord.gg/VStdRr8nP2"><img src="https://img.shields.io/badge/discord-invite-5865f2?style=for-the-badge&logo=discord&logoColor=white"></a>
<img src="https://img.shields.io/github/issues/RileCraft/DiscordBot-Template.svg?style=for-the-badge">
<img src="https://img.shields.io/github/forks/RileCraft/DiscordBot-Template.svg?style=for-the-badge">
Expand All @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down
13 changes: 11 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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"
}
Expand Down
14 changes: 2 additions & 12 deletions src/structures/commandOptions/channelCooldown.js
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
14 changes: 2 additions & 12 deletions src/structures/commandOptions/globalCooldown.js
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
14 changes: 2 additions & 12 deletions src/structures/commandOptions/guildCooldown.js
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down

0 comments on commit ede1c98

Please sign in to comment.