blob: 3c70cc20f21c38382352cd4b5439892a7d599034 [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 },
48 "allowed": {
49 "users": data.wordfilter.ignore.members.map(user => user.toString()),
50 "roles": data.wordfilter.ignore.roles.map(role => role.toString()),
51 "channels": data.wordfilter.ignore.channels.map(channel => channel.toString())
52 }
53 },
54 "invite": {
55 "enabled": data.invite ? data.invite.enabled : false,
56 "allowed": {
57 "users": data.invite ? data.invite.whitelist.members.map(user => user.toString()) : [],
58 "channels": data.invite ? data.invite.whitelist.channels.map(channel => channel.toString()) : [],
59 "roles": data.invite ? data.invite.whitelist.roles.map(role => role.toString()) : []
60 }
61 },
62 "pings": {
63 "mass": 5,
64 "everyone": true,
65 "roles": true,
66 "allowed": {
67 "roles": [],
68 "rolesToMention": null,
69 "users": null,
70 "channels": null
71 }
72 }
73 },
74 "welcome": {
75 "enabled": data.welcome ? (data.welcome.message.text !== null) : false,
76 "verificationRequired": {
77 "message": null,
78 "role": null,
79 },
80 "welcomeRole": data.welcome ? (data.welcome.role !== null ? data.welcome.role.toString() : null) : null,
81 "channel": data.welcome ? (data.welcome.message.text !== null ? data.welcome.message.channel.toString() : null) : null,
82 "message": data.welcome ? (data.welcome.message.text) : null
83 },
84 "stats": [],
85 "logging": {
86 "logs": {
87 "enabled": true,
88 "channel": data.log_info.log_channel ? data.log_info.log_channel.toString() : null,
89 "toLog": "3fffff"
90 },
91 "staff": {
92 "channel": data.log_info.staff ? data.log_info.staff.toString() : null,
93 }
94 },
95 "verify": {
96 "enabled": data.verify_role !== null,
97 "role": data.verify_role ? data.verify_role.toString() : null,
98 },
99 "tickets": {
100 "enabled": data.modmail ? (data.modmail.cat !== null) : null,
101 "category": data.modmail ? (data.modmail.cat !== null ? data.modmail.cat.toString() : null) : null,
102 "types": "3f",
103 "customTypes": null,
104 "supportRole": data.modmail ? (data.modmail.mention !== null ? data.modmail.mention.toString() : null) : null,
105 "maxTickets": data.modmail ? (data.modmail.max) : 5
106 },
107 "moderation": {
108 "mute": {
109 "timeout": true,
110 "role": null,
111 "text": null,
112 "link": null
113 },
114 "kick": {
115 "text": null,
116 "link": null
117 },
118 "ban": {
119 "text": null,
120 "link": null
121 },
122 "softban": {
123 "text": null,
124 "link": null
125 },
126 "warn": {
127 "text": null,
128 "link": null
129 },
130 "role": {
131 "role": null
132 }
133 },
134 "tracks": [],
135 "roleMenu": [],
136 "tags": data.tags
137 }
138 // Insert the new data into the database
139 await collection.updateOne({ id: data.guild_info.id.toString() }, { $set: newData }, { upsert: true });
140 // Delete the old file
141 fs.unlinkSync(`./oldData/${file}`);
142 console.log(`└ Successfully migrated file ${file}`);
143 x++;
144}
145
146
147// console.log((await collection.findOne({ id: "your mother" })));