forked from GlaceYT/ALL-IN-ONE-BOT
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmongodb.js
More file actions
165 lines (141 loc) · 5.36 KB
/
mongodb.js
File metadata and controls
165 lines (141 loc) · 5.36 KB
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
// Update in mongodb.js
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);
const mongoose = require('mongoose');
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');
await mongoose.connect(uri);
console.log('\x1b[36m[ MONGOOSE ]\x1b[0m', '\x1b[32mConnected using Mongoose ✅\x1b[0m');
await initCollections();
} catch (err) {
console.error("❌ Error connecting to MongoDB or Mongoose", err);
}
}
async function initCollections() {
giveawayCollection = db.collection('giveaways');
try {
await giveawayCollection.createIndex({ messageId: 1 }, { unique: true });
console.log('\x1b[36m[ COLLECTION ]\x1b[0m', '\x1b[32mGiveaway collection initialized ✅\x1b[0m');
} catch (err) {
console.error("❌ Error initializing giveaway collection", err);
}
}
const db = client.db("discord-bot");
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 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');
const stickyMessageCollection = db.collection('stickymessages');
const serverStatsCollection = db.collection('serverStats');
const autoResponderCollection = db.collection('autoResponder');
const playlistCollection = db.collection('lavalinkplaylist');
const autoplayCollection = db.collection('autoplaylavalink');
const embedCollection = db.collection('aioembeds');
const countingCollection = db.collection('countingame');
const botStatusCollection = db.collection('bot_status');
const scheduleCollection = db.collection('scheduleCollections')
const gameAccountsCollection = db.collection('gameAccounts');
let giveawayCollection;
async function saveGiveaway(giveaway) {
if (!giveawayCollection) {
console.error("Giveaway collection not initialized!");
return;
}
await giveawayCollection.updateOne(
{ messageId: giveaway.messageId },
{ $set: giveaway },
{ upsert: true }
);
}
async function getGiveaways() {
if (!giveawayCollection) {
console.error("Giveaway collection not initialized!");
return [];
}
return await giveawayCollection.find().toArray();
}
async function getGiveawayById(messageId) {
if (!giveawayCollection) {
console.error("Giveaway collection not initialized!");
return null;
}
return await giveawayCollection.findOne({ messageId });
}
async function deleteGiveaway(messageId) {
if (!giveawayCollection) {
console.error("Giveaway collection not initialized!");
return;
}
await giveawayCollection.deleteOne({ messageId });
}
module.exports = {
connectToDatabase,
voiceChannelCollection,
centralizedControlCollection,
nqnCollection,
welcomeCollection,
giveawayCollections: db.collection('giveaways'),
saveGiveaway,
getGiveaways,
getGiveawayById,
deleteGiveaway,
autoroleCollection,
hentaiCommandCollection,
serverConfigCollection,
reactionRolesCollection,
antisetupCollection,
notificationsCollection,
anticonfigcollection,
afkCollection,
logsCollection,
nicknameConfigs,
usersCollection,
epicDataCollection,
customCommandsCollection,
economyCollection,
birthdayCollection,
applicationCollection,
serverLevelingLogsCollection,
commandLogsCollection,
reportsCollection,
stickyMessageCollection,
serverStatsCollection,
autoResponderCollection,
playlistCollection,
autoplayCollection,
embedCollection,
countingCollection,
botStatusCollection,
scheduleCollection,
gameAccountsCollection,
};