blob: 34fc2c5bddf71a81d2d7b6c461f0540bc0e8032c [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,
PineaFan538d3752023-01-12 21:48:23 +000051 allowed: {
52 channels: data.invite ? data.invite.whitelist.channels.map((channel) => channel.toString()) : [],
53 users: [],
54 roles: []
55 }
pineafan6fb3e072022-05-20 19:27:23 +010056 },
Skyler Grey75ea9172022-08-06 10:22:23 +010057 pings: {
58 mass: 5,
59 everyone: true,
60 roles: true
pineafan6fb3e072022-05-20 19:27:23 +010061 }
62 },
Skyler Grey75ea9172022-08-06 10:22:23 +010063 welcome: {
64 enabled: data.welcome ? data.welcome.message.text !== null : false,
65 verificationRequired: {
66 message: null,
67 role: null
pineafan6fb3e072022-05-20 19:27:23 +010068 },
Skyler Grey11236ba2022-08-08 21:13:33 +010069 role: data.welcome ? (data.welcome.role !== null ? data.welcome.role.toString() : null) : null,
Skyler Grey75ea9172022-08-06 10:22:23 +010070 channel: data.welcome
71 ? data.welcome.message.text !== null
72 ? data.welcome.message.channel.toString()
73 : null
74 : null,
75 message: data.welcome ? data.welcome.message.text : null
pineafan6fb3e072022-05-20 19:27:23 +010076 },
Skyler Grey75ea9172022-08-06 10:22:23 +010077 stats: {},
78 logging: {
79 logs: {
80 enabled: true,
Skyler Grey11236ba2022-08-08 21:13:33 +010081 channel: data.log_info.log_channel ? data.log_info.log_channel.toString() : null,
Skyler Grey75ea9172022-08-06 10:22:23 +010082 toLog: "3fffff"
pineafan6fb3e072022-05-20 19:27:23 +010083 },
Skyler Grey75ea9172022-08-06 10:22:23 +010084 staff: {
Skyler Grey11236ba2022-08-08 21:13:33 +010085 channel: data.log_info.staff ? data.log_info.staff.toString() : null
pineafan6fb3e072022-05-20 19:27:23 +010086 }
87 },
Skyler Grey75ea9172022-08-06 10:22:23 +010088 verify: {
89 enabled: data.verify_role !== null,
90 role: data.verify_role ? data.verify_role.toString() : null
pineafan6fb3e072022-05-20 19:27:23 +010091 },
Skyler Grey75ea9172022-08-06 10:22:23 +010092 tickets: {
93 enabled: data.modmail ? data.modmail.cat !== null : null,
Skyler Grey11236ba2022-08-08 21:13:33 +010094 category: data.modmail ? (data.modmail.cat !== null ? data.modmail.cat.toString() : null) : null,
Skyler Grey75ea9172022-08-06 10:22:23 +010095 types: "3f",
96 customTypes: null,
Skyler Grey11236ba2022-08-08 21:13:33 +010097 supportRole: data.modmail ? (data.modmail.mention !== null ? data.modmail.mention.toString() : null) : null,
Skyler Grey75ea9172022-08-06 10:22:23 +010098 maxTickets: data.modmail ? data.modmail.max : 5
pineafan6fb3e072022-05-20 19:27:23 +010099 },
Skyler Grey75ea9172022-08-06 10:22:23 +0100100 moderation: {
101 mute: {
102 timeout: true,
103 role: null,
104 text: null,
105 link: null
pineafan6fb3e072022-05-20 19:27:23 +0100106 },
Skyler Grey75ea9172022-08-06 10:22:23 +0100107 kick: {
108 text: null,
109 link: null
pineafan6fb3e072022-05-20 19:27:23 +0100110 },
Skyler Grey75ea9172022-08-06 10:22:23 +0100111 ban: {
112 text: null,
113 link: null
pineafan6fb3e072022-05-20 19:27:23 +0100114 },
Skyler Grey75ea9172022-08-06 10:22:23 +0100115 softban: {
116 text: null,
117 link: null
pineafan6fb3e072022-05-20 19:27:23 +0100118 },
Skyler Grey75ea9172022-08-06 10:22:23 +0100119 warn: {
120 text: null,
121 link: null
pineafan6fb3e072022-05-20 19:27:23 +0100122 },
Skyler Grey75ea9172022-08-06 10:22:23 +0100123 role: {
124 role: null
pineafan6fb3e072022-05-20 19:27:23 +0100125 }
126 },
Skyler Grey75ea9172022-08-06 10:22:23 +0100127 tracks: [],
128 roleMenu: [],
129 tags: data.tags
pineafan63fc5e22022-08-04 22:04:10 +0100130 };
pineafan6fb3e072022-05-20 19:27:23 +0100131 // Insert the new data into the database
Skyler Grey11236ba2022-08-08 21:13:33 +0100132 await collection.updateOne({ id: data.guild_info.id.toString() }, { $set: newData }, { upsert: true });
pineafan6fb3e072022-05-20 19:27:23 +0100133 // Delete the old file
134 fs.unlinkSync(`./oldData/${file}`);
135 console.log(`└ Successfully migrated file ${file}`);
136 x++;
137}
138
pineafan6fb3e072022-05-20 19:27:23 +0100139// console.log((await collection.findOne({ id: "your mother" })));