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