| 19 | |
| 20 | // Diagnostic logging helper with timestamp and process info |
| 21 | function log(level: 'info' | 'error' | 'warn', message: string, data?: Record<string, unknown>): void { |
| 22 | const timestamp = new Date().toISOString() |
| 23 | const pid = process.pid |
| 24 | const hostname = os.hostname() |
| 25 | const prefix = `[${timestamp}] [PID:${pid}] [host:${hostname}] [discord-bot]` |
| 26 | const dataStr = data ? ` ${JSON.stringify(data)}` : '' |
| 27 | if (level === 'error') { |
| 28 | console.error(`${prefix} ${message}${dataStr}`) |
| 29 | } else if (level === 'warn') { |
| 30 | console.warn(`${prefix} ${message}${dataStr}`) |
| 31 | } else { |
| 32 | console.log(`${prefix} ${message}${dataStr}`) |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | function sleep(ms: number): Promise<void> { |
| 37 | return new Promise((resolve) => setTimeout(resolve, ms)) |