Skip to content

[Enhancement] - remove top-leve init in useTextContent #2

@IzzyDotExe

Description

@IzzyDotExe

Priority: Medium

Type: Technical Debt / Performance

Description

Currently, useTextContent.ts loads all locale files synchronously at module import time using readFileSync. This blocks the Node.js event loop during bot startup and prevents proper async error handling.

Current Problem

// Runs immediately when module is imported
for (let locale in Locale) {
    translationFiles[locale] = JSON.parse(readFileSync(path, 'utf-8'));
}

Issues

  • Blocks event loop during module load
  • No graceful degradation if files are slow to read
  • Harder to implement hot-reloading or dynamic locale updates
  • Not idiomatic for Node.js/Discord.js applications

Proposed Solution

  1. Create Async Initialization Function
  2. Call During Bot Startup
  3. Add Safety Check in Hook

Acceptance Criteria

All locale files load asynchronously
Bot startup is non-blocking
Error handling preserves current fallback behavior
useTextContent throws clear error if called before initialization
No regression in translation functionality

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions