-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
86 lines (75 loc) · 2.4 KB
/
main.js
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
const {Client, Collection} = require('discord.js');
require('dotenv').config();
const TOKEN = process.env.TOKEN;
const express = require('express');
const cors = require('cors');
const fs = require('fs');
const Sentry = require('@sentry/node');
const Tracing = require('@sentry/tracing');
const getDateTime = () => {
let date = new Date();
let hour = date.getHours();
hour = (hour < 10 ? '0' : '') + hour;
let min = date.getMinutes();
min = (min < 10 ? '0' : '') + min;
let sec = date.getSeconds();
sec = (sec < 10 ? '0' : '') + sec;
let year = date.getFullYear();
let month = date.getMonth() + 1;
month = (month < 10 ? '0' : '') + month;
let day = date.getDate();
day = (day < 10 ? '0' : '') + day;
return year + '-' + month + '-' + day + '-' + hour + '-' + min + '-' + sec;
};
fs.writeFile(`logs/${getDateTime()}.txt`, '', (err) => {});
const app = express();
const corsOptions = {
origin: [ `${process.env.CLIENT_URL}`, 'http://localhost:3000' ],
credentials: true,
allowedHeaders: [
'sessionId',
'Content-Type',
'Authorization',
'authorization',
],
exposedHeaders: [ 'sessionId' ],
methods: 'GET,HEAD,PUT,PATCH,POST,DELETE',
preflightContinue: false,
};
app.use(cors(corsOptions));
const client = new Client({intents: 4097});
module.exports = app;
//Setup DB
require('./utils/functions')(client);
client.mongoose = require('./utils/mongoose');
client.mongoose.init(client.timestampParser(), client);
//Handler and Commands
client.commands = new Collection();
[ 'EventUtil', 'CommandUtil' ].forEach((handler) => {
require(`./utils/handlers/${handler}`)(client);
});
Sentry.init({
dsn: process.env.SENTRY_DNS,
// Set tracesSampleRate to 1.0 to capture 100%
// of transactions for performance monitoring.
// We recommend adjusting this value in production
tracesSampleRate: 1.0,
});
//Check error
process.on('exit', (code) => {
client.logger(`Le processus s'est arrêté avec le code: ${code}!`);
});
process.on('uncaughtException', (err, origin) => {
client.logger(`uncaughtException: ${err}`, `Origine: ${origin}`);
console.log(`uncaughtException: ${err}`, `Origine: ${origin}`);
});
process.on('unhandledRejection', (reason, promise) => {
client.logger(`UNHANDLED_REJECTION: ${reason}\n--------\n\n${promise}`);
console.log(`UNHANDLED_REJECTION: ${reason}\n--------`, promise);
});
process.on('warning', (...args) => {
client.logger(...args);
console.log(...args);
});
//Login
client.login(TOKEN);