Added new logger
This commit is contained in:
@@ -3,7 +3,7 @@ import fs from "fs"
|
||||
import { ICommand, IContextMenu } from "~/interfaces"
|
||||
import { ExtendedClient } from "./Client.js"
|
||||
import env from "./Env.js"
|
||||
import { color } from "./Functions/colors.js"
|
||||
import { log } from "./Logger.js"
|
||||
type FileType = "js" | "ts"
|
||||
|
||||
export default async function autoDeployCommands(fileType: FileType, client: ExtendedClient) {
|
||||
@@ -69,34 +69,37 @@ export default async function autoDeployCommands(fileType: FileType, client: Ext
|
||||
|
||||
const nc = commands.map(cmd => {
|
||||
return " " + cmd.name
|
||||
}).join("\n")
|
||||
})
|
||||
// }).join("\n")
|
||||
|
||||
if (JSON.stringify(commandData) === JSON.stringify(currentCommandsData)) {
|
||||
console.log(color("Commands are up to date.", "green"))
|
||||
console.log(color(nc, "lavender"))
|
||||
log("Commands are up to date.", "info", { type: "preset", color: "green" })
|
||||
// log(nc, "info", { type: "preset", color: "lavender" })
|
||||
nc.forEach(c => log(c, "info", { type: "preset", color: "lavender" }))
|
||||
} else {
|
||||
console.log(color("Commands are not up to date.", "red"))
|
||||
log("Commands are not up to date.", "info", { type: "preset", color: "red" })
|
||||
|
||||
if (currentCommands.size === 0) {
|
||||
for (const cmd of commands) {
|
||||
await guildclient.commands.create(cmd)
|
||||
}
|
||||
console.log(color(nc, "lavender"))
|
||||
console.log(color("All commands were registered.", "green"))
|
||||
// log(nc, "info", { type: "preset", color: "lavender" })
|
||||
nc.forEach(c => log(c, "info", { type: "preset", color: "lavender" }))
|
||||
log("All commands were registered.", "info", { type: "preset", color: "green" })
|
||||
return
|
||||
}
|
||||
|
||||
for (const cmd of currentCommandsData) {
|
||||
if (!commandData.find(c => c.name === cmd.name)) {
|
||||
await guildclient.commands.delete(currentCommands.find(c => c.name === cmd.name)!.id)
|
||||
console.log(color(" " + cmd.name + " was unregistered.", "red"))
|
||||
log(" " + cmd.name + " was unregistered.", "info", { type: "preset", color: "red" })
|
||||
}
|
||||
}
|
||||
|
||||
for (const cmd of commandData) {
|
||||
if (!currentCommandsData.find(c => c.name === cmd.name)) {
|
||||
await guildclient.commands.create(commands.find(c => c.name === cmd.name)!)
|
||||
console.log(color(" " + cmd.name + " was registered.", "lavender"))
|
||||
log(" " + cmd.name + " was registered.", "info", { type: "preset", color: "lavender" })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,12 +111,13 @@ export default async function autoDeployCommands(fileType: FileType, client: Ext
|
||||
|
||||
if (JSON.stringify(cmd) !== JSON.stringify(currentCommandData)) {
|
||||
await guildclient.commands.edit(currentCommand.id, cmd)
|
||||
console.log(color(" " + cmd.name + " was updated.", "lavender"))
|
||||
log(" " + cmd.name + " was updated.", "info", { type: "preset", color: "lavender" })
|
||||
}
|
||||
}
|
||||
|
||||
console.log(color("-------------", "lavender"))
|
||||
console.log(color(nc, "lavender"))
|
||||
log("-------------", "info", { type: "preset", color: "lavender" })
|
||||
// log(nc, "info", { type: "preset", color: "lavender" })
|
||||
nc.forEach(c => log(c, "info", { type: "preset", color: "lavender" }))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import { Client, Collection, GatewayIntentBits, Partials } from "discord.js"
|
||||
import { IAutocomplete, IButton, ICommand, IContextMenu, IModal } from "~/interfaces"
|
||||
import autoDeployCommands from "./Autodeploy.js"
|
||||
import env from "./Env.js"
|
||||
import { color } from "./Functions/colors.js"
|
||||
import { log } from "./Logger.js"
|
||||
|
||||
export class ExtendedClient extends Client {
|
||||
commands: Collection<string, ICommand> = new Collection()
|
||||
@@ -33,15 +33,15 @@ export class ExtendedClient extends Client {
|
||||
async start() {
|
||||
let token: string
|
||||
if (process.env.NODE_ENV === "dev" && process.env.TYPESCRIPT === "true") {
|
||||
console.log(color("Running in development mode. [tsx]", "lavender"))
|
||||
log("Running in development mode. [tsx]", "info", { type: "preset", color: "lavender" })
|
||||
token = env.dev.devtoken
|
||||
autoDeployCommands("ts", this)
|
||||
} else if (process.env.NODE_ENV === "dev" && !process.env.TYPESCRIPT) {
|
||||
console.log(color("Running in development mode.", "lavender"))
|
||||
log("Running in development mode.", "info", { type: "preset", color: "lavender" })
|
||||
token = env.dev.devtoken
|
||||
autoDeployCommands("js", this)
|
||||
} else {
|
||||
console.log(color("Running in production mode.", "green"))
|
||||
log("Running in production mode.", "info", { type: "preset", color: "green" })
|
||||
token = env.prod.token
|
||||
}
|
||||
|
||||
|
||||
@@ -1,48 +0,0 @@
|
||||
import chalk from "chalk"
|
||||
|
||||
const colors = {
|
||||
red: "#f38ba8",
|
||||
lavender: "#b4befe",
|
||||
green: "#a6e3a1",
|
||||
pink: "#f5c2e7"
|
||||
}
|
||||
|
||||
export function color(text: string, type: keyof typeof colors) {
|
||||
return chalk.hex(colors[type])(text)
|
||||
}
|
||||
|
||||
export function colorCustom(text: string, color: string) {
|
||||
return chalk.hex(color)(text)
|
||||
}
|
||||
|
||||
/* const colors = {
|
||||
reset: "\x1b[0m",
|
||||
bright: "\x1b[1m",
|
||||
dim: "\x1b[2m",
|
||||
underscore: "\x1b[4m",
|
||||
blink: "\x1b[5m",
|
||||
reverse: "\x1b[7m",
|
||||
hidden: "\x1b[8m",
|
||||
|
||||
black: "\x1b[30m",
|
||||
red: "\x1b[31m",
|
||||
green: "\x1b[32m",
|
||||
yellow: "\x1b[33m",
|
||||
blue: "\x1b[34m",
|
||||
magenta: "\x1b[35m",
|
||||
cyan: "\x1b[36m",
|
||||
white: "\x1b[37m",
|
||||
|
||||
bgBlack: "\x1b[40m",
|
||||
bgRed: "\x1b[41m",
|
||||
bgGreen: "\x1b[42m",
|
||||
bgYellow: "\x1b[43m",
|
||||
bgBlue: "\x1b[44m",
|
||||
bgMagenta: "\x1b[45m",
|
||||
bgCyan: "\x1b[46m",
|
||||
bgWhite: "\x1b[47m",
|
||||
}
|
||||
|
||||
export default function colorize(text: string, color: keyof typeof colors) {
|
||||
return colors[color] + text + colors.reset
|
||||
} */
|
||||
@@ -1,6 +1,7 @@
|
||||
import { Guild, MessageCreateOptions, TextChannel } from "discord.js"
|
||||
import { botLogChannel, devLogChannel, errorLogChannel, guildid, guildLogChannel, moderationLogChannel, onlineLogChannel } from "~/config/options.js"
|
||||
import { client } from "~/utils/Illegitimate.js"
|
||||
import { log } from "../Logger.js"
|
||||
|
||||
const channels = {
|
||||
online: onlineLogChannel,
|
||||
@@ -24,7 +25,7 @@ export default async function logToChannel(channel: Channel, message: MessageCre
|
||||
}
|
||||
|
||||
if (!logChannel) {
|
||||
console.log(`[ERROR] Could not find channel used for ${channel} logging.`)
|
||||
log(`[ERROR] Could not find channel used for ${channel} logging.`, "error")
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -3,9 +3,9 @@ import { YoutubeiExtractor } from "discord-player-youtubei"
|
||||
import { Redis } from "ioredis"
|
||||
import { ExtendedClient as Client } from "~/utils/Client.js"
|
||||
import env from "~/utils/Env.js"
|
||||
import { color } from "~/utils/Functions/colors.js"
|
||||
import { MissingEnvVarsError } from "./Classes.js"
|
||||
import loadAllEvents from "./Events/loadevents.js"
|
||||
import { log } from "./Logger.js"
|
||||
|
||||
const client = new Client()
|
||||
const redis = new Redis(env.prod.redisURI)
|
||||
@@ -32,7 +32,7 @@ class Illegitimate {
|
||||
|
||||
private async databases() {
|
||||
redis.on("ready", () => {
|
||||
console.log(color("Connected to Redis", "green"))
|
||||
log("Connected to Redis", "info", { type: "preset", color: "green" })
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -14,8 +14,7 @@ const AllLogs = {
|
||||
info: { m: "INFO", c: null },
|
||||
error: { m: "ERROR", c: "#ff6666" },
|
||||
warn: { m: "WARN", c: "#ffcc99" },
|
||||
debug: { m: "DEBUG", c: "#66ff66" },
|
||||
custom: { m: "CUSTOM", c: null }
|
||||
debug: { m: "DEBUG", c: "#66ff66" }
|
||||
} as const
|
||||
|
||||
type LogType = keyof typeof AllLogs
|
||||
@@ -28,34 +27,28 @@ type CustomColorProps = {
|
||||
color: string
|
||||
}
|
||||
|
||||
export function log(m: string, t: LogType = "info", c?: CustomColorProps): void {
|
||||
export function log(m: string, t: LogType, c?: CustomColorProps): void {
|
||||
const date = new Date()
|
||||
const time = logTimeFormatter(date)
|
||||
const logType = AllLogs[t].m
|
||||
const logColor = AllLogs[t].c
|
||||
|
||||
const message = `[${logType}] ${time} | ${m}`
|
||||
if (t === "info") {
|
||||
console.log(message)
|
||||
return
|
||||
}
|
||||
|
||||
if (t === "custom") {
|
||||
if (!c) {
|
||||
console.error("Custom log type requires a color.")
|
||||
if (!c) {
|
||||
if (t === "info") {
|
||||
console.log(message)
|
||||
return
|
||||
}
|
||||
|
||||
if (c.type === "preset") {
|
||||
const color = colors[c.color]
|
||||
console.log(cc(message, color))
|
||||
} else {
|
||||
console.log(cc(message, c.color))
|
||||
}
|
||||
console.log(cc(message, logColor!))
|
||||
return
|
||||
}
|
||||
|
||||
console.log(cc(message, logColor!))
|
||||
if (c.type === "preset") {
|
||||
const color = colors[c.color]
|
||||
console.log(cc(message, color))
|
||||
} else {
|
||||
console.log(cc(message, c.color))
|
||||
}
|
||||
}
|
||||
|
||||
function cc(text: string, color: string) {
|
||||
|
||||
Reference in New Issue
Block a user