blob: ca6e63d97c2b6ad086e7252c0f7ce2152f668366 [file] [log] [blame]
pineafan6fb3e072022-05-20 19:27:23 +01001import fs from 'fs';
2import { MongoClient } from 'mongodb';
3
4const mongoClient = new MongoClient('mongodb://127.0.0.1:27017/local');
5await mongoClient.connect()
6const database = mongoClient.db("Nucleus");
7const collection = database.collection("migrationTesting");
8
9// Loop through all files in the oldData folder
10const files = fs.readdirSync('./oldData');
11let x = 0
12for (const file of files) {
13 console.log(`┌ Processing file ${x} of ${files.length - 1} | ${file}`);
14 // Read the file as a json
15 let data
16 try {
17 data = JSON.parse(fs.readFileSync(`./oldData/${file}`));
18 } catch {
19 console.log(`└ Error reading file ${file}`);
20 x++
21 continue;
22 }
23 // Check if data version is 3
24 if (data.version !== 3) {
25 console.log(`├ Version was too old on ${file}`);
26 console.log(`└ Skipping file`);
27 x++;
28 continue
29 }
30 // Convert to the new format
31 const newData = {
32 "id": data.guild_info.id.toString(),
33 "version": 1,
34 "singleEventNotifications": {
35 "statsChannelDeleted": false
36 },
37 "filters": {
38 "images": {
39 "NSFW": !data.images.nsfw,
40 "size": data.images.toosmall
41 },
42 "wordFilter": {
43 "enabled": true,
44 "words": {
45 "strict": data.wordfilter.strict,
46 "loose": data.wordfilter.soft
47 },
pineafan6fb3e072022-05-20 19:27:23 +010048 },
49 "invite": {
50 "enabled": data.invite ? data.invite.enabled : false,
pineafane23c4ec2022-07-27 21:56:27 +010051 "channels": data.invite ? data.invite.whitelist.channels.map(channel => channel.toString()) : [],
pineafan6fb3e072022-05-20 19:27:23 +010052 },
53 "pings": {
54 "mass": 5,
55 "everyone": true,
pineafane23c4ec2022-07-27 21:56:27 +010056 "roles": true
pineafan6fb3e072022-05-20 19:27:23 +010057 }
58 },
59 "welcome": {
60 "enabled": data.welcome ? (data.welcome.message.text !== null) : false,
61 "verificationRequired": {
62 "message": null,
63 "role": null,
64 },
65 "welcomeRole": data.welcome ? (data.welcome.role !== null ? data.welcome.role.toString() : null) : null,
66 "channel": data.welcome ? (data.welcome.message.text !== null ? data.welcome.message.channel.toString() : null) : null,
67 "message": data.welcome ? (data.welcome.message.text) : null
68 },
pineafane23c4ec2022-07-27 21:56:27 +010069 "stats": {},
pineafan6fb3e072022-05-20 19:27:23 +010070 "logging": {
71 "logs": {
72 "enabled": true,
73 "channel": data.log_info.log_channel ? data.log_info.log_channel.toString() : null,
74 "toLog": "3fffff"
75 },
76 "staff": {
77 "channel": data.log_info.staff ? data.log_info.staff.toString() : null,
78 }
79 },
80 "verify": {
81 "enabled": data.verify_role !== null,
82 "role": data.verify_role ? data.verify_role.toString() : null,
83 },
84 "tickets": {
85 "enabled": data.modmail ? (data.modmail.cat !== null) : null,
86 "category": data.modmail ? (data.modmail.cat !== null ? data.modmail.cat.toString() : null) : null,
87 "types": "3f",
88 "customTypes": null,
89 "supportRole": data.modmail ? (data.modmail.mention !== null ? data.modmail.mention.toString() : null) : null,
90 "maxTickets": data.modmail ? (data.modmail.max) : 5
91 },
92 "moderation": {
93 "mute": {
94 "timeout": true,
95 "role": null,
96 "text": null,
97 "link": null
98 },
99 "kick": {
100 "text": null,
101 "link": null
102 },
103 "ban": {
104 "text": null,
105 "link": null
106 },
107 "softban": {
108 "text": null,
109 "link": null
110 },
111 "warn": {
112 "text": null,
113 "link": null
114 },
115 "role": {
116 "role": null
117 }
118 },
119 "tracks": [],
120 "roleMenu": [],
121 "tags": data.tags
122 }
123 // Insert the new data into the database
124 await collection.updateOne({ id: data.guild_info.id.toString() }, { $set: newData }, { upsert: true });
125 // Delete the old file
126 fs.unlinkSync(`./oldData/${file}`);
127 console.log(`└ Successfully migrated file ${file}`);
128 x++;
129}
130
131
132// console.log((await collection.findOne({ id: "your mother" })));