blob: e5b302c97ea973962236704876dc0cf42e84c3b3 [file] [log] [blame]
pineafan63fc5e22022-08-04 22:04:10 +01001import fs from "fs";
2import { MongoClient } from "mongodb";
pineafan6fb3e072022-05-20 19:27:23 +01003
pineafan63fc5e22022-08-04 22:04:10 +01004const mongoClient = new MongoClient("mongodb://127.0.0.1:27017/local");
5await mongoClient.connect();
pineafan6fb3e072022-05-20 19:27:23 +01006const database = mongoClient.db("Nucleus");
7const collection = database.collection("migrationTesting");
8
9// Loop through all files in the oldData folder
pineafan63fc5e22022-08-04 22:04:10 +010010const files = fs.readdirSync("./oldData");
11let x = 0;
pineafan6fb3e072022-05-20 19:27:23 +010012for (const file of files) {
13 console.log(`┌ Processing file ${x} of ${files.length - 1} | ${file}`);
14 // Read the file as a json
pineafan63fc5e22022-08-04 22:04:10 +010015 let data;
pineafan6fb3e072022-05-20 19:27:23 +010016 try {
17 data = JSON.parse(fs.readFileSync(`./oldData/${file}`));
18 } catch {
19 console.log(`└ Error reading file ${file}`);
pineafan63fc5e22022-08-04 22:04:10 +010020 x++;
pineafan6fb3e072022-05-20 19:27:23 +010021 continue;
22 }
23 // Check if data version is 3
24 if (data.version !== 3) {
25 console.log(`├ Version was too old on ${file}`);
pineafan63fc5e22022-08-04 22:04:10 +010026 console.log("└ Skipping file");
pineafan6fb3e072022-05-20 19:27:23 +010027 x++;
pineafan63fc5e22022-08-04 22:04:10 +010028 continue;
pineafan6fb3e072022-05-20 19:27:23 +010029 }
30 // Convert to the new format
31 const newData = {
Skyler Grey75ea9172022-08-06 10:22:23 +010032 id: data.guild_info.id.toString(),
33 version: 1,
34 singleEventNotifications: {
35 statsChannelDeleted: false
pineafan6fb3e072022-05-20 19:27:23 +010036 },
Skyler Grey75ea9172022-08-06 10:22:23 +010037 filters: {
38 images: {
39 NSFW: !data.images.nsfw,
40 size: data.images.toosmall
pineafan6fb3e072022-05-20 19:27:23 +010041 },
Skyler Grey75ea9172022-08-06 10:22:23 +010042 wordFilter: {
43 enabled: true,
44 words: {
45 strict: data.wordfilter.strict,
46 loose: data.wordfilter.soft
pineafan63fc5e22022-08-04 22:04:10 +010047 }
pineafan6fb3e072022-05-20 19:27:23 +010048 },
Skyler Grey75ea9172022-08-06 10:22:23 +010049 invite: {
50 enabled: data.invite ? data.invite.enabled : false,
Skyler Grey11236ba2022-08-08 21:13:33 +010051 channels: data.invite ? data.invite.whitelist.channels.map((channel) => channel.toString()) : []
pineafan6fb3e072022-05-20 19:27:23 +010052 },
Skyler Grey75ea9172022-08-06 10:22:23 +010053 pings: {
54 mass: 5,
55 everyone: true,
56 roles: true
pineafan6fb3e072022-05-20 19:27:23 +010057 }
58 },
Skyler Grey75ea9172022-08-06 10:22:23 +010059 welcome: {
60 enabled: data.welcome ? data.welcome.message.text !== null : false,
61 verificationRequired: {
62 message: null,
63 role: null
pineafan6fb3e072022-05-20 19:27:23 +010064 },
Skyler Grey11236ba2022-08-08 21:13:33 +010065 role: data.welcome ? (data.welcome.role !== null ? data.welcome.role.toString() : null) : null,
Skyler Grey75ea9172022-08-06 10:22:23 +010066 channel: data.welcome
67 ? data.welcome.message.text !== null
68 ? data.welcome.message.channel.toString()
69 : null
70 : null,
71 message: data.welcome ? data.welcome.message.text : null
pineafan6fb3e072022-05-20 19:27:23 +010072 },
Skyler Grey75ea9172022-08-06 10:22:23 +010073 stats: {},
74 logging: {
75 logs: {
76 enabled: true,
Skyler Grey11236ba2022-08-08 21:13:33 +010077 channel: data.log_info.log_channel ? data.log_info.log_channel.toString() : null,
Skyler Grey75ea9172022-08-06 10:22:23 +010078 toLog: "3fffff"
pineafan6fb3e072022-05-20 19:27:23 +010079 },
Skyler Grey75ea9172022-08-06 10:22:23 +010080 staff: {
Skyler Grey11236ba2022-08-08 21:13:33 +010081 channel: data.log_info.staff ? data.log_info.staff.toString() : null
pineafan6fb3e072022-05-20 19:27:23 +010082 }
83 },
Skyler Grey75ea9172022-08-06 10:22:23 +010084 verify: {
85 enabled: data.verify_role !== null,
86 role: data.verify_role ? data.verify_role.toString() : null
pineafan6fb3e072022-05-20 19:27:23 +010087 },
Skyler Grey75ea9172022-08-06 10:22:23 +010088 tickets: {
89 enabled: data.modmail ? data.modmail.cat !== null : null,
Skyler Grey11236ba2022-08-08 21:13:33 +010090 category: data.modmail ? (data.modmail.cat !== null ? data.modmail.cat.toString() : null) : null,
Skyler Grey75ea9172022-08-06 10:22:23 +010091 types: "3f",
92 customTypes: null,
Skyler Grey11236ba2022-08-08 21:13:33 +010093 supportRole: data.modmail ? (data.modmail.mention !== null ? data.modmail.mention.toString() : null) : null,
Skyler Grey75ea9172022-08-06 10:22:23 +010094 maxTickets: data.modmail ? data.modmail.max : 5
pineafan6fb3e072022-05-20 19:27:23 +010095 },
Skyler Grey75ea9172022-08-06 10:22:23 +010096 moderation: {
97 mute: {
98 timeout: true,
99 role: null,
100 text: null,
101 link: null
pineafan6fb3e072022-05-20 19:27:23 +0100102 },
Skyler Grey75ea9172022-08-06 10:22:23 +0100103 kick: {
104 text: null,
105 link: null
pineafan6fb3e072022-05-20 19:27:23 +0100106 },
Skyler Grey75ea9172022-08-06 10:22:23 +0100107 ban: {
108 text: null,
109 link: null
pineafan6fb3e072022-05-20 19:27:23 +0100110 },
Skyler Grey75ea9172022-08-06 10:22:23 +0100111 softban: {
112 text: null,
113 link: null
pineafan6fb3e072022-05-20 19:27:23 +0100114 },
Skyler Grey75ea9172022-08-06 10:22:23 +0100115 warn: {
116 text: null,
117 link: null
pineafan6fb3e072022-05-20 19:27:23 +0100118 },
Skyler Grey75ea9172022-08-06 10:22:23 +0100119 role: {
120 role: null
pineafan6fb3e072022-05-20 19:27:23 +0100121 }
122 },
Skyler Grey75ea9172022-08-06 10:22:23 +0100123 tracks: [],
124 roleMenu: [],
125 tags: data.tags
pineafan63fc5e22022-08-04 22:04:10 +0100126 };
pineafan6fb3e072022-05-20 19:27:23 +0100127 // Insert the new data into the database
Skyler Grey11236ba2022-08-08 21:13:33 +0100128 await collection.updateOne({ id: data.guild_info.id.toString() }, { $set: newData }, { upsert: true });
pineafan6fb3e072022-05-20 19:27:23 +0100129 // Delete the old file
130 fs.unlinkSync(`./oldData/${file}`);
131 console.log(`└ Successfully migrated file ${file}`);
132 x++;
133}
134
pineafan6fb3e072022-05-20 19:27:23 +0100135// console.log((await collection.findOne({ id: "your mother" })));