This repository has been archived by the owner on May 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
70 lines (61 loc) · 1.75 KB
/
index.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
const { ShardingManager } = require("discord.js");
const {
token,
expressPort,
mongodbUrl,
expressHost,
} = require("./config.json");
const https = require("https");
const { MongoClient, ServerApiVersion } = require("mongodb");
var fs = require("fs");
// Auth server
const app = require("./web/faceitAuth");
var options = {
key: fs.readFileSync("./web/security/cert.key"),
cert: fs.readFileSync("./web/security/cert.pem"),
};
const server = https
.createServer(options, app)
.listen(expressPort, expressHost, () => {
console.log(
"FaceIT OAuth Server listening on port " +
expressPort +
" on " +
expressHost
);
});
//test db
const mongoDBClient = new MongoClient(mongodbUrl, {
serverApi: {
version: ServerApiVersion.v1,
strict: true,
deprecationErrors: true,
},
});
async function run() {
try {
// Connect the client to the server (optional starting in v4.7)
await mongoDBClient.connect();
// Send a ping to confirm a successful connection
await mongoDBClient.db("admin").command({ ping: 1 });
console.log(
"Pinged your deployment. You successfully connected to MongoDB!"
);
// Create collection if not exists TODO
// Create if not exists index to delete ids
await mongoDBClient
.db("FaceITDiscordBot")
.collection("faceitloginids")
.createIndex({ expiresAfter: 1 }, { expireAfterSeconds: 180 });
console.log("Created Index in MongoDB");
} finally {
// Ensures that the client will close when you finish/error
await mongoDBClient.close();
}
}
run().catch(console.dir);
const manager = new ShardingManager("./bot.js", {
token: token,
});
manager.on("shardCreate", (shard) => console.log(`Launched shard ${shard.id}`));
manager.spawn();