Merge branch 'dev' into 'main'
Dev See merge request illegitimate/illegitimate-bot!313
This commit is contained in:
@@ -1,15 +1,16 @@
|
||||
import { REST, Routes } from "discord.js"
|
||||
import env from "../src/utils/Env"
|
||||
import { log } from "../src/utils/Logger.js"
|
||||
|
||||
const rest = new REST({ version: "10" }).setToken(env.dev.devtoken)
|
||||
|
||||
try {
|
||||
console.log("Started deleting application (/) commands.")
|
||||
log("Started deleting application (/) commands.", "info")
|
||||
await rest.put(
|
||||
Routes.applicationGuildCommands(env.dev.devid, env.dev.guildid),
|
||||
{ body: [] }
|
||||
)
|
||||
console.log("Successfully deleted application (/) commands.")
|
||||
log("Successfully deleted application (/) commands.", "info")
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import { REST, RESTPutAPIApplicationCommandsJSONBody, Routes } from "discord.js"
|
||||
import fs from "node:fs"
|
||||
import { ICommand } from "../src/interfaces"
|
||||
import env from "../src/utils/Env"
|
||||
import { color } from "../src/utils/Functions/colors"
|
||||
import { log } from "../src/utils/Logger.js"
|
||||
const rest = new REST({ version: "10" }).setToken(env.prod.token)
|
||||
|
||||
const commands: RESTPutAPIApplicationCommandsJSONBody = []
|
||||
@@ -19,16 +19,16 @@ for (const file of contentMenuCommands) {
|
||||
}
|
||||
|
||||
try {
|
||||
console.log(color(`Started refreshing ${commands.length} application (/) commands.`, "green"))
|
||||
log(`Started refreshing ${commands.length} application (/) commands.`, "info", { type: "preset", color: "green" })
|
||||
|
||||
const commandsString = commands.map(command => " " + command.name)
|
||||
console.log(color(commandsString.join("\n"), "lavender"))
|
||||
log(commandsString.join("\n"), "info", { type: "preset", color: "lavender" })
|
||||
|
||||
await rest.put(
|
||||
Routes.applicationCommands(env.dev.clientid),
|
||||
{ body: commands }
|
||||
).then(() => {
|
||||
console.log(color(`Successfully reloaded ${commands.length} application (/) commands.`, "green"))
|
||||
log(`Successfully reloaded ${commands.length} application (/) commands.`, "info", { type: "preset", color: "green" })
|
||||
process.exit(0)
|
||||
})
|
||||
} catch (error) {
|
||||
|
||||
@@ -2,6 +2,7 @@ import { REST, RESTPutAPIApplicationCommandsJSONBody, Routes } from "discord.js"
|
||||
import fs from "fs"
|
||||
import { ICommand } from "../src/interfaces"
|
||||
import env from "../src/utils/Env"
|
||||
import { log } from "../src/utils/Logger.js"
|
||||
const rest = new REST({ version: "10" }).setToken(env.dev.devtoken)
|
||||
|
||||
const commands: RESTPutAPIApplicationCommandsJSONBody = []
|
||||
@@ -22,13 +23,13 @@ for (const file of contentMenuCommands) {
|
||||
}
|
||||
|
||||
try {
|
||||
console.log(`Started refreshing ${commands.length} application (/) commands.`)
|
||||
log(`Started refreshing ${commands.length} application (/) commands.`, "info")
|
||||
|
||||
await rest.put(
|
||||
Routes.applicationGuildCommands(env.dev.devid, env.dev.guildid),
|
||||
{ body: commands }
|
||||
).then(() => {
|
||||
console.log(`Successfully reloaded ${commands.length} application (/) commands.`)
|
||||
log(`Successfully reloaded ${commands.length} application (/) commands.`, "info")
|
||||
process.exit(0)
|
||||
})
|
||||
} catch (error) {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import axios from "axios"
|
||||
import { log } from "../src/utils/Logger.js"
|
||||
|
||||
const url = process.env.WATCHTOWERURL
|
||||
const token = process.env.WATCHTOWERTOKEN
|
||||
@@ -12,7 +13,7 @@ await axios.get(url, {
|
||||
Authorization: `Bearer ${token}`
|
||||
}
|
||||
}).then(() => {
|
||||
console.log("Illegitimate bot updated")
|
||||
log("Illegitimate bot updated", "info")
|
||||
}).catch(err => {
|
||||
console.error("Error updating bot", err)
|
||||
})
|
||||
|
||||
@@ -108,10 +108,10 @@ export default async function guildInfo(interaction: ChatInputCommandInteraction
|
||||
const guildCreated = new Date(guildCreatedMS)
|
||||
const guildTag = guild!.tag
|
||||
const guildExpUnformatted = guild!.exp
|
||||
const guildExp = numberFormatter.format(guildExpUnformatted)
|
||||
const guildExp = numberFormatter(guildExpUnformatted)
|
||||
const guildLvl = guildLevel(guildExpUnformatted)
|
||||
const guildMembers = guild!.members
|
||||
const guildCreatedTime = dateTimeFormatter.format(guildCreated)
|
||||
const guildCreatedTime = dateTimeFormatter(guildCreated)
|
||||
|
||||
const guildOwner = guildMembers.find(m => m.rank === "Guild Master")!.uuid
|
||||
const guildOwnerName = await getIGN(guildOwner)
|
||||
@@ -124,10 +124,10 @@ export default async function guildInfo(interaction: ChatInputCommandInteraction
|
||||
})
|
||||
|
||||
const totalGuildMembersWeeklyXPUnformatted = guildMembersWeeklyXP.reduce((a, b) => a + b, 0)
|
||||
const totalGuildMembersWeeklyXP = numberFormatter.format(totalGuildMembersWeeklyXPUnformatted)
|
||||
const totalGuildMembersWeeklyXP = numberFormatter(totalGuildMembersWeeklyXPUnformatted)
|
||||
|
||||
const averageGuildMembersWeeklyXPUnformatted = Math.round(totalGuildMembersWeeklyXPUnformatted / 7)
|
||||
const averageGuildMembersWeeklyXP = numberFormatter.format(averageGuildMembersWeeklyXPUnformatted)
|
||||
const averageGuildMembersWeeklyXP = numberFormatter(averageGuildMembersWeeklyXPUnformatted)
|
||||
|
||||
await interaction.editReply({
|
||||
embeds: [{
|
||||
|
||||
@@ -102,17 +102,17 @@ export default async function guildMember(interaction: ChatInputCommandInteracti
|
||||
const guildRank = guildMember!.rank
|
||||
const memberGexp = guildMember!.expHistory
|
||||
const allDaysGexp = Object.keys(memberGexp).map(key => {
|
||||
return ("**➺ " + key + ":** " + "`" + numberFormatter.format(memberGexp[key]) + "`" + "\n")
|
||||
return ("**➺ " + key + ":** " + "`" + numberFormatter(memberGexp[key]) + "`" + "\n")
|
||||
})
|
||||
const expValue = allDaysGexp.join("")
|
||||
const totalWeeklyGexpUnformatted = Object.values(memberGexp).reduce((a, b) => a + b, 0)
|
||||
const totalWeeklyGexp = numberFormatter.format(totalWeeklyGexpUnformatted)
|
||||
const totalWeeklyGexp = numberFormatter(totalWeeklyGexpUnformatted)
|
||||
const averageWeeklyGexpUnformatted = Math.round(totalWeeklyGexpUnformatted / 7)
|
||||
const averageWeeklyGexp = numberFormatter.format(averageWeeklyGexpUnformatted)
|
||||
const averageWeeklyGexp = numberFormatter(averageWeeklyGexpUnformatted)
|
||||
|
||||
const guildMemberJoinMS = guildMember!.joined
|
||||
const guildMemberJoinTime = new Date(guildMemberJoinMS)
|
||||
const guildMemberJoin = dateTimeFormatter.format(guildMemberJoinTime)
|
||||
const guildMemberJoin = dateTimeFormatter(guildMemberJoinTime)
|
||||
|
||||
await interaction.editReply({
|
||||
embeds: [{
|
||||
|
||||
@@ -114,10 +114,10 @@ export default async function guildTop(interaction: ChatInputCommandInteraction)
|
||||
const gexpTodayUnformatted = guildMembers.map(member => {
|
||||
return member.expHistory[Object.keys(member.expHistory)[0]]
|
||||
}).reduce((a, b) => a + b, 0)
|
||||
const gexpToday = numberFormatter.format(gexpTodayUnformatted)
|
||||
const gexpToday = numberFormatter(gexpTodayUnformatted)
|
||||
|
||||
const averageGuildMemberGEXPUnformatted = Math.floor(gexpTodayUnformatted / guildMembers.length)
|
||||
const averageGuildMemberGEXP = numberFormatter.format(averageGuildMemberGEXPUnformatted)
|
||||
const averageGuildMemberGEXP = numberFormatter(averageGuildMemberGEXPUnformatted)
|
||||
|
||||
const allMembersDailyGEXP = guildMembers.map(member => {
|
||||
return {
|
||||
@@ -178,7 +178,7 @@ export default async function guildTop(interaction: ChatInputCommandInteraction)
|
||||
const sliceSize = amount / 4
|
||||
|
||||
for (let i = 0; i < amount; i++) {
|
||||
const gexp = numberFormatter.format(topMembers[i].gexp)
|
||||
const gexp = numberFormatter(topMembers[i].gexp)
|
||||
const ign = guildData.find(member => member.uuid === topMembers[i].uuid)?.ign
|
||||
|
||||
const position = i + 1
|
||||
|
||||
@@ -3,9 +3,9 @@ import { getVerifies } from "src/drizzle/functions.js"
|
||||
import { embedColor, hypixelGuildID } from "~/config/options.js"
|
||||
import { IGuildData } from "~/interfaces"
|
||||
import env from "~/utils/Env.js"
|
||||
import { color } from "~/utils/Functions/colors.js"
|
||||
import roleManage from "~/utils/Functions/rolesmanage.js"
|
||||
import { getGuild, getIGN } from "~/utils/Hypixel.js"
|
||||
import { log } from "~/utils/Logger.js"
|
||||
|
||||
export default async function updateAll(interaction: ChatInputCommandInteraction): Promise<void> {
|
||||
await interaction.deferReply()
|
||||
@@ -66,12 +66,12 @@ export default async function updateAll(interaction: ChatInputCommandInteraction
|
||||
for (const gmember of guildMembers) {
|
||||
const memberData = verifiedUsers.find(user => user.userID === gmember.id)
|
||||
|
||||
console.log(color(`Updating ${gmember.member.user.username} [${i}/${guildMembers.length}]`, "green"))
|
||||
log(`Updating ${gmember.member.user.username} [${i}/${guildMembers.length}]`, "info", { type: "preset", color: "green" })
|
||||
i++
|
||||
|
||||
if (!memberData) {
|
||||
if (gmember.member.user.bot) {
|
||||
console.log(color(` Skipped bot [${gmember.member.user.username}]`, "lavender"))
|
||||
log(` Skipped bot [${gmember.member.user.username}]`, "info", { type: "preset", color: "lavender" })
|
||||
continue
|
||||
}
|
||||
const roles = roleManage("defaultnoverify")
|
||||
@@ -80,7 +80,7 @@ export default async function updateAll(interaction: ChatInputCommandInteraction
|
||||
await gmember.member.setNickname(`${gmember.member.user.username} (X)`, "Updating all discord members").catch(() => {
|
||||
// Do nothing
|
||||
})
|
||||
console.log(color(`${gmember.member.user.username} [X]`, "lavender"))
|
||||
log(`${gmember.member.user.username} [X]`, "info", { type: "preset", color: "lavender" })
|
||||
} else {
|
||||
const uuid = memberData.uuid
|
||||
const ign = await getIGN(uuid)
|
||||
@@ -89,10 +89,10 @@ export default async function updateAll(interaction: ChatInputCommandInteraction
|
||||
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")
|
||||
console.log(color(`${gmember.member.user.username} [Default]`, "lavender"))
|
||||
log(`${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
|
||||
console.log(color(" Updating roles for " + gmember.member.user.username, "lavender"))
|
||||
log(" Updating roles for " + gmember.member.user.username, "info", { type: "preset", color: "lavender" })
|
||||
|
||||
if (guildMemberRank === "Guild Master") {
|
||||
const rolesmanage = roleManage("gm")
|
||||
@@ -126,7 +126,7 @@ export default async function updateAll(interaction: ChatInputCommandInteraction
|
||||
}
|
||||
}
|
||||
|
||||
console.log("Successfully updated all roles.")
|
||||
log("Successfully updated all roles.", "info")
|
||||
|
||||
await channel.send({
|
||||
embeds: [{
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { IAutocomplete } from "~/interfaces"
|
||||
import { log } from "~/utils/Logger.js"
|
||||
|
||||
export default {
|
||||
name: "unban",
|
||||
@@ -25,7 +26,7 @@ export default {
|
||||
}))
|
||||
|
||||
await interaction.respond(results.slice(0, 25)).catch(err => {
|
||||
console.log(err)
|
||||
log(err, "error")
|
||||
})
|
||||
}
|
||||
} as IAutocomplete
|
||||
|
||||
@@ -4,8 +4,8 @@ import { addWaitingList, getWaitingLists, removeWaitingList } from "src/drizzle/
|
||||
import { embedColor, hypixelGuildID, waitingListChannel, waitingListMessage } from "~/config/options.js"
|
||||
import { waitingListRole } from "~/config/roles.js"
|
||||
import { IButton } from "~/interfaces"
|
||||
import { color } from "~/utils/Functions/colors.js"
|
||||
import { getGuild, getIGN } from "~/utils/Hypixel.js"
|
||||
import { log } from "~/utils/Logger.js"
|
||||
|
||||
export default {
|
||||
name: "guildapplicationaccept",
|
||||
@@ -127,8 +127,9 @@ export default {
|
||||
})
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
} catch (err) {
|
||||
console.log(
|
||||
color("Error while trying to update waiting list.", "red")
|
||||
log(
|
||||
"Error while trying to update waiting list.",
|
||||
"error"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
import { TextChannel } from "discord.js"
|
||||
import { devMessage, embedColor, guildLogChannel, hypixelGuildID } from "~/config/options.js"
|
||||
import { ICron, IGuildData } from "~/interfaces"
|
||||
import { color } from "~/utils/Functions/colors.js"
|
||||
import { numberFormatter } from "~/utils/Functions/intlFormaters.js"
|
||||
import { getGuild, getIGN } from "~/utils/Hypixel.js"
|
||||
import { client } from "~/utils/Illegitimate.js"
|
||||
import { log } from "~/utils/Logger.js"
|
||||
|
||||
async function guildWeekly() {
|
||||
const channel = client.channels.cache.get(guildLogChannel) as TextChannel
|
||||
|
||||
if (!channel) {
|
||||
console.log(color("Guild log channel not found", "red"))
|
||||
log("Guild log channel not found", "error")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ async function guildWeekly() {
|
||||
|
||||
for (let i = 0; i < allMembersGexpSorted.length; i++) {
|
||||
const ign = await getIGN(allMembersGexpSorted[i].uuid)
|
||||
const gexp = numberFormatter.format(allMembersGexpSorted[i].exp)
|
||||
const gexp = numberFormatter(allMembersGexpSorted[i].exp)
|
||||
const position = i + 1
|
||||
guildMembersList.push("**#" + position + " " + ign + ":** `" + gexp + "`")
|
||||
}
|
||||
@@ -66,8 +66,8 @@ async function guildWeekly() {
|
||||
const averageGuildMembersDailyXPUnformatted = totalGuildMembersWeeklyXPUnformatted / 7
|
||||
|
||||
// final values
|
||||
const totalGuildMembersWeeklyXP = numberFormatter.format(totalGuildMembersWeeklyXPUnformatted)
|
||||
const averageGuildMembersWeeklyXP = numberFormatter.format(averageGuildMembersDailyXPUnformatted)
|
||||
const totalGuildMembersWeeklyXP = numberFormatter(totalGuildMembersWeeklyXPUnformatted)
|
||||
const averageGuildMembersWeeklyXP = numberFormatter(averageGuildMembersDailyXPUnformatted)
|
||||
|
||||
await message.edit({
|
||||
embeds: [{
|
||||
|
||||
@@ -12,7 +12,7 @@ export default {
|
||||
embeds: [{
|
||||
title: "New Member",
|
||||
description: userMention(member.id) + " has joined the server.\n" +
|
||||
"Account created: " + dateTimeFormatter.format(member.user.createdAt),
|
||||
"Account created: " + dateTimeFormatter(member.user.createdAt),
|
||||
color: embedColor,
|
||||
thumbnail: {
|
||||
url: member.user.avatarURL() || ""
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { IEvent } from "~/interfaces"
|
||||
import { color } from "~/utils/Functions/colors.js"
|
||||
import { log } from "~/utils/Logger.js"
|
||||
|
||||
export default {
|
||||
event: "interactionCreate",
|
||||
@@ -15,21 +15,19 @@ export default {
|
||||
}
|
||||
|
||||
if (subcommand) {
|
||||
console.log(
|
||||
color(
|
||||
interaction.user.username + " ran " +
|
||||
interaction.commandName + " " +
|
||||
subcommand,
|
||||
"pink"
|
||||
)
|
||||
log(
|
||||
interaction.user.username + " ran " +
|
||||
interaction.commandName + " " +
|
||||
subcommand,
|
||||
"info",
|
||||
{ type: "preset", color: "pink" }
|
||||
)
|
||||
} else {
|
||||
console.log(
|
||||
color(
|
||||
interaction.user.username + " ran " +
|
||||
interaction.commandName,
|
||||
"pink"
|
||||
)
|
||||
log(
|
||||
interaction.user.username + " ran " +
|
||||
interaction.commandName,
|
||||
"info",
|
||||
{ type: "preset", color: "pink" }
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -43,11 +41,10 @@ export default {
|
||||
btnId = btnId.split("-")[0]
|
||||
}
|
||||
|
||||
console.log(
|
||||
color(
|
||||
interaction.user.username + " clicked " + btnId,
|
||||
"pink"
|
||||
)
|
||||
log(
|
||||
interaction.user.username + " clicked " + btnId,
|
||||
"info",
|
||||
{ type: "preset", color: "pink" }
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { IEvent } from "~/interfaces"
|
||||
import { color } from "~/utils/Functions/colors.js"
|
||||
import { log } from "~/utils/Logger.js"
|
||||
|
||||
export default {
|
||||
event: "ready",
|
||||
execute(client) {
|
||||
console.log(color("Logged in as " + client.user!.tag + "!", "green"))
|
||||
log("Logged in as " + client.user!.tag + "!", "info", { type: "preset", color: "green" })
|
||||
}
|
||||
} as IEvent<"ready">
|
||||
|
||||
@@ -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,12 +1,24 @@
|
||||
const numberFormatter = new Intl.NumberFormat("en-US")
|
||||
export function numberFormatter(d: number): string {
|
||||
return new Intl.NumberFormat("en-US").format(d)
|
||||
}
|
||||
|
||||
const dateTimeFormatter = new Intl.DateTimeFormat("hr-HR", {
|
||||
year: "numeric",
|
||||
month: "numeric",
|
||||
day: "numeric",
|
||||
hour: "numeric",
|
||||
minute: "numeric",
|
||||
second: "numeric"
|
||||
})
|
||||
export function dateTimeFormatter(d: Date): string {
|
||||
return new Intl.DateTimeFormat("hr-HR", {
|
||||
year: "numeric",
|
||||
month: "numeric",
|
||||
day: "numeric",
|
||||
hour: "numeric",
|
||||
minute: "numeric",
|
||||
second: "numeric"
|
||||
}).format(d)
|
||||
}
|
||||
|
||||
export { dateTimeFormatter, numberFormatter }
|
||||
export function logTimeFormatter(d: Date): string {
|
||||
return new Intl.DateTimeFormat("hr-HR", {
|
||||
year: "numeric",
|
||||
month: "numeric",
|
||||
day: "numeric",
|
||||
hour: "numeric",
|
||||
minute: "numeric"
|
||||
}).format(d)
|
||||
}
|
||||
|
||||
@@ -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" })
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
56
src/utils/Logger.ts
Normal file
56
src/utils/Logger.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
import chalk from "chalk"
|
||||
import { logTimeFormatter } from "./Functions/intlFormaters.js"
|
||||
|
||||
const colors = {
|
||||
red: "#f38ba8",
|
||||
lavender: "#b4befe",
|
||||
green: "#a6e3a1",
|
||||
pink: "#f5c2e7"
|
||||
}
|
||||
|
||||
type Colors = keyof typeof colors
|
||||
|
||||
const AllLogs = {
|
||||
info: { m: "INFO", c: null },
|
||||
error: { m: "ERROR", c: "#ff6666" },
|
||||
warn: { m: "WARN", c: "#ffcc99" },
|
||||
debug: { m: "DEBUG", c: "#66ff66" }
|
||||
} as const
|
||||
|
||||
type LogType = keyof typeof AllLogs
|
||||
|
||||
type CustomColorProps = {
|
||||
type: "preset"
|
||||
color: Colors
|
||||
} | {
|
||||
type: "custom"
|
||||
color: string
|
||||
}
|
||||
|
||||
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 (!c) {
|
||||
if (t === "info") {
|
||||
console.log(message)
|
||||
return
|
||||
}
|
||||
console.log(cc(message, logColor!))
|
||||
return
|
||||
}
|
||||
|
||||
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) {
|
||||
return chalk.hex(color)(text)
|
||||
}
|
||||
Reference in New Issue
Block a user