Skip to content

Commit

Permalink
added custom logger options in config.ts & make config.ts more determ…
Browse files Browse the repository at this point in the history
…inistic
  • Loading branch information
GhomKrosmonaute committed Jun 26, 2024
1 parent 12c9bb7 commit 6c85d41
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 48 deletions.
14 changes: 4 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"dependencies": {
"@discordjs/rest": "^0.5.0",
"@ghom/handler": "^3.1.0",
"@ghom/logger": "^1.2.0",
"@ghom/logger": "^2.0.0",
"@ghom/orm": "^1.7.0",
"boxen": "^7.0.0",
"chalk": "^5.0.1",
Expand Down
19 changes: 7 additions & 12 deletions src/app/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type * as discord from "discord.js"

import type * as pagination from "./pagination.ts"
import type * as command from "./command.ts"
import type * as logger from "./logger.ts"
import type * as slash from "./slash.ts"

import * as util from "./util.ts"
Expand Down Expand Up @@ -67,19 +68,13 @@ export interface Config {
* Custom messages for the system
*/
systemMessages?: Partial<util.SystemMessages>
}

const finalConfig: {
data: Config | null
} = {
data: null,
}

export function getConfig() {
if (!finalConfig.data) throw new Error("Config not initialized")
return finalConfig.data
/**
* Custom options for the system logger
*/
logger?: logger.LoggerOptions
}

export async function initConfig() {
finalConfig.data = await util.scrap(config)
export function getConfig(): Config {
return config
}
26 changes: 20 additions & 6 deletions src/app/logger.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
import { logger } from "@ghom/logger"
import { logger, Logger } from "@ghom/logger"
import { getConfig } from "./config.ts"

const log = logger.log.bind(logger)
const warn = logger.warn.bind(logger)
const error = logger.error.bind(logger)
const success = logger.success.bind(logger)
const { logger: loggerOptions } = getConfig()

export const systemLogger = loggerOptions ? new Logger(loggerOptions) : logger

const log = systemLogger.log.bind(systemLogger)
const warn = systemLogger.warn.bind(systemLogger)
const error = systemLogger.error.bind(systemLogger)
const success = systemLogger.success.bind(systemLogger)

export { log, warn, error, success }

export { Logger } from "@ghom/logger"
export {
Logger,
LoggerLevels,
defaultLoggerRenders,
defaultLoggerColors,
defaultLoggerPattern,
loggerLevelName,
} from "@ghom/logger"

export type * from "@ghom/logger"
34 changes: 17 additions & 17 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
import * as app from "#app"

export const config: app.Scrap<app.Config> = {
export const config: app.Config = {
ignoreBots: true,
getPrefix() {
return process.env.BOT_PREFIX!
},
client: {
intents: [
app.IntentsBitField.Flags.Guilds,
app.IntentsBitField.Flags.GuildMembers,
app.IntentsBitField.Flags.GuildModeration,
app.IntentsBitField.Flags.GuildEmojisAndStickers,
app.IntentsBitField.Flags.GuildIntegrations,
app.IntentsBitField.Flags.GuildWebhooks,
app.IntentsBitField.Flags.GuildInvites,
app.IntentsBitField.Flags.GuildVoiceStates,
app.IntentsBitField.Flags.GuildPresences,
app.IntentsBitField.Flags.GuildMessages,
app.IntentsBitField.Flags.GuildMessageReactions,
app.IntentsBitField.Flags.GuildMessageTyping,
app.IntentsBitField.Flags.DirectMessages,
app.IntentsBitField.Flags.DirectMessageReactions,
app.IntentsBitField.Flags.DirectMessageTyping,
app.IntentsBitField.Flags.MessageContent,
"Guilds",
"GuildMembers",
"GuildModeration",
"GuildEmojisAndStickers",
"GuildIntegrations",
"GuildWebhooks",
"GuildInvites",
"GuildVoiceStates",
"GuildPresences",
"GuildMessages",
"GuildMessageReactions",
"GuildMessageTyping",
"DirectMessages",
"DirectMessageReactions",
"DirectMessageTyping",
"MessageContent",
],
makeCache: app.Options.cacheWithLimits({
...app.Options.DefaultMakeCacheSettings,
Expand Down
1 change: 0 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ const app = await import("#app")

try {
await app.orm.init()
await app.initConfig()
await app.commandHandler.init()
await app.slashCommandHandler.init()
await app.listenerHandler.init()
Expand Down
1 change: 0 additions & 1 deletion tests/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const app = await import("#app")

try {
await app.orm.handler.init()
await app.initConfig()
await app.commandHandler.init()
await app.slashCommandHandler.init()
await app.listenerHandler.init()
Expand Down

0 comments on commit 6c85d41

Please sign in to comment.