mirror of
https://github.com/cloudmaker97/FS25-Discord-Bot.git
synced 2025-12-06 08:28:33 +00:00
Restart the bot if an error occurs in the discord service; added Dockerfile
This commit is contained in:
parent
6b6b422f3d
commit
8434a32c34
3 changed files with 29 additions and 2 deletions
11
Dockerfile
Normal file
11
Dockerfile
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
FROM node:latest
|
||||||
|
LABEL name="LS25-Discord-Bot"
|
||||||
|
LABEL authors="Dennis Heinrich"
|
||||||
|
|
||||||
|
# Copy the source files
|
||||||
|
WORKDIR /app
|
||||||
|
COPY . /app
|
||||||
|
RUN npm install
|
||||||
|
|
||||||
|
CMD ["npm", "start"]
|
||||||
|
ENTRYPOINT ["npm", "start"]
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
"main": "source/Main.ts",
|
"main": "source/Main.ts",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "npx tsc && node build/Main.js",
|
"start": "npx tsc && node build/Main.js",
|
||||||
|
"build": "npx tsc",
|
||||||
"schema": "npx json2ts -i source/Schema/ServerStats.json -o ./source/Schema/ServerStats.d.ts --unreachableDefinitions",
|
"schema": "npx json2ts -i source/Schema/ServerStats.json -o ./source/Schema/ServerStats.d.ts --unreachableDefinitions",
|
||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,22 @@ discordClient.login(appConfig.discord.botToken).then(() => {
|
||||||
appLogger.info(`Login successful to discord with token`);
|
appLogger.info(`Login successful to discord with token`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start the DiscordService and restart it if an error occurred
|
||||||
|
*/
|
||||||
|
function startDiscordService(): void {
|
||||||
|
try {
|
||||||
|
new DiscordService(discordClient);
|
||||||
|
} catch (exception) {
|
||||||
|
appLogger.error(`Restarting the discord service, an error occurred`, exception);
|
||||||
|
} finally {
|
||||||
|
setTimeout(() => {
|
||||||
|
startDiscordService();
|
||||||
|
}, 5000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
discordClient.on('ready', () => {
|
discordClient.on('ready', () => {
|
||||||
appLogger.info(`Discord client ready. Logged in as ${discordClient.user?.username}!`);
|
appLogger.info(`Discord client ready. Logged in as ${discordClient.user?.username}!`);
|
||||||
new DiscordService(discordClient);
|
startDiscordService();
|
||||||
});
|
});
|
||||||
Loading…
Reference in a new issue