Compare commits

..

1 commit

Author SHA1 Message Date
Slincnik
031106de33
Merge dc7bef73ee into 5a30a64230 2024-12-07 14:59:36 +03:00
5 changed files with 41 additions and 42 deletions

View file

@ -1,9 +1,8 @@
import logger from "../../../helpers/logger.js";
import differentCommands from "../utils/differentcommands.js"; import differentCommands from "../utils/differentcommands.js";
export default async function registerCommands(props) { export default async function registerCommands(props) {
const globalCommands = props.commands.filter(cmd => !cmd.options?.devOnly); const globalCommands = props.commands.filter(cmd => !cmd.options?.devOnly);
props.client.once("ready", () => registerGlobalCommands(props.client, globalCommands)); await registerGlobalCommands(props.client, globalCommands);
} }
const registerGlobalCommands = async (client, commands) => { const registerGlobalCommands = async (client, commands) => {
@ -15,14 +14,12 @@ const registerGlobalCommands = async (client, commands) => {
const targetCommand = appCommandsManager.cache.find(cmd => cmd.name === data.name); const targetCommand = appCommandsManager.cache.find(cmd => cmd.name === data.name);
if (targetCommand && differentCommands(targetCommand, data)) { if (targetCommand && differentCommands(targetCommand, data)) {
await targetCommand.edit(data).catch(() => logger.error(`Failed to update command: ${data.name} globally`)); await targetCommand.edit(data).catch(() => console.log(`Failed to update command: ${data.name} globally`));
logger.log(`Edited command globally: ${data.name}`); console.log(`Edited command globally: ${data.name}`);
} else if (!targetCommand) { } else if (!targetCommand) {
await appCommandsManager.create(data).catch(() => logger.error(`Failed to register command: ${data.name}`)); await appCommandsManager.create(data).catch(() => console.log(`Failed to register command: ${data.name}`));
} }
}), }),
); );
logger.log("Registered global commands");
}; };

View file

@ -1,4 +1,3 @@
import logger from "../../helpers/logger.js";
import { client } from "../../index.js"; import { client } from "../../index.js";
import { getFilePaths } from "../../utils/get-path.js"; import { getFilePaths } from "../../utils/get-path.js";
import { toFileURL } from "../../utils/resolve-file.js"; import { toFileURL } from "../../utils/resolve-file.js";
@ -22,12 +21,12 @@ const buildCommands = async () => {
const { data, run } = await import(toFileURL(cmdFilePath)); const { data, run } = await import(toFileURL(cmdFilePath));
if (!data || !data.name) { if (!data || !data.name) {
logger.warn(`Command ${cmdFilePath} does not have a data object or name`); console.warn(`Command ${cmdFilePath} does not have a data object or name`);
continue; continue;
} }
if (typeof run !== "function") { if (typeof run !== "function") {
logger.warn(`Command ${cmdFilePath} does not have a run function or it is not a function`); console.warn(`Command ${cmdFilePath} does not have a run function or it is not a function`);
continue; continue;
} }

View file

@ -1,4 +1,3 @@
import logger from "../../helpers/logger.js";
import { client } from "../../index.js"; import { client } from "../../index.js";
import { getFilePaths } from "../../utils/get-path.js"; import { getFilePaths } from "../../utils/get-path.js";
import { toFileURL } from "../../utils/resolve-file.js"; import { toFileURL } from "../../utils/resolve-file.js";
@ -7,6 +6,7 @@ export const events = [];
export const init = async () => { export const init = async () => {
await buildEvents(); await buildEvents();
registerEvents(); registerEvents();
}; };
@ -18,23 +18,23 @@ const buildEvents = async () => {
const { data, run } = await import(toFileURL(eventFilePath)); const { data, run } = await import(toFileURL(eventFilePath));
if (!data || !data.name) { if (!data || !data.name) {
logger.warn(`Event ${eventFilePath} does not have a data object or name`); console.warn(`Event ${eventFilePath} does not have a data object or name`);
continue; continue;
} }
if (typeof run !== "function") { if (typeof run !== "function") {
logger.warn(`Event ${eventFilePath} does not have a run function or it is not a function`); console.warn(`Event ${eventFilePath} does not have a run function or it is not a function`);
continue; continue;
} }
events.push({ data, run }); events.push({ data, run });
} }
} catch (error) { } catch (error) {
logger.error("Error build events: ", error); console.error("Error build events: ", error);
} }
}; };
const registerEvents = async () => { const registerEvents = () => {
for (const { data, run } of events) { for (const { data, run } of events) {
if (data.once) client.once(data.name, run); if (data.once) client.once(data.name, run);
else client.on(data.name, run); else client.on(data.name, run);

View file

@ -1,47 +1,52 @@
import chalk from "chalk"; import { bgBlue, black, green } from "chalk";
function format(tDate) { function dateTimePad(value, digits) {
return new Intl.DateTimeFormat("ru-RU", { let number = value;
year: "numeric", while (number.toString().length < digits) number = "0" + number;
month: "2-digit",
day: "2-digit", return number;
hour: "2-digit",
minute: "2-digit",
second: "2-digit",
}).format(tDate);
} }
const logLevels = { function format(tDate) {
LOG: chalk.bgBlue("LOG"), return (
WARN: chalk.black.bgYellow("WARN"), dateTimePad(tDate.getDate(), 2) +
ERROR: chalk.black.bgRed("ERROR"), "-" +
DEBUG: chalk.green("DEBUG"), dateTimePad(tDate.getMonth() + 1, 2) +
CMD: chalk.black.bgWhite("CMD"), "-" +
READY: chalk.black.bgGreen("READY"), dateTimePad(tDate.getFullYear(), 2) +
}; " " +
dateTimePad(tDate.getHours(), 2) +
":" +
dateTimePad(tDate.getMinutes(), 2) +
":" +
dateTimePad(tDate.getSeconds(), 2) +
"." +
dateTimePad(tDate.getMilliseconds(), 3)
);
}
export default { export default {
log(content) { log(content) {
return console.log(`[${format(Date.now())}]: ${logLevels.LOG} ${content}`); return console.log(`[${format(new Date(Date.now()))}]: ${bgBlue("LOG")} ${content}`);
}, },
warn(content) { warn(content) {
return console.log(`[${format(Date.now())}]: ${logLevels.WARN} ${content}`); return console.log(`[${format(new Date(Date.now()))}]: ${black.bgYellow("WARN")} ${content}`);
}, },
error(content) { error(content) {
return console.log(`[${format(Date.now())}]: ${logLevels.ERROR} ${content}`); return console.log(`[${format(new Date(Date.now()))}]: ${black.bgRed("ERROR")} ${content}`);
}, },
debug(content) { debug(content) {
return console.log(`[${format(Date.now())}]: ${logLevels.DEBUG} ${content}`); return console.log(`[${format(new Date(Date.now()))}]: ${green("DEBUG")} ${content}`);
}, },
cmd(content) { cmd(content) {
return console.log(`[${format(Date.now())}]: ${logLevels.CMD} ${content}`); return console.log(`[${format(new Date(Date.now()))}]: ${black.bgWhite("CMD")} ${content}`);
}, },
ready(content) { ready(content) {
return console.log(`[${format(Date.now())}]: ${logLevels.READY} ${content}`); return console.log(`[${format(new Date(Date.now()))}]: ${black.bgGreen("READY")} ${content}`);
}, },
}; };

View file

@ -1,5 +1,3 @@
import logger from "../helpers/logger.js";
export const data = { export const data = {
name: "ready", name: "ready",
once: true, once: true,
@ -10,5 +8,5 @@ export const data = {
* @param {import("../base/Client.JaBaClient")} client * @param {import("../base/Client.JaBaClient")} client
*/ */
export async function run(client) { export async function run(client) {
logger.log(client.user.tag + " is online!"); console.log(client.user.tag + " is online!");
} }