Base structure

This commit is contained in:
2022-11-23 13:23:25 +01:00
parent c7a66fddca
commit 261627570d
11 changed files with 870 additions and 0 deletions

View File

@ -0,0 +1,62 @@
/* eslint-disable prefer-rest-params */
/**
* This module swaps the default console outputs to own functions and adds a timestamp to each message
*/
import path from "path";
import fs from "fs-extra";
export default function() {
fs.ensureDirSync(path.join(__dirname, "../data/log/"));
const callDate = new Date();
const logFileName = `${callDate.getUTCFullYear()}-${`0${callDate.getUTCMonth() + 1}`.slice(-2)}-${`0${callDate.getUTCDate()}`.slice(-2)}-${`0${callDate.getUTCHours()}`.slice(-2)}-${`0${callDate.getUTCMinutes()}`.slice(-2)}-${`0${callDate.getUTCSeconds()}`.slice(-2)}-${`00${callDate.getUTCMilliseconds()}`.slice(-3)}.log`;
const logFile = fs.createWriteStream(path.join(__dirname, `../data/log/${logFileName}`));
const out = new console.Console(process.stdout, process.stderr, true);
const logConsole = new console.Console(logFile);
function log() {
const now = new Date();
const Prepend = `[i] [${now.getUTCFullYear()}-${`0${now.getUTCMonth() + 1}`.slice(-2)}-${`0${now.getUTCDate()}`.slice(-2)} ${`0${now.getUTCHours()}`.slice(-2)}:${`0${now.getUTCMinutes()}`.slice(-2)}:${`0${now.getUTCSeconds()}`.slice(-2)}.${`00${now.getUTCMilliseconds()}`.slice(-3)}] `;
arguments[0] = `${Prepend}${arguments[0].toString().normalize()}`;
for (let i = 0; i < arguments.length; i++) {
arguments[i] = arguments[i].split("\n").join(`\n${new Array(31).join(" ")}`);
}
out.log(...arguments);
logConsole.log(...arguments);
}
function warn() {
const now = new Date();
const Prepend = `[W] [${now.getUTCFullYear()}-${`0${now.getUTCMonth() + 1}`.slice(-2)}-${`0${now.getUTCDate()}`.slice(-2)} ${`0${now.getUTCHours()}`.slice(-2)}:${`0${now.getUTCMinutes()}`.slice(-2)}:${`0${now.getUTCSeconds()}`.slice(-2)}.${`00${now.getUTCMilliseconds()}`.slice(-3)}] `;
arguments[0] = `${Prepend}${arguments[0].toString().normalize()}`;
for (let i = 0; i < arguments.length; i++) {
const argument = arguments[i].toString().normalize();
arguments[i] = argument.split("\n").join(`\n${new Array(31).join(" ")}`);
}
out.warn(...arguments);
logConsole.warn(...arguments);
}
function error() {
const now = new Date();
const Prepend = `==== [ERROR] [${now.getUTCFullYear()}-${`0${now.getUTCMonth() + 1}`.slice(-2)}-${`0${now.getUTCDate()}`.slice(-2)} ${`0${now.getUTCHours()}`.slice(-2)}:${`0${now.getUTCMinutes()}`.slice(-2)}:${`0${now.getUTCSeconds()}`.slice(-2)}.${`00${now.getUTCMilliseconds()}`.slice(-3)}] ====\n`;
arguments[0] = `${Prepend}${arguments[0].toString().normalize()}`;
for (let i = 0; i < arguments.length; i++) {
arguments[i] = arguments[i].toString().normalize();
}
out.error(...arguments);
logConsole.error(...arguments);
}
console.log = log;
console.warn = warn;
console.error = error;
}

View File

@ -0,0 +1,24 @@
import pack from "../../package.json";
import { EmbedBuilder } from "discord.js";
import client from "../client";
// const _coolColors = [0x054566];
export default function getDefaultEmbed(): EmbedBuilder {
const embed = new EmbedBuilder();
embed.setFooter({
text: `Channel filter V${pack.version} by AstroGD®`,
iconURL: client.user?.avatarURL() || undefined,
});
embed.setTimestamp(new Date());
embed.setColor(0x3682cc);
return embed;
}
export function getSuccessEmbed(): EmbedBuilder {
const embed = getDefaultEmbed();
embed.setTitle("Success");
embed.setColor(0x32d122);
return embed;
}