-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.mjs
59 lines (52 loc) · 1.59 KB
/
index.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/**
* Imports
*/
import dotenv from 'dotenv';
import fs from 'fs';
import path from 'path';
import * as Sentry from '@sentry/node';
import { ProfilingIntegration } from '@sentry/profiling-node';
import Client from './src/Client.mjs';
import Translate from './src/modules/Translate/Translate.mjs';
// Load .env file
const productionEnvPath = path.join(process.cwd(), '.env.production');
dotenv.config({
path: fs.existsSync(productionEnvPath)
? productionEnvPath
: path.join(process.cwd(), '.env'),
});
// Override .env file with .development.env file if in development mode
if (process.env.NODE_ENV !== 'production') dotenv.config({ override: true });
// Override console.log to include a timestamp
console.log = console.info = (
oldLog =>
(...args) => {
const timestamp = new Date()
.toLocaleString(process.env.LOCALE, { timeZone: process.env.TIMEZONE })
.split(', ')
.join(' ');
oldLog.apply(console, [`[${timestamp}]`, ...args]);
}
)(console.log);
/**
* Initiation
*/
async function init() {
// Initiate Sentry
if (process.env.NODE_ENV === 'production' && process.env.SENTRY_DSN)
Sentry.init({
dsn: process.env.SENTRY_DSN,
environment: process.env.NODE_ENV,
integrations: [new ProfilingIntegration()],
includeLocalVariables: true,
// Performance Monitoring
tracesSampleRate: 1.0,
// Set sampling rate for profiling - this is relative to tracesSampleRate
profilesSampleRate: 1.0,
});
// Initiate translation engines
await Translate.initEngines();
// Initiate Discord client
await Client.init();
}
init();