blob: a9132f86ed3509194a9b3f760213f16188e31af6 [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,
51 channels: data.invite
52 ? data.invite.whitelist.channels.map((channel) =>
53 channel.toString()
54 )
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 Grey75ea9172022-08-06 10:22:23 +010069 role: data.welcome
70 ? data.welcome.role !== null
71 ? data.welcome.role.toString()
72 : null
73 : null,
74 channel: data.welcome
75 ? data.welcome.message.text !== null
76 ? data.welcome.message.channel.toString()
77 : null
78 : null,
79 message: data.welcome ? data.welcome.message.text : null
pineafan6fb3e072022-05-20 19:27:23 +010080 },
Skyler Grey75ea9172022-08-06 10:22:23 +010081 stats: {},
82 logging: {
83 logs: {
84 enabled: true,
85 channel: data.log_info.log_channel
86 ? data.log_info.log_channel.toString()
87 : null,
88 toLog: "3fffff"
pineafan6fb3e072022-05-20 19:27:23 +010089 },
Skyler Grey75ea9172022-08-06 10:22:23 +010090 staff: {
91 channel: data.log_info.staff
92 ? data.log_info.staff.toString()
93 : null
pineafan6fb3e072022-05-20 19:27:23 +010094 }
95 },
Skyler Grey75ea9172022-08-06 10:22:23 +010096 verify: {
97 enabled: data.verify_role !== null,
98 role: data.verify_role ? data.verify_role.toString() : null
pineafan6fb3e072022-05-20 19:27:23 +010099 },
Skyler Grey75ea9172022-08-06 10:22:23 +0100100 tickets: {
101 enabled: data.modmail ? data.modmail.cat !== null : null,
102 category: data.modmail
103 ? data.modmail.cat !== null
104 ? data.modmail.cat.toString()
105 : null
106 : null,
107 types: "3f",
108 customTypes: null,
109 supportRole: data.modmail
110 ? data.modmail.mention !== null
111 ? data.modmail.mention.toString()
112 : null
113 : null,
114 maxTickets: data.modmail ? data.modmail.max : 5
pineafan6fb3e072022-05-20 19:27:23 +0100115 },
Skyler Grey75ea9172022-08-06 10:22:23 +0100116 moderation: {
117 mute: {
118 timeout: true,
119 role: null,
120 text: null,
121 link: null
pineafan6fb3e072022-05-20 19:27:23 +0100122 },
Skyler Grey75ea9172022-08-06 10:22:23 +0100123 kick: {
124 text: null,
125 link: null
pineafan6fb3e072022-05-20 19:27:23 +0100126 },
Skyler Grey75ea9172022-08-06 10:22:23 +0100127 ban: {
128 text: null,
129 link: null
pineafan6fb3e072022-05-20 19:27:23 +0100130 },
Skyler Grey75ea9172022-08-06 10:22:23 +0100131 softban: {
132 text: null,
133 link: null
pineafan6fb3e072022-05-20 19:27:23 +0100134 },
Skyler Grey75ea9172022-08-06 10:22:23 +0100135 warn: {
136 text: null,
137 link: null
pineafan6fb3e072022-05-20 19:27:23 +0100138 },
Skyler Grey75ea9172022-08-06 10:22:23 +0100139 role: {
140 role: null
pineafan6fb3e072022-05-20 19:27:23 +0100141 }
142 },
Skyler Grey75ea9172022-08-06 10:22:23 +0100143 tracks: [],
144 roleMenu: [],
145 tags: data.tags
pineafan63fc5e22022-08-04 22:04:10 +0100146 };
pineafan6fb3e072022-05-20 19:27:23 +0100147 // Insert the new data into the database
Skyler Grey75ea9172022-08-06 10:22:23 +0100148 await collection.updateOne(
149 { id: data.guild_info.id.toString() },
150 { $set: newData },
151 { upsert: true }
152 );
pineafan6fb3e072022-05-20 19:27:23 +0100153 // Delete the old file
154 fs.unlinkSync(`./oldData/${file}`);
155 console.log(`└ Successfully migrated file ${file}`);
156 x++;
157}
158
pineafan6fb3e072022-05-20 19:27:23 +0100159// console.log((await collection.findOne({ id: "your mother" })));