mirror of
https://github.com/JonnyBro/JaBa.git
synced 2024-12-29 14:53:03 +05:00
Compare commits
4 commits
031106de33
...
60ecbd38f1
Author | SHA1 | Date | |
---|---|---|---|
|
60ecbd38f1 | ||
|
be5722bb01 | ||
|
024822d1f3 | ||
|
cfee30528d |
5 changed files with 42 additions and 41 deletions
|
@ -1,8 +1,9 @@
|
|||
import logger from "../../../helpers/logger.js";
|
||||
import differentCommands from "../utils/differentcommands.js";
|
||||
|
||||
export default async function registerCommands(props) {
|
||||
const globalCommands = props.commands.filter(cmd => !cmd.options?.devOnly);
|
||||
await registerGlobalCommands(props.client, globalCommands);
|
||||
props.client.once("ready", () => registerGlobalCommands(props.client, globalCommands));
|
||||
}
|
||||
|
||||
const registerGlobalCommands = async (client, commands) => {
|
||||
|
@ -14,12 +15,14 @@ const registerGlobalCommands = async (client, commands) => {
|
|||
const targetCommand = appCommandsManager.cache.find(cmd => cmd.name === data.name);
|
||||
|
||||
if (targetCommand && differentCommands(targetCommand, data)) {
|
||||
await targetCommand.edit(data).catch(() => console.log(`Failed to update command: ${data.name} globally`));
|
||||
await targetCommand.edit(data).catch(() => logger.error(`Failed to update command: ${data.name} globally`));
|
||||
|
||||
console.log(`Edited command globally: ${data.name}`);
|
||||
logger.log(`Edited command globally: ${data.name}`);
|
||||
} else if (!targetCommand) {
|
||||
await appCommandsManager.create(data).catch(() => console.log(`Failed to register command: ${data.name}`));
|
||||
await appCommandsManager.create(data).catch(() => logger.error(`Failed to register command: ${data.name}`));
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
||||
logger.log("Registered global commands");
|
||||
};
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import logger from "../../helpers/logger.js";
|
||||
import { client } from "../../index.js";
|
||||
import { getFilePaths } from "../../utils/get-path.js";
|
||||
import { toFileURL } from "../../utils/resolve-file.js";
|
||||
|
@ -21,12 +22,12 @@ const buildCommands = async () => {
|
|||
const { data, run } = await import(toFileURL(cmdFilePath));
|
||||
|
||||
if (!data || !data.name) {
|
||||
console.warn(`Command ${cmdFilePath} does not have a data object or name`);
|
||||
logger.warn(`Command ${cmdFilePath} does not have a data object or name`);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (typeof run !== "function") {
|
||||
console.warn(`Command ${cmdFilePath} does not have a run function or it is not a function`);
|
||||
logger.warn(`Command ${cmdFilePath} does not have a run function or it is not a function`);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import logger from "../../helpers/logger.js";
|
||||
import { client } from "../../index.js";
|
||||
import { getFilePaths } from "../../utils/get-path.js";
|
||||
import { toFileURL } from "../../utils/resolve-file.js";
|
||||
|
@ -6,7 +7,6 @@ export const events = [];
|
|||
|
||||
export const init = async () => {
|
||||
await buildEvents();
|
||||
|
||||
registerEvents();
|
||||
};
|
||||
|
||||
|
@ -18,23 +18,23 @@ const buildEvents = async () => {
|
|||
const { data, run } = await import(toFileURL(eventFilePath));
|
||||
|
||||
if (!data || !data.name) {
|
||||
console.warn(`Event ${eventFilePath} does not have a data object or name`);
|
||||
logger.warn(`Event ${eventFilePath} does not have a data object or name`);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (typeof run !== "function") {
|
||||
console.warn(`Event ${eventFilePath} does not have a run function or it is not a function`);
|
||||
logger.warn(`Event ${eventFilePath} does not have a run function or it is not a function`);
|
||||
continue;
|
||||
}
|
||||
|
||||
events.push({ data, run });
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error build events: ", error);
|
||||
logger.error("Error build events: ", error);
|
||||
}
|
||||
};
|
||||
|
||||
const registerEvents = () => {
|
||||
const registerEvents = async () => {
|
||||
for (const { data, run } of events) {
|
||||
if (data.once) client.once(data.name, run);
|
||||
else client.on(data.name, run);
|
||||
|
|
|
@ -1,52 +1,47 @@
|
|||
import { bgBlue, black, green } from "chalk";
|
||||
|
||||
function dateTimePad(value, digits) {
|
||||
let number = value;
|
||||
while (number.toString().length < digits) number = "0" + number;
|
||||
|
||||
return number;
|
||||
}
|
||||
import chalk from "chalk";
|
||||
|
||||
function format(tDate) {
|
||||
return (
|
||||
dateTimePad(tDate.getDate(), 2) +
|
||||
"-" +
|
||||
dateTimePad(tDate.getMonth() + 1, 2) +
|
||||
"-" +
|
||||
dateTimePad(tDate.getFullYear(), 2) +
|
||||
" " +
|
||||
dateTimePad(tDate.getHours(), 2) +
|
||||
":" +
|
||||
dateTimePad(tDate.getMinutes(), 2) +
|
||||
":" +
|
||||
dateTimePad(tDate.getSeconds(), 2) +
|
||||
"." +
|
||||
dateTimePad(tDate.getMilliseconds(), 3)
|
||||
);
|
||||
return new Intl.DateTimeFormat("ru-RU", {
|
||||
year: "numeric",
|
||||
month: "2-digit",
|
||||
day: "2-digit",
|
||||
hour: "2-digit",
|
||||
minute: "2-digit",
|
||||
second: "2-digit",
|
||||
}).format(tDate);
|
||||
}
|
||||
|
||||
const logLevels = {
|
||||
LOG: chalk.bgBlue("LOG"),
|
||||
WARN: chalk.black.bgYellow("WARN"),
|
||||
ERROR: chalk.black.bgRed("ERROR"),
|
||||
DEBUG: chalk.green("DEBUG"),
|
||||
CMD: chalk.black.bgWhite("CMD"),
|
||||
READY: chalk.black.bgGreen("READY"),
|
||||
};
|
||||
|
||||
export default {
|
||||
log(content) {
|
||||
return console.log(`[${format(new Date(Date.now()))}]: ${bgBlue("LOG")} ${content}`);
|
||||
return console.log(`[${format(Date.now())}]: ${logLevels.LOG} ${content}`);
|
||||
},
|
||||
|
||||
warn(content) {
|
||||
return console.log(`[${format(new Date(Date.now()))}]: ${black.bgYellow("WARN")} ${content}`);
|
||||
return console.log(`[${format(Date.now())}]: ${logLevels.WARN} ${content}`);
|
||||
},
|
||||
|
||||
error(content) {
|
||||
return console.log(`[${format(new Date(Date.now()))}]: ${black.bgRed("ERROR")} ${content}`);
|
||||
return console.log(`[${format(Date.now())}]: ${logLevels.ERROR} ${content}`);
|
||||
},
|
||||
|
||||
debug(content) {
|
||||
return console.log(`[${format(new Date(Date.now()))}]: ${green("DEBUG")} ${content}`);
|
||||
return console.log(`[${format(Date.now())}]: ${logLevels.DEBUG} ${content}`);
|
||||
},
|
||||
|
||||
cmd(content) {
|
||||
return console.log(`[${format(new Date(Date.now()))}]: ${black.bgWhite("CMD")} ${content}`);
|
||||
return console.log(`[${format(Date.now())}]: ${logLevels.CMD} ${content}`);
|
||||
},
|
||||
|
||||
ready(content) {
|
||||
return console.log(`[${format(new Date(Date.now()))}]: ${black.bgGreen("READY")} ${content}`);
|
||||
return console.log(`[${format(Date.now())}]: ${logLevels.READY} ${content}`);
|
||||
},
|
||||
};
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import logger from "../helpers/logger.js";
|
||||
|
||||
export const data = {
|
||||
name: "ready",
|
||||
once: true,
|
||||
|
@ -8,5 +10,5 @@ export const data = {
|
|||
* @param {import("../base/Client.JaBaClient")} client
|
||||
*/
|
||||
export async function run(client) {
|
||||
console.log(client.user.tag + " is online!");
|
||||
logger.log(client.user.tag + " is online!");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue