-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
56 lines (47 loc) · 1.67 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
const { Client, GatewayIntentBits } = require('discord.js');
const express = require('express');
const dotenv = require('dotenv').config();
const connectToMongoDB = require('./connect');
const { handleGenerateNewShortURL, handleDelete } = require('./controllers/url');
const staticRoute = require('./routes/staticRouter');
const { generate } = require('./controllers/gemini');
// Connections
connectToMongoDB(process.env.MONGODB_URI)
.then(() => console.log('Connected to MongoDB'));
const app = express();
const PORT = process.env.PORT || 8001;
// Bot Configurations
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent] });
// Route Definition
app.use("/", staticRoute);
client.on("messageCreate", async (message) => {
if(message.author.bot) return;
else if(message.content.startsWith("create")) {
const res = await handleGenerateNewShortURL(message);
message.reply({
content: res.shortenedURL,
})
}
else if(message.content.startsWith("delete")) {
const res = await handleDelete(message);
message.reply({
content: res.message,
})
}
else {
const res = await generate(message);
message.reply({
content: res.message,
});
}
});
client.on("interactionCreate", (interaction) => {
if(!interaction.isCommand()) return;
if(interaction.commandName === "ping") {
interaction.reply({
content: "Pong!",
});
}
});
client.login(process.env.BOT_TOKEN);
app.listen(PORT, () => console.log(`Server Started at PORT: ${PORT}. Click Here: http://127.0.0.1:${PORT}`));