-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
59 lines (49 loc) · 1.49 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
import mongoose from "mongoose";
import { Client, GatewayIntentBits, Partials } from "discord.js";
import express from "express";
import cookieParser from "cookie-parser";
import { incomingMessage } from "./app/controllers/messages-controller.js";
import logger from "./app/tools/logger.js";
import { startCron, stopCron } from "./app/controllers/crons-controller.js";
import { api, oauth } from "./app/controllers/routes-controller.js";
const bot = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.DirectMessages,
],
partials: [Partials.Channel],
});
const app = express();
const port = 3000;
mongoose
.connect(process.env.MONGO_URL || "mongodb://localhost:27017/test")
.then(() => {
logger.info("Connected to database");
})
.catch((e) => logger.error(`Could not connect to database: ${e}`));
bot.on("ready", () => {
logger.info("Bot ready");
startCron(bot);
bot.user.setActivity({ name: "for new PB | ?h", type: 3 });
});
bot.on("messageCreate", incomingMessage);
bot.login(process.env.TOKEN);
app.use(express.json());
app.use((req, res, next) => {
req.bot = bot;
next();
});
app.use(cookieParser());
app.post("/api/oauth/discord/:code", oauth);
app.use("/api", api);
app.listen(port, () => {
logger.info(`Server listenning on port ${port}`);
});
process.on("exit", () => {
stopCron();
mongoose.disconnect();
logger.info("Exiting");
});