Skip to content

Commit f394ab8

Browse files
committed
Improved update process
The update system is updated to force restart, block event attention, and block configuration updates before migration
1 parent 8921782 commit f394ab8

File tree

6 files changed

+74
-23
lines changed

6 files changed

+74
-23
lines changed

lib/menus/update.js

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ export default async (beforeError, forceUpdate) => {
1616
// Stores the local configuration from the configuration file
1717
let localConfig = require('./config.json');
1818

19-
// Function to show the post-update menu
20-
async function showPostUpdateMenu() {
19+
// Function to show the post-update check menu
20+
async function showPostUpdateCheckMenu() {
2121

2222
// Shows the select menu
2323
global.currentPrompt = select({
@@ -150,14 +150,17 @@ export default async (beforeError, forceUpdate) => {
150150
// Function to update the bot
151151
async function updateBot() {
152152

153+
// Indicates that the bot is not ready to handle events
154+
global.readyStatus = false;
155+
153156
// Cleans the console and shows the logo
154157
process.stdout.write('\u001b[2J\u001b[0;0H');
155158
await splashLogo(client.locale.lib.loaders.splashLogo);
156159

157160
// Shows a message indicating that the bot is downloading the new version
158161
console.log(`⬇️ ${await client.functions.utils.parseLocale(locale.downloadingNewVersion, { targetVersion: `v${latestRemoteTag}`, repositoryURL: packageConfig.repository.url })} ...`);
159162

160-
// Ignores the config.json file --- EXPERIMENTAL
163+
// Ignores the config.json file
161164
await git.raw(['update-index', '--skip-worktree', 'config.json']);
162165

163166
// Makes a pull to update the bot
@@ -166,21 +169,49 @@ export default async (beforeError, forceUpdate) => {
166169
// Makes a checkout to the latest tag
167170
//await git.checkout(latestTag);
168171

169-
// Simulates a loading time --- EXPERIMENTAL
170-
await new Promise(resolve => setTimeout(resolve, 3000));
171-
172-
// Shows a message indicating that the bot is migrating the database and the configuration files
173-
console.log(`🔄 ${locale.migrating} ...`);
174-
175-
// Simulates a loading time --- EXPERIMENTAL
176-
await new Promise(resolve => setTimeout(resolve, 3000));
172+
// Stops ignoring the config.json file
173+
await git.raw(['update-index', '--no-skip-worktree', 'config.json']);
177174

178175
// Cleans the console and shows the logo
179176
process.stdout.write('\u001b[2J\u001b[0;0H');
180177
await splashLogo(client.locale.lib.loaders.splashLogo);
181178

182179
// Shows a message indicating that the bot has been updated
183180
console.log(`🎉 ${await client.functions.utils.parseLocale(locale.updatedCorrectly, { targetVersion: `v${latestRemoteTag}` })}\n`);
181+
182+
// Shows a message indicating that the bot needs to be restarted in order to apply the changes
183+
console.log(`${locale.needsRestart}.\n`);
184+
185+
// Shows the select menu to ask the user if wants to update the bot
186+
global.currentPrompt = select({
187+
188+
message: `${locale.restartConfirmationPrompt.message}:`,
189+
choices: [
190+
{
191+
name: `🔄 ${locale.restartConfirmationPrompt.restartNow}`,
192+
value: 'restart'
193+
}
194+
],
195+
});
196+
197+
// When the user selects an option
198+
global.currentPrompt.then(async (result) => {
199+
200+
// If the user wants to restart now, restarts the bot
201+
if (result === 'restart') process.exit(0);
202+
203+
// When an error occurs
204+
}).catch(async (error) => {
205+
206+
// Runs this menu again, passing the error
207+
await client.functions.menus[menuName](error);
208+
});
209+
210+
// Waits 30 seconds before exiting the process
211+
await new Promise(resolve => setTimeout(resolve, 30000));
212+
213+
// Exits the process
214+
process.exit(0);
184215
};
185216

186217
// Shows a message indicating that there are new updates
@@ -323,8 +354,8 @@ export default async (beforeError, forceUpdate) => {
323354
console.log(`✅ ${locale.alreadyUpdated}: v${latestLocalTag}\n`);
324355
};
325356

326-
// Shows the post-update menu
327-
await showPostUpdateMenu();
357+
// Shows the post-update check menu
358+
await showPostUpdateCheckMenu();
328359

329360
} catch (error) {
330361

locales/en-US.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,7 +1356,7 @@
13561356
},
13571357
"errorMessage": "An unexpected error ocurred. Check the logs for more details",
13581358
"checkingForUpdates": "Checking if there are new updates",
1359-
"updatedCorrectly": "The bot has been correctly updated to {{targetVersion}}",
1359+
"updatedCorrectly": "The bot has been correctly updated to {{targetVersion}}!",
13601360
"noReleaseNotes": "There are no release notes available for this version",
13611361
"newVersionAvailable": "Version {{targetVersion}} is available!",
13621362
"releaseNotes": "Release notes",
@@ -1368,7 +1368,11 @@
13681368
},
13691369
"alreadyUpdated": "The bot is already updated to the latest version",
13701370
"downloadingNewVersion": "Downloading {{targetVersion}} from {{repositoryURL}}",
1371-
"migrating": "Migrating the databases and the configuration files"
1371+
"needsRestart": "The bot must be restarted to apply the changes.\nIf you don't do it now, the process will automatically abort after 30 seconds.\nIf you are using a process manager like PM2 or Docker, the bot will automatically start again.\nOtherwise, you will have to restart it manually",
1372+
"restartConfirmationPrompt": {
1373+
"message": "Would you like to restart now?",
1374+
"restartNow": "Restart now"
1375+
}
13721376
},
13731377
"main": {
13741378
"promptMessage": "Select an option",

locales/es-ES.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1339,7 +1339,7 @@
13391339
},
13401340
"errorMessage": "An unexpected error ocurred. Check the logs for more details",
13411341
"checkingForUpdates": "Checking if there are new updates",
1342-
"updatedCorrectly": "The bot has been correctly updated to {{targetVersion}}",
1342+
"updatedCorrectly": "The bot has been correctly updated to {{targetVersion}}!",
13431343
"noReleaseNotes": "There are no release notes available for this version",
13441344
"newVersionAvailable": "Version {{targetVersion}} is available!",
13451345
"releaseNotes": "Release notes",
@@ -1351,7 +1351,11 @@
13511351
},
13521352
"alreadyUpdated": "The bot is already updated to the latest version",
13531353
"downloadingNewVersion": "Downloading {{targetVersion}} from {{repositoryURL}}",
1354-
"migrating": "Migrating the databases and the configuration files"
1354+
"needsRestart": "The bot must be restarted to apply the changes.\nIf you don't do it now, the process will automatically abort after 30 seconds.\nIf you are using a process manager like PM2 or Docker, the bot will automatically start again.\nOtherwise, you will have to restart it manually",
1355+
"restartConfirmationPrompt": {
1356+
"message": "Would you like to restart now?",
1357+
"restartNow": "Restart now"
1358+
}
13551359
},
13561360
"main": {
13571361
"promptMessage": "Select an option",

locales/it.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,7 +1340,7 @@
13401340
},
13411341
"errorMessage": "An unexpected error ocurred. Check the logs for more details",
13421342
"checkingForUpdates": "Checking if there are new updates",
1343-
"updatedCorrectly": "The bot has been correctly updated to {{targetVersion}}",
1343+
"updatedCorrectly": "The bot has been correctly updated to {{targetVersion}}!",
13441344
"noReleaseNotes": "There are no release notes available for this version",
13451345
"newVersionAvailable": "Version {{targetVersion}} is available!",
13461346
"releaseNotes": "Release notes",
@@ -1352,7 +1352,11 @@
13521352
},
13531353
"alreadyUpdated": "The bot is already updated to the latest version",
13541354
"downloadingNewVersion": "Downloading {{targetVersion}} from {{repositoryURL}}",
1355-
"migrating": "Migrating the databases and the configuration files"
1355+
"needsRestart": "The bot must be restarted to apply the changes.\nIf you don't do it now, the process will automatically abort after 30 seconds.\nIf you are using a process manager like PM2 or Docker, the bot will automatically start again.\nOtherwise, you will have to restart it manually",
1356+
"restartConfirmationPrompt": {
1357+
"message": "Would you like to restart now?",
1358+
"restartNow": "Restart now"
1359+
}
13561360
},
13571361
"main": {
13581362
"promptMessage": "Select an option",

locales/ro.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,7 +1340,7 @@
13401340
},
13411341
"errorMessage": "An unexpected error ocurred. Check the logs for more details",
13421342
"checkingForUpdates": "Checking if there are new updates",
1343-
"updatedCorrectly": "The bot has been correctly updated to {{targetVersion}}",
1343+
"updatedCorrectly": "The bot has been correctly updated to {{targetVersion}}!",
13441344
"noReleaseNotes": "There are no release notes available for this version",
13451345
"newVersionAvailable": "Version {{targetVersion}} is available!",
13461346
"releaseNotes": "Release notes",
@@ -1352,7 +1352,11 @@
13521352
},
13531353
"alreadyUpdated": "The bot is already updated to the latest version",
13541354
"downloadingNewVersion": "Downloading {{targetVersion}} from {{repositoryURL}}",
1355-
"migrating": "Migrating the databases and the configuration files"
1355+
"needsRestart": "The bot must be restarted to apply the changes.\nIf you don't do it now, the process will automatically abort after 30 seconds.\nIf you are using a process manager like PM2 or Docker, the bot will automatically start again.\nOtherwise, you will have to restart it manually",
1356+
"restartConfirmationPrompt": {
1357+
"message": "Would you like to restart now?",
1358+
"restartNow": "Restart now"
1359+
}
13561360
},
13571361
"main": {
13581362
"promptMessage": "Select an option",

locales/zh-CN.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,7 +1340,7 @@
13401340
},
13411341
"errorMessage": "An unexpected error ocurred. Check the logs for more details",
13421342
"checkingForUpdates": "Checking if there are new updates",
1343-
"updatedCorrectly": "The bot has been correctly updated to {{targetVersion}}",
1343+
"updatedCorrectly": "The bot has been correctly updated to {{targetVersion}}!",
13441344
"noReleaseNotes": "There are no release notes available for this version",
13451345
"newVersionAvailable": "Version {{targetVersion}} is available!",
13461346
"releaseNotes": "Release notes",
@@ -1352,7 +1352,11 @@
13521352
},
13531353
"alreadyUpdated": "The bot is already updated to the latest version",
13541354
"downloadingNewVersion": "Downloading {{targetVersion}} from {{repositoryURL}}",
1355-
"migrating": "Migrating the databases and the configuration files"
1355+
"needsRestart": "The bot must be restarted to apply the changes.\nIf you don't do it now, the process will automatically abort after 30 seconds.\nIf you are using a process manager like PM2 or Docker, the bot will automatically start again.\nOtherwise, you will have to restart it manually",
1356+
"restartConfirmationPrompt": {
1357+
"message": "Would you like to restart now?",
1358+
"restartNow": "Restart now"
1359+
}
13561360
},
13571361
"main": {
13581362
"promptMessage": "Select an option",

0 commit comments

Comments
 (0)