Skip to content

Commit

Permalink
V1.0.7 Release
Browse files Browse the repository at this point in the history
  • Loading branch information
RileCraft committed Feb 9, 2024
1 parent 508ffe8 commit 62cc14b
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 44 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-1.0.6-05122A?style=for-the-badge">
<img src="https://img.shields.io/badge/version-1.0.7-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-ts.svg?style=for-the-badge">
<img src="https://img.shields.io/github/forks/RileCraft/DiscordBot-Template-ts.svg?style=for-the-badge">
Expand All @@ -12,9 +12,10 @@
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 1.0.6
### IMPORTANT UPDATE 1.0.7

- **Fixed Windows Support and SlashCommands & ContextMenus not Registering.**
- Added dependency of `simple-json-db` for the cooldown system as i rage quit and can't do it with `fs` myself.
- Fixed subDirectories not working for commands.
- Latest Discord.js adaptation.
- Following JavaScript Naming Convention.
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-ts",
"version": "1.0.6",
"version": "1.0.7",
"description": "TypeScript version of DiscordBot-Template",
"main": "./src/bot.ts",
"type": "module",
Expand All @@ -21,6 +21,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
3 changes: 3 additions & 0 deletions src/bot.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Client, DiscordClient, GatewayIntentBits, Partials } from "discord.js";
import { BOT_TOKEN } from "./config.js";
import { dirname } from "path";
import JSONdb from 'simple-json-db';
import { ButtonCommand, ClientEvent, ContextMenu, MessageCommand, ModalForm, SelectMenu, SlashCommand } from "./types.js";
import { ButtonManager } from "./structures/managers/buttonCommands.js";
import { EventManager } from "./structures/managers/events.js";
Expand Down Expand Up @@ -30,6 +31,8 @@ export const rootPath = __dirname;
partials: [Partials.Channel]
});

client.cooldownDB = new JSONdb("./cooldownDB.json");

client.messageCommands = new Map<string, MessageCommand>();
client.messageCommands_Aliases = new Map<string, string>();
client.events = new Map<string, ClientEvent>();
Expand Down
15 changes: 2 additions & 13 deletions src/structures/commandOptions/channelCooldown.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,15 @@
import { EmbedBuilder, Interaction, Message, DiscordClient } from "discord.js";
import { AnyCommand, InteractionTypeOptions } from "../../types.js";
import { appendFile, readFileSync } from "fs";
import { join } from "path";
import { rootPath } from "../../bot.js";

export const channelCooldownFN = async(client: DiscordClient, message: Message | Interaction<"cached">, command: AnyCommand, interactionType: InteractionTypeOptions): Promise<boolean> => {
if (!command.channelCooldown || isNaN(command.channelCooldown) || !message.guild) return true;

const dbData = `channelCoolown.${message.channel?.id}.${interactionType}.${command.name}.${message.member?.id}`;
const currentTime: number = Date.now();
let storedTime: number;

try {
storedTime = Number(readFileSync(join(rootPath, "cooldownDB.txt"), { encoding: 'utf8', flag: 'r' }).split("\n").filter((stuff: string) => stuff === dbData)[0].split(".")[4]);
} catch {
storedTime = 0;
};
const storedTime: number = client.cooldownDB?.get(dbData) ?? 0;

if (Math.floor(currentTime - storedTime) >= command.channelCooldown || !storedTime) {
appendFile(join(rootPath, "cooldownDB.txt"), `${dbData}.${currentTime}`, (error) => {
if (error) console.error("cooldownDB.txt did not exist, creating . . .")
});
client.cooldownDB?.set(dbData, currentTime);
return true;
} else {
if (command.returnErrors === false || command.returnChannelCooldownError === false) return false;
Expand Down
15 changes: 2 additions & 13 deletions src/structures/commandOptions/globalCooldown.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,15 @@
import { EmbedBuilder, Interaction, Message, DiscordClient } from "discord.js";
import { AnyCommand, InteractionTypeOptions } from "../../types.js";
import { appendFile, readFileSync } from "fs";
import { join } from "path";
import { rootPath } from "../../bot.js";

export const globalCooldownFN = async(client: DiscordClient, message: Message | Interaction<"cached">, command: AnyCommand, interactionType: InteractionTypeOptions): Promise<boolean> => {
if (!command.globalCooldown || isNaN(command.globalCooldown)) return true;

const dbData = `globalCooldown.${interactionType}.${command.name}.${message.member?.id}`
const currentTime: number = Date.now();
let storedTime: number;

try {
storedTime = Number(readFileSync(join(rootPath, "cooldownDB.txt"), { encoding: 'utf8', flag: 'r' }).split("\n").filter((stuff: string) => stuff === dbData)[0].split(".")[4]);
} catch {
storedTime = 0;
};
const storedTime: number = client.cooldownDB?.get(dbData) ?? 0;

if (Math.floor(currentTime - storedTime) >= command.globalCooldown || !storedTime) {
appendFile(join(rootPath, "cooldownDB.txt"), `${dbData}.${currentTime}`, (error) => {
if (error) console.error("cooldownDB.txt did not exist, creating . . .")
});
client.cooldownDB?.set(dbData, currentTime);
return true;
} else {
if (command.returnErrors === false || command.returnGlobalCooldownError === false) return false;
Expand Down
15 changes: 2 additions & 13 deletions src/structures/commandOptions/guildCooldown.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,15 @@
import { EmbedBuilder, Interaction, Message, DiscordClient } from "discord.js";
import { AnyCommand, InteractionTypeOptions } from "../../types.js";
import { join } from "path";
import { rootPath } from "../../bot.js";
import { appendFile, readFileSync } from "fs";

export const guildCooldownFN = async(client: DiscordClient, message: Message | Interaction<"cached">, command: AnyCommand, interactionType: InteractionTypeOptions): Promise<boolean> => {
if (!command.guildCooldown || isNaN(command.guildCooldown) || !message.guild) return true;

const dbData = `guildCooldown.${message.guild?.id}.${interactionType}.${command.name}.${message.member?.id}`;
const currentTime: number = Date.now();
let storedTime: number;

try {
storedTime = Number(readFileSync(join(rootPath, "cooldownDB.txt"), { encoding: 'utf8', flag: 'r' }).split("\n").filter((stuff: string) => stuff === dbData)[0].split(".")[5]);
} catch {
storedTime = 0;
};
const storedTime: number = client.cooldownDB?.get(dbData) ?? 0;

if (Math.floor(currentTime - storedTime) >= command.guildCooldown || !storedTime) {
appendFile(join(rootPath, "cooldownDB.txt"), `${dbData}.${currentTime}`, (error) => {
if (error) console.error("cooldownDB.txt did not exist, creating . . .")
});
client.cooldownDB?.set(dbData, currentTime);
return true;
} else {
if (command.returnErrors == false || command.returnGuildCooldownError === false) return false;
Expand Down
2 changes: 2 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { AnySelectMenuInteraction, ApplicationCommandOptionType, ApplicationCommandType, AutocompleteInteraction, ButtonInteraction, ChatInputCommandInteraction, DiscordClient, Message, MessageContextMenuCommandInteraction, ModalSubmitInteraction, UserContextMenuCommandInteraction } from "discord.js";
import JSONdb from "simple-json-db";

// Main Types
declare module "discord.js" {
export interface DiscordClient extends Client<true> {
cooldownDB?: JSONdb
messageCommands?: Map<string, MessageCommand>,
messageCommands_Aliases?: Map<string, string>,
events?: Map<string, ClientEvent>,
Expand Down

0 comments on commit 62cc14b

Please sign in to comment.