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, |
| 51 | channels: data.invite |
| 52 | ? data.invite.whitelist.channels.map((channel) => |
| 53 | channel.toString() |
| 54 | ) |
| 55 | : [] |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 56 | }, |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 57 | pings: { |
| 58 | mass: 5, |
| 59 | everyone: true, |
| 60 | roles: true |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 61 | } |
| 62 | }, |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 63 | welcome: { |
| 64 | enabled: data.welcome ? data.welcome.message.text !== null : false, |
| 65 | verificationRequired: { |
| 66 | message: null, |
| 67 | role: null |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 68 | }, |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 69 | 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 |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 80 | }, |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 81 | 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" |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 89 | }, |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 90 | staff: { |
| 91 | channel: data.log_info.staff |
| 92 | ? data.log_info.staff.toString() |
| 93 | : null |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 94 | } |
| 95 | }, |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 96 | verify: { |
| 97 | enabled: data.verify_role !== null, |
| 98 | role: data.verify_role ? data.verify_role.toString() : null |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 99 | }, |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 100 | 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 |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 115 | }, |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 116 | moderation: { |
| 117 | mute: { |
| 118 | timeout: true, |
| 119 | role: null, |
| 120 | text: null, |
| 121 | link: null |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 122 | }, |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 123 | kick: { |
| 124 | text: null, |
| 125 | link: null |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 126 | }, |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 127 | ban: { |
| 128 | text: null, |
| 129 | link: null |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 130 | }, |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 131 | softban: { |
| 132 | text: null, |
| 133 | link: null |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 134 | }, |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 135 | warn: { |
| 136 | text: null, |
| 137 | link: null |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 138 | }, |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 139 | role: { |
| 140 | role: null |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 141 | } |
| 142 | }, |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 143 | tracks: [], |
| 144 | roleMenu: [], |
| 145 | tags: data.tags |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 146 | }; |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 147 | // Insert the new data into the database |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 148 | await collection.updateOne( |
| 149 | { id: data.guild_info.id.toString() }, |
| 150 | { $set: newData }, |
| 151 | { upsert: true } |
| 152 | ); |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 153 | // Delete the old file |
| 154 | fs.unlinkSync(`./oldData/${file}`); |
| 155 | console.log(`└ Successfully migrated file ${file}`); |
| 156 | x++; |
| 157 | } |
| 158 | |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 159 | // console.log((await collection.findOne({ id: "your mother" }))); |