Created
August 3, 2022 23:54
-
-
Save paradox-glitch/73f1aa391475d09d6c6b58b5f55b81cc to your computer and use it in GitHub Desktop.
Some automated help for updating from djs 13 to 14
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //* BACK UP YOUR CODE | |
| //* Copyright 2022, Morgan Finney | |
| //* MIT License, http://www.opensource.org/licenses/mit-license.php | |
| //* Limitations | |
| //* - Only one folder can be updated at a time, change the m_Folder variable to choose the folder to target. | |
| //* - Fails if there is a comma , in the title or the body of the field, | |
| //* fields that fail will be commented with v14FLAG above, you can then search and update them manually. | |
| //* - This will create multiple .addFields per embed and will not condense them down to one. | |
| //* Notes | |
| //* This was created quickly for my use case, and works flawlessly, however this may not be the case for all, | |
| //* BACKUP YOUR CODE, this code is licensed as MIT and no liability will be accepted. | |
| const fs = require('fs'); | |
| const m_Folder = `slashCommands` | |
| try { | |
| const l_FoldersFilesNames = fs.readdirSync(`./${m_Folder}`).filter(file => file.endsWith('.js')); | |
| for (const a_FileName of l_FoldersFilesNames) { | |
| var l_FileAsString = fs.readFileSync(`./${m_Folder}/${a_FileName}`, 'utf8'); | |
| const l_AddFieldRegex = /(\.addField)\((?:[^)(]+|\((?:[^)(]+|\([^)(]*\))*\))*\)/ig; | |
| const l_DetectedOldAddFields = l_FileAsString.match(l_AddFieldRegex); | |
| if (l_DetectedOldAddFields) | |
| l_DetectedOldAddFields.forEach(a_DetectedOldAddField => { | |
| var l_Trimmed = a_DetectedOldAddField.substring(10) | |
| l_Trimmed = l_Trimmed.slice(0, -1) | |
| var l_Split = l_Trimmed.split(',') | |
| if (l_Split.length > 3) { | |
| l_Flag = `//* v14FLAG - Unable to automatically update field\n${a_DetectedOldAddField}` | |
| l_FileAsString = l_FileAsString.replace(a_DetectedOldAddField, l_Flag) | |
| } else { | |
| var l_NewAddFields = `.addFields({name: ${l_Split[0].trim()}, value: ${l_Split[1].trim()}${l_Split[2] ? `, inline: ${l_Split[2].trim()}` : `, inline: false`}})` | |
| l_FileAsString = l_FileAsString.replace(a_DetectedOldAddField, l_NewAddFields) | |
| } | |
| }); | |
| fs.writeFile(`./${m_Folder}/${a_FileName}`, l_FileAsString, (err) => { | |
| if (err) { | |
| throw err; | |
| } | |
| }) | |
| }; | |
| console.log(`!!! DONE !!!`) | |
| } catch (err) { | |
| console.error(err); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment