Updated log function
This commit is contained in:
@@ -71,12 +71,12 @@ const cmd: SubCommand = async ({ interaction }) => {
|
||||
for (const gmember of guildMembers) {
|
||||
const memberData = verifiedUsers.find(user => user.userID === gmember.id)
|
||||
|
||||
log(`Updating ${gmember.member.user.username} [${i}/${guildMembers.length}]`, "info", { type: "preset", color: "green" })
|
||||
log.custom(`Updating ${gmember.member.user.username} [${i}/${guildMembers.length}]`, "info", { type: "preset", color: "green" })
|
||||
i++
|
||||
|
||||
if (!memberData) {
|
||||
if (gmember.member.user.bot) {
|
||||
log(` Skipped bot [${gmember.member.user.username}]`, "info", { type: "preset", color: "lavender" })
|
||||
log.custom(` Skipped bot [${gmember.member.user.username}]`, "info", { type: "preset", color: "lavender" })
|
||||
continue
|
||||
}
|
||||
const roles = roleManage("defaultnoverify")
|
||||
@@ -85,7 +85,7 @@ const cmd: SubCommand = async ({ interaction }) => {
|
||||
await gmember.member.setNickname(`${gmember.member.user.username} (X)`, "Updating all discord members").catch(() => {
|
||||
// Do nothing
|
||||
})
|
||||
log(`${gmember.member.user.username} [X]`, "info", { type: "preset", color: "lavender" })
|
||||
log.custom(`${gmember.member.user.username} [X]`, "info", { type: "preset", color: "lavender" })
|
||||
} else {
|
||||
const uuid = memberData.uuid
|
||||
const ign = await getIGN(uuid)
|
||||
@@ -94,10 +94,10 @@ const cmd: SubCommand = async ({ interaction }) => {
|
||||
const roles = roleManage("default")
|
||||
await gmember.member.roles.remove(roles.rolesToRemove, "Updating all discord members")
|
||||
await gmember.member.roles.add(roles.rolesToAdd, "Updating all discord members")
|
||||
log(`${gmember.member.user.username} [Default]`, "info", { type: "preset", color: "lavender" })
|
||||
log.custom(`${gmember.member.user.username} [Default]`, "info", { type: "preset", color: "lavender" })
|
||||
} else if (guildMemberIDs.includes(memberData!.uuid)) {
|
||||
const guildMemberRank = hypixelGuildMembers.find(gmember => gmember.uuid === memberData!.uuid)!.rank
|
||||
log(" Updating roles for " + gmember.member.user.username, "info", { type: "preset", color: "lavender" })
|
||||
log.custom(" Updating roles for " + gmember.member.user.username, "info", { type: "preset", color: "lavender" })
|
||||
|
||||
const rank = getGuildRank(guildMemberRank)
|
||||
if (rank) {
|
||||
@@ -111,7 +111,7 @@ const cmd: SubCommand = async ({ interaction }) => {
|
||||
}
|
||||
}
|
||||
|
||||
log("Successfully updated all roles.", "info")
|
||||
log.info("Successfully updated all roles.")
|
||||
|
||||
await channel.send({
|
||||
embeds: [{
|
||||
|
||||
@@ -26,7 +26,7 @@ export default {
|
||||
}))
|
||||
|
||||
await interaction.respond(results.slice(0, 25)).catch(err => {
|
||||
log(err, "error")
|
||||
log.error(err)
|
||||
})
|
||||
}
|
||||
} as IAutocomplete
|
||||
|
||||
@@ -85,7 +85,7 @@ export default {
|
||||
if (process.env.NODE_ENV === "dev") return
|
||||
|
||||
const [error] = await tryCatch(updateWaitingList())
|
||||
if (error) return log("Error while trying to update waiting list.", "error")
|
||||
if (error) return log.error("Error while trying to update waiting list.")
|
||||
|
||||
async function updateWaitingList() {
|
||||
const channel = guild.channels.cache.get(waitingListChannel) as TextChannel
|
||||
|
||||
@@ -10,7 +10,7 @@ async function guildWeekly() {
|
||||
const channel = client.channels.cache.get(guildLogChannel) as TextChannel
|
||||
|
||||
if (!channel) {
|
||||
log("Guild log channel not found", "error")
|
||||
log.error("Guild log channel not found")
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ import { log } from "~/utils/Logger"
|
||||
|
||||
export const once = true
|
||||
const event: Event<"ready"> = (client) => {
|
||||
log("Logged in as " + client.user!.tag + "!", "info", { type: "preset", color: "green" })
|
||||
log.custom("Logged in as " + client.user!.tag + "!", "info", { type: "preset", color: "green" })
|
||||
}
|
||||
|
||||
export default event
|
||||
|
||||
@@ -73,33 +73,33 @@ export default async function autoDeployCommands(fileType: FileType, client: Ext
|
||||
// }).join("\n")
|
||||
|
||||
if (JSON.stringify(commandData) === JSON.stringify(currentCommandsData)) {
|
||||
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" }))
|
||||
log.custom("Commands are up to date.", "info", { type: "preset", color: "green" })
|
||||
// log.custom(nc, "info", { type: "preset", color: "lavender" })
|
||||
nc.forEach(c => log.custom(c, "info", { type: "preset", color: "lavender" }))
|
||||
} else {
|
||||
log("Commands are not up to date.", "info", { type: "preset", color: "red" })
|
||||
log.custom("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)
|
||||
}
|
||||
// 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" })
|
||||
// log.custom(nc, "info", { type: "preset", color: "lavender" })
|
||||
nc.forEach(c => log.custom(c, "info", { type: "preset", color: "lavender" }))
|
||||
log.custom("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)
|
||||
log(" " + cmd.name + " was unregistered.", "info", { type: "preset", color: "red" })
|
||||
log.custom(" " + 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)!)
|
||||
log(" " + cmd.name + " was registered.", "info", { type: "preset", color: "lavender" })
|
||||
log.custom(" " + cmd.name + " was registered.", "info", { type: "preset", color: "lavender" })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,13 +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)
|
||||
log(" " + cmd.name + " was updated.", "info", { type: "preset", color: "lavender" })
|
||||
log.custom(" " + cmd.name + " was updated.", "info", { type: "preset", color: "lavender" })
|
||||
}
|
||||
}
|
||||
|
||||
log("-------------", "info", { type: "preset", color: "lavender" })
|
||||
// log(nc, "info", { type: "preset", color: "lavender" })
|
||||
nc.forEach(c => log(c, "info", { type: "preset", color: "lavender" }))
|
||||
log.custom("-------------", "info", { type: "preset", color: "lavender" })
|
||||
// log.custom(nc, "info", { type: "preset", color: "lavender" })
|
||||
nc.forEach(c => log.custom(c, "info", { type: "preset", color: "lavender" }))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -33,15 +33,15 @@ export class ExtendedClient extends Client {
|
||||
async start() {
|
||||
let token: string
|
||||
if (process.env.NODE_ENV === "dev" && process.env.TYPESCRIPT === "true") {
|
||||
log("Running in development mode. [tsx]", "info", { type: "preset", color: "lavender" })
|
||||
log.custom("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) {
|
||||
log("Running in development mode.", "info", { type: "preset", color: "lavender" })
|
||||
log.custom("Running in development mode.", "info", { type: "preset", color: "lavender" })
|
||||
token = env.dev.DEVTOKEN
|
||||
autoDeployCommands("js", this)
|
||||
} else {
|
||||
log("Running in production mode.", "info", { type: "preset", color: "green" })
|
||||
log.custom("Running in production mode.", "info", { type: "preset", color: "green" })
|
||||
token = env.prod.TOKEN
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ export default async function loadAutocompleteEvents(client: Client, ft: FileTyp
|
||||
const autocomplete = client.autocomplete.get(interaction.commandName)
|
||||
|
||||
if (!autocomplete) {
|
||||
log(`No autocomplete matching ${interaction.commandName} was found.`, "error")
|
||||
log.error(`No autocomplete matching ${interaction.commandName} was found.`)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -45,6 +45,6 @@ export default async function loadAutocompleteEvents(client: Client, ft: FileTyp
|
||||
}]
|
||||
})
|
||||
}
|
||||
log(error, "error")
|
||||
log.error(error)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ export default async function loadButtonEvents(client: Client, ft: FileType) {
|
||||
content: "Button logic not implemented. This is most likely an old button",
|
||||
flags: MessageFlags.Ephemeral
|
||||
})
|
||||
log(`No event matching ${interaction.customId} was found.`, "error")
|
||||
log.error(`No event matching ${interaction.customId} was found.`)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ export default async function loadButtonEvents(client: Client, ft: FileType) {
|
||||
})
|
||||
}
|
||||
|
||||
log(error, "error")
|
||||
log.error(error)
|
||||
if (!interaction.deferred) {
|
||||
await interaction.reply({
|
||||
embeds: [{
|
||||
|
||||
@@ -30,7 +30,7 @@ export default async function loadSlashCommandsEvents(client: Client, ft: FileTy
|
||||
content: "Command logic not implemented. This is most likely an old command",
|
||||
flags: MessageFlags.Ephemeral
|
||||
})
|
||||
log(`No command matching ${interaction.commandName} was found.`, "error")
|
||||
log.error(`No command matching ${interaction.commandName} was found.`)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ export default async function loadSlashCommandsEvents(client: Client, ft: FileTy
|
||||
})
|
||||
}
|
||||
|
||||
log(error, "error")
|
||||
log.error(error)
|
||||
if (!interaction.deferred) {
|
||||
await interaction.reply({
|
||||
embeds: [{
|
||||
|
||||
@@ -30,7 +30,7 @@ export default async function loadContextMenuEvents(client: Client, ft: FileType
|
||||
content: "Command logic not implemented. This is most likely an old command",
|
||||
flags: MessageFlags.Ephemeral
|
||||
})
|
||||
log(`No command matching ${interaction.commandName} was found.`, "error")
|
||||
log.error(`No command matching ${interaction.commandName} was found.`)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ export default async function loadContextMenuEvents(client: Client, ft: FileType
|
||||
})
|
||||
}
|
||||
|
||||
log(error, "error")
|
||||
log.error(error)
|
||||
if (!interaction.deferred) {
|
||||
await interaction.reply({
|
||||
embeds: [{
|
||||
|
||||
@@ -9,11 +9,11 @@ import loadEvents from "./events"
|
||||
import loadModalEvents from "./modal"
|
||||
|
||||
export default async function loadAllEvents(client: Client, ft: "js" | "ts") {
|
||||
await loadEvents(client, ft).then(() => log("Events loaded", "info"))
|
||||
await loadButtonEvents(client, ft).then(() => log("Button events loaded", "info"))
|
||||
await loadSlashCommandsEvents(client, ft).then(() => log("Slash commands loaded", "info"))
|
||||
await loadContextMenuEvents(client, ft).then(() => log("Context menu events loaded", "info"))
|
||||
await loadModalEvents(client, ft).then(() => log("Modal events loaded", "info"))
|
||||
await loadAutocompleteEvents(client, ft).then(() => log("Autocomplete events loaded", "info"))
|
||||
await loadCronEvents(ft).then(() => log("Cron events loaded", "info"))
|
||||
await loadEvents(client, ft).then(() => log.info("Events loaded"))
|
||||
await loadButtonEvents(client, ft).then(() => log.info("Button events loaded"))
|
||||
await loadSlashCommandsEvents(client, ft).then(() => log.info("Slash commands loaded"))
|
||||
await loadContextMenuEvents(client, ft).then(() => log.info("Context menu events loaded"))
|
||||
await loadModalEvents(client, ft).then(() => log.info("Modal events loaded"))
|
||||
await loadAutocompleteEvents(client, ft).then(() => log.info("Autocomplete events loaded"))
|
||||
await loadCronEvents(ft).then(() => log.info("Cron events loaded"))
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ export default async function loadModalEvents(client: Client, ft: FileType) {
|
||||
content: "Modal logic not implemented. This is most likely an old modal",
|
||||
flags: MessageFlags.Ephemeral
|
||||
})
|
||||
log(`No modal matching ${interaction.customId} was found.`, "error")
|
||||
log.error(`No modal matching ${interaction.customId} was found.`)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ export default async function loadModalEvents(client: Client, ft: FileType) {
|
||||
})
|
||||
}
|
||||
|
||||
log(error, "error")
|
||||
log.error(error)
|
||||
if (!interaction.deferred) {
|
||||
await interaction.reply({
|
||||
embeds: [{
|
||||
|
||||
@@ -25,7 +25,7 @@ export default async function logToChannel(channel: Channel, message: MessageCre
|
||||
}
|
||||
|
||||
if (!logChannel) {
|
||||
log(`[ERROR] Could not find channel used for ${channel} logging.`, "error")
|
||||
log.error(`[ERROR] Could not find channel used for ${channel} logging.`)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ class Illegitimate {
|
||||
|
||||
private async databases() {
|
||||
redis.on("ready", () => {
|
||||
log("Connected to Redis", "info", { type: "preset", color: "green" })
|
||||
log.custom("Connected to Redis", "info", { type: "preset", color: "green" })
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -28,17 +28,32 @@ type CustomColorProps = {
|
||||
color: string
|
||||
}
|
||||
|
||||
export function log(m: any, t: LogType, c?: CustomColorProps): void {
|
||||
const date = new Date()
|
||||
const time = logTimeFormatter(date)
|
||||
const logType = AllLogs[t].m
|
||||
const logColor = AllLogs[t].c
|
||||
const date = new Date()
|
||||
const time = logTimeFormatter(date)
|
||||
|
||||
const message = `${time} - [${logType}] | ${m}`
|
||||
if (!c) {
|
||||
console.log(cc(message, logColor))
|
||||
return
|
||||
}
|
||||
function info(msg: any) {
|
||||
const message = `${time} - [${AllLogs.info.m}] | ${msg}`
|
||||
console.log(cc(message, AllLogs.info.c))
|
||||
}
|
||||
|
||||
function warn(msg: any) {
|
||||
const message = `${time} - [${AllLogs.warn.m}] | ${msg}`
|
||||
console.log(cc(message, AllLogs.warn.c))
|
||||
}
|
||||
|
||||
function error(msg: any) {
|
||||
const message = `${time} - [${AllLogs.error.m}] | ${msg}`
|
||||
console.error(cc(message, AllLogs.error.c))
|
||||
}
|
||||
|
||||
function critical(msg: any) {
|
||||
const message = `${time} - [${AllLogs.critical.m}] | ${msg}`
|
||||
console.error(cc(message, AllLogs.critical.c))
|
||||
}
|
||||
|
||||
function custom(msg: any, type: LogType, c: CustomColorProps) {
|
||||
const log = AllLogs[type].m
|
||||
const message = `${time} - [${log}] | ${msg}`
|
||||
|
||||
if (c.type === "preset") {
|
||||
const color = colors[c.color]
|
||||
@@ -51,3 +66,13 @@ export function log(m: any, t: LogType, c?: CustomColorProps): void {
|
||||
function cc(text: string, color: string) {
|
||||
return chalk.hex(color)(text)
|
||||
}
|
||||
|
||||
const log = {
|
||||
info,
|
||||
warn,
|
||||
error,
|
||||
critical,
|
||||
custom
|
||||
}
|
||||
|
||||
export { cc, log }
|
||||
|
||||
Reference in New Issue
Block a user