-
Notifications
You must be signed in to change notification settings - Fork 156
/
Copy pathmongodb.js
98 lines (89 loc) · 3.33 KB
/
mongodb.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
87
88
89
90
91
92
93
94
95
96
97
98
const { MongoClient } = require('mongodb');
const fs = require('fs');
const path = require('path');
const colors = require('./UI/colors/colors');
const configPath = path.join(__dirname, 'config.json');
const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
const uri = config.mongodbUri || process.env.MONGODB_URI;
const client = new MongoClient(uri);
async function connectToDatabase() {
try {
await client.connect();
console.log('\n' + '─'.repeat(40));
console.log(`${colors.magenta}${colors.bright}🕸️ DATABASE CONNECTION${colors.reset}`);
console.log('─'.repeat(40));
console.log('\x1b[36m[ DATABASE ]\x1b[0m', '\x1b[32mConnected to MongoDB ✅\x1b[0m');
} catch (err) {
console.error("Error connecting to MongoDB", err);
}
}
const db = client.db("discord-bot");
const ticketsCollection = db.collection("tickets");
const voiceChannelCollection = db.collection("voiceChannels");
const centralizedControlCollection = db.collection("centralizedControl");
const nqnCollection = db.collection("nqn");
const welcomeCollection = db.collection("welcomeChannels");
const autoroleCollection = db.collection("autorolesetups");
const hentaiCommandCollection = db.collection("hentailove");
const serverConfigCollection = db.collection("serverconfig");
const reactionRolesCollection = db.collection("reactionRoles");
const antisetupCollection = db.collection("antisetup");
const anticonfigcollection = db.collection("anticonfiglist")
const afkCollection = db.collection('afk');
const giveawayCollection = db.collection("giveaways");
const notificationsCollection = db.collection("notifications");
const logsCollection = db.collection("logs");
const nicknameConfigs = db.collection("nicknameConfig");
const economyCollection = db.collection("economy");
const usersCollection = db.collection('users');
const epicDataCollection = db.collection('epicData');
const customCommandsCollection = db.collection('customCommands');
const birthdayCollection = db.collection('birthday');
const applicationCollection = db.collection('applications');
const serverLevelingLogsCollection = db.collection('serverLevelingLogs');
const commandLogsCollection = db.collection('commandLogs');
const reportsCollection = db.collection('reports');
async function saveGiveaway(giveaway) {
await giveawayCollection.updateOne(
{ messageId: giveaway.messageId },
{ $set: giveaway },
{ upsert: true }
);
}
async function getGiveaways() {
return await giveawayCollection.find().toArray();
}
async function deleteGiveaway(messageId) {
await giveawayCollection.deleteOne({ messageId });
}
module.exports = {
connectToDatabase,
ticketsCollection,
voiceChannelCollection,
centralizedControlCollection,
nqnCollection,
welcomeCollection,
giveawayCollection,
saveGiveaway,
getGiveaways,
deleteGiveaway,
autoroleCollection,
hentaiCommandCollection,
serverConfigCollection,
reactionRolesCollection,
antisetupCollection,
notificationsCollection,
anticonfigcollection,
afkCollection,
logsCollection,
nicknameConfigs,
usersCollection,
epicDataCollection,
customCommandsCollection,
economyCollection,
birthdayCollection,
applicationCollection,
serverLevelingLogsCollection,
commandLogsCollection,
reportsCollection,
};