Skip to content

Commit be43aba

Browse files
committed
fix colors import to avoid extending String.prototype
1 parent 2dbb3e4 commit be43aba

File tree

5 files changed

+47
-34
lines changed

5 files changed

+47
-34
lines changed

src/CommandKit.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
import { CommandHandler, EventHandler, ValidationHandler } from "./handlers";
2-
import { CommandKitData, CommandKitOptions } from "./typings";
3-
import "colors";
1+
import { CommandHandler, EventHandler, ValidationHandler } from './handlers';
2+
import { CommandKitData, CommandKitOptions } from './typings';
3+
import colors from 'colors/safe';
44

55
export class CommandKit {
66
#data: CommandKitData;
77

88
constructor({ ...options }: CommandKitOptions) {
99
if (!options.client) {
10-
throw new Error('"client" is required when instantiating CommandKit.'.red);
10+
throw new Error(colors.red('"client" is required when instantiating CommandKit.'));
1111
}
1212

1313
if (options.validationsPath && !options.commandsPath) {
14-
throw new Error('"commandsPath" is required when "validationsPath" is set.'.red);
14+
throw new Error(colors.red('"commandsPath" is required when "validationsPath" is set.'));
1515
}
1616

1717
this.#data = {

src/handlers/command-handler/CommandHandler.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { toFileURL } from '../../utils/resolve-file-url';
44
import builtInValidations from './validations';
55
import registerCommands from './functions/registerCommands';
66
import handleCommands from './functions/handleCommands';
7-
import 'colors';
7+
import colors from 'colors/safe';
88

99
export class CommandHandler {
1010
_data: CommandHandlerData;
@@ -39,12 +39,12 @@ export class CommandHandler {
3939
if (commandObj.default) commandObj = commandObj.default;
4040

4141
if (!commandObj.data) {
42-
console.log(`⏩ Ignoring: Command ${compactFilePath} does not export "data".`.yellow);
42+
console.log(colors.yellow(`⏩ Ignoring: Command ${compactFilePath} does not export "data".`));
4343
continue;
4444
}
4545

4646
if (!commandObj.run) {
47-
console.log(`⏩ Ignoring: Command ${compactFilePath} does not export "run".`.yellow);
47+
console.log(colors.yellow(`⏩ Ignoring: Command ${compactFilePath} does not export "run".`));
4848
continue;
4949
}
5050

src/handlers/command-handler/functions/registerCommands.ts

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
1-
import { Guild, GuildApplicationCommandManager } from "discord.js";
2-
import { CommandHandler } from "../CommandHandler";
3-
import areSlashCommandsDifferent from "../utils/areSlashCommandsDifferent";
4-
import "colors";
1+
import { Guild, GuildApplicationCommandManager } from 'discord.js';
2+
import { CommandHandler } from '../CommandHandler';
3+
import areSlashCommandsDifferent from '../utils/areSlashCommandsDifferent';
4+
import colors from 'colors/safe';
55

66
export default async function registerCommands(commandHandler: CommandHandler) {
77
const client = commandHandler._data.client;
88
const devGuildIds = commandHandler._data.devGuildIds;
99
const commands = commandHandler._data.commands;
1010

11-
client.once("ready", async () => {
11+
client.once('ready', async () => {
1212
const devGuilds: Guild[] = [];
1313

1414
for (const devGuildId of devGuildIds) {
1515
const guild = client.guilds.cache.get(devGuildId);
1616

1717
if (!guild) {
18-
console.log(`⏩ Ignoring: Guild ${devGuildId} does not exist or client isn't in this guild.`.yellow);
18+
console.log(
19+
colors.yellow(`⏩ Ignoring: Guild ${devGuildId} does not exist or client isn't in this guild.`)
20+
);
1921
continue;
2022
}
2123

@@ -39,10 +41,12 @@ export default async function registerCommands(commandHandler: CommandHandler) {
3941
const targetCommand = appCommands?.cache.find((cmd) => cmd.name === command.data.name);
4042

4143
if (!targetCommand) {
42-
console.log(`⏩ Ignoring: Command "${command.data.name}" is globally marked as deleted.`.yellow);
44+
console.log(
45+
colors.yellow(`⏩ Ignoring: Command "${command.data.name}" is globally marked as deleted.`)
46+
);
4347
} else {
4448
targetCommand.delete().then(() => {
45-
console.log(`🚮 Deleted command "${command.data.name}" globally.`.green);
49+
console.log(colors.green(`🚮 Deleted command "${command.data.name}" globally.`));
4650
});
4751
}
4852

@@ -51,13 +55,16 @@ export default async function registerCommands(commandHandler: CommandHandler) {
5155

5256
if (!targetCommand) {
5357
console.log(
54-
`⏩ Ignoring: Command "${command.data.name}" is marked as deleted for ${guildCommands.guild.name}.`
55-
.yellow
58+
colors.yellow(
59+
`⏩ Ignoring: Command "${command.data.name}" is marked as deleted for ${guildCommands.guild.name}.`
60+
)
5661
);
5762
} else {
5863
targetCommand.delete().then(() => {
5964
console.log(
60-
`🚮 Deleted command "${command.data.name}" in ${guildCommands.guild.name}.`.green
65+
colors.green(
66+
`🚮 Deleted command "${command.data.name}" in ${guildCommands.guild.name}.`
67+
)
6168
);
6269
});
6370
}
@@ -80,10 +87,10 @@ export default async function registerCommands(commandHandler: CommandHandler) {
8087
appGlobalCommand
8188
.edit(commandData)
8289
.then(() => {
83-
console.log(`✅ Edited command "${commandData.name}" globally.`.green);
90+
console.log(colors.green(`✅ Edited command "${commandData.name}" globally.`));
8491
})
8592
.catch((error) => {
86-
console.log(`❌ Failed to edit command "${commandData.name}" globally.`.red);
93+
console.log(colors.red(`❌ Failed to edit command "${commandData.name}" globally.`));
8794
console.error(error);
8895
});
8996

@@ -103,13 +110,16 @@ export default async function registerCommands(commandHandler: CommandHandler) {
103110
.edit(commandData)
104111
.then(() => {
105112
console.log(
106-
`✅ Edited command "${commandData.name}" in ${guildCommands.guild.name}.`.green
113+
colors.green(
114+
`✅ Edited command "${commandData.name}" in ${guildCommands.guild.name}.`
115+
)
107116
);
108117
})
109118
.catch((error) => {
110119
console.log(
111-
`❌ Failed to edit command "${commandData.name}" in ${guildCommands.guild.name}.`
112-
.red
120+
colors.red(
121+
`❌ Failed to edit command "${commandData.name}" in ${guildCommands.guild.name}.`
122+
)
113123
);
114124
console.error(error);
115125
});
@@ -126,8 +136,9 @@ export default async function registerCommands(commandHandler: CommandHandler) {
126136
if (command.options?.devOnly) {
127137
if (!devGuilds.length) {
128138
console.log(
129-
`⏩ Ignoring: Cannot register command "${command.data.name}" as no valid "devGuildIds" were provided.`
130-
.yellow
139+
colors.yellow(
140+
`⏩ Ignoring: Cannot register command "${command.data.name}" as no valid "devGuildIds" were provided.`
141+
)
131142
);
132143
continue;
133144
}
@@ -139,10 +150,12 @@ export default async function registerCommands(commandHandler: CommandHandler) {
139150
guild?.commands
140151
.create(command.data)
141152
.then(() => {
142-
console.log(`✅ Registered command "${command.data.name}" in ${guild.name}.`.green);
153+
console.log(colors.green(`✅ Registered command "${command.data.name}" in ${guild.name}.`));
143154
})
144155
.catch((error) => {
145-
console.log(`❌ Failed to register command "${command.data.name}" in ${guild.name}.`.red);
156+
console.log(
157+
colors.red(`❌ Failed to register command "${command.data.name}" in ${guild.name}.`)
158+
);
146159
console.error(error);
147160
});
148161
}
@@ -155,10 +168,10 @@ export default async function registerCommands(commandHandler: CommandHandler) {
155168
appCommands
156169
?.create(command.data)
157170
.then(() => {
158-
console.log(`✅ Registered command "${command.data.name}" globally.`.green);
171+
console.log(colors.green(`✅ Registered command "${command.data.name}" globally.`));
159172
})
160173
.catch((error) => {
161-
console.log(`❌ Failed to register command "${command.data.name}" globally.`.red);
174+
console.log(colors.red(`❌ Failed to register command "${command.data.name}" globally.`));
162175
console.error(error);
163176
});
164177
}

src/handlers/event-handler/EventHandler.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { getFilePaths, getFolderPaths } from '../../utils/get-paths';
22
import { toFileURL } from '../../utils/resolve-file-url';
33
import { EventHandlerOptions, EventHandlerData } from './typings';
4-
import 'colors';
4+
import colors from 'colors/safe';
55

66
export class EventHandler {
77
#data: EventHandlerData;
@@ -42,7 +42,7 @@ export class EventHandler {
4242
const compactFilePath = eventFilePath.split(process.cwd())[1] || eventFilePath;
4343

4444
if (typeof eventFunction !== 'function') {
45-
console.log(`⏩ Ignoring: Event ${compactFilePath} does not export a function.`.yellow);
45+
console.log(colors.yellow(`⏩ Ignoring: Event ${compactFilePath} does not export a function.`));
4646
continue;
4747
}
4848

src/handlers/validation-handler/ValidationHandler.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { ValidationHandlerData, ValidationHandlerOptions } from './typings';
22
import { getFilePaths } from '../../utils/get-paths';
33
import { toFileURL } from '../../utils/resolve-file-url';
4-
import 'colors';
4+
import colors from 'colors/safe';
55

66
export class ValidationHandler {
77
#data: ValidationHandlerData;
@@ -29,7 +29,7 @@ export class ValidationHandler {
2929
const compactFilePath = validationFilePath.split(process.cwd())[1] || validationFilePath;
3030

3131
if (typeof validationFunction !== 'function') {
32-
console.log(`⏩ Ignoring: Validation ${compactFilePath} does not export a function.`.yellow);
32+
console.log(colors.yellow(`⏩ Ignoring: Validation ${compactFilePath} does not export a function.`));
3333
continue;
3434
}
3535

0 commit comments

Comments
 (0)