djskage
Version:
A Discord.js extension for utility commands
176 lines (175 loc) • 7.02 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const discordjs = __importStar(require("discord.js"));
const moment_1 = __importDefault(require("moment"));
class Logger {
static getCallerName() {
const stack = new Error().stack || "";
const stackLines = stack.split("\n");
const callerLine = stackLines[3];
const match = callerLine.match(/at .*\\(.*):(\d+):\d+/);
if (match) {
const file = match[1];
const lineNumber = match[2];
return `${file}:${lineNumber}`;
}
return "Unknown";
}
static setDebugOptions({ enabled, level, }) {
if (!enabled || !level)
return;
this.debugEnabled = enabled;
this.debugLevel = level;
}
static log(d, name) {
if (!this.debugEnabled)
return;
if (!this.debugLevel.includes("log"))
return;
console.log(`${Color.greenBright(`[${this.djsversion}]`)} - ${Color.whiteBright((0, moment_1.default)().format("MM/DD H:mm:ss"))} - ${Color.orange("LOG".padEnd(6))} ${Color.greenBright(" | ") +
Color.orange(`[${name ? name : this.getCallerName()}]`)} ${Color.greenBright(`| ${d}`)}`);
}
static ready(d, name) {
if (!this.debugEnabled)
return;
console.log(Color.blueBright(`${Color.blueBright(`[${this.djsversion}]`)} - ${Color.whiteBright((0, moment_1.default)().format("MM/DD H:mm:ss"))} - ${Color.orange("READY".padEnd(6))} ${Color.blueBright(" | ") +
Color.orange(`[${name ? name : this.getCallerName()}]`)} ${Color.blueBright(`| ${d}`)}`));
}
static warn(d, name) {
if (!this.debugEnabled)
return;
if (!this.debugLevel.includes("warn"))
return;
console.log(Color.yellow(`${Color.yellow(`[${this.djsversion}]`)} - ${Color.whiteBright((0, moment_1.default)().format("MM/DD H:mm:ss"))} - ${Color.orange("WARN".padEnd(6))} ${Color.yellow(" | ") +
Color.orange(`[${name ? name : this.getCallerName()}]`)} ${Color.yellow(`| ${d}`)}`));
}
static error(d, e, name) {
if (!this.debugEnabled)
return;
if (!this.debugLevel.includes("error"))
return;
console.log(Color.red(`${Color.red(`[${this.djsversion}]`)} - ${Color.whiteBright((0, moment_1.default)().format("MM/DD H:mm:ss"))} - ${Color.orange("ERROR".padEnd(6))} ${Color.red(" | ") +
Color.orange(`[${name ? name : this.getCallerName()}]`)} ${Color.red(`| ${d}`)}`));
e ? console.error(Color.red(e.stack ? e.stack : e)) : null;
}
static verbose(d, name) {
if (!this.debugEnabled)
return;
if (!this.debugLevel.includes("verbose"))
return;
console.log(Color.cyan(`${Color.cyan(`[${this.djsversion}]`)} - ${Color.whiteBright((0, moment_1.default)().format("MM/DD H:mm:ss"))} - ${Color.orange("VERBOSE".padEnd(0))}${Color.cyan(" | ") +
Color.orange(`[${name ? name : this.getCallerName()}]`)} ${Color.cyan(`| ${d}`)}`));
}
static fatal(d, e, name) {
if (!this.debugEnabled)
return;
if (!this.debugLevel.includes("fatal"))
return;
console.log(Color.bold(Color.whiteBright(`${Color.whiteBright(`[${this.djsversion}]`)} - ${Color.whiteBright((0, moment_1.default)().format("MM/DD H:mm:ss"))} - ${Color.orange("FATAL".padEnd(6))} ${Color.whiteBright(" | ") +
Color.orange(`[${name ? name : this.getCallerName()}]`)} ${Color.whiteBright(`| ${d}`)}`)));
e
? console.error(Color.bold(Color.whiteBright(`${JSON.stringify(e)}`)))
: null;
}
}
Logger.debugEnabled = false;
Logger.djsversion = "v" + discordjs.version;
exports.default = Logger;
;
class Color {
static applyStyle(text, style) {
return `${style}${text}${Color.RESET}`;
}
static bold(text) {
return Color.applyStyle(text, Color.BOLD);
}
static underline(text) {
return Color.applyStyle(text, Color.UNDERLINE);
}
static red(text) {
return Color.applyStyle(text, Color.RED);
}
static green(text) {
return Color.applyStyle(text, Color.GREEN);
}
static yellow(text) {
return Color.applyStyle(text, Color.YELLOW);
}
static orange(text) {
return Color.applyStyle(text, Color.ORANGE);
}
static blue(text) {
return Color.applyStyle(text, Color.BLUE);
}
static magenta(text) {
return Color.applyStyle(text, Color.MAGENTA);
}
static cyan(text) {
return Color.applyStyle(text, Color.CYAN);
}
static redBright(text) {
return Color.applyStyle(text, Color.BRIGHT_RED);
}
static greenBright(text) {
return Color.applyStyle(text, Color.BRIGHT_GREEN);
}
static yellowBright(text) {
return Color.applyStyle(text, Color.BRIGHT_YELLOW);
}
static blueBright(text) {
return Color.applyStyle(text, Color.BRIGHT_BLUE);
}
static magentaBright(text) {
return Color.applyStyle(text, Color.BRIGHT_MAGENTA);
}
static cyanBright(text) {
return Color.applyStyle(text, Color.BRIGHT_CYAN);
}
static whiteBright(text) {
return Color.applyStyle(text, Color.BRIGHT_WHITE);
}
}
Color.RESET = "\x1b[0m";
Color.BOLD = "\x1b[1m";
Color.UNDERLINE = "\x1b[4m";
Color.RED = "\x1b[31m";
Color.GREEN = "\x1b[32m";
Color.YELLOW = "\x1b[33m";
Color.ORANGE = "\x1b[38;5;214m";
Color.BLUE = "\x1b[34m";
Color.MAGENTA = "\x1b[35m";
Color.CYAN = "\x1b[36m";
Color.WHITE = "\x1b[37m";
Color.BRIGHT_RED = "\x1b[91m";
Color.BRIGHT_GREEN = "\x1b[92m";
Color.BRIGHT_YELLOW = "\x1b[93m";
Color.BRIGHT_BLUE = "\x1b[94m";
Color.BRIGHT_MAGENTA = "\x1b[95m";
Color.BRIGHT_CYAN = "\x1b[96m";
Color.BRIGHT_WHITE = "\x1b[97m";