* Add config/ folder and SQLITE database

* Cleanup docker image and update node from 16 to 18
This commit is contained in:
Mylloon 2022-07-28 15:31:11 +02:00
parent 1481614be6
commit 008efd77a9
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
5 changed files with 39 additions and 4 deletions

View file

@ -1,6 +1,10 @@
# syntax=docker/dockerfile:1
FROM node:16.15.0-alpine3.15
FROM node:18.7.0-alpine3.16
ENV DOCKERIZED=1
RUN mkdir /config
RUN chown node:node /config
RUN apk add dumb-init
ENV NODE_ENV=production
@ -13,5 +17,6 @@ RUN npm ci --only=production
RUN npx tsc
RUN rm -r src/ tsconfig.json
RUN npm uninstall typescript discord-api-types @types/sqlite3
CMD ["dumb-init", "node", "./dist/index.js"]

View file

@ -28,6 +28,8 @@ services:
container_name: Botanique
environment:
- TOKEN_DISCORD=ton-token-va-ici
volumes:
- /here/your/path:/config
restart: unless-stopped
```
@ -37,6 +39,11 @@ services:
| TOKEN_DISCORD | Token Discord | Aucune |
| DEFAULT_LANG | Langue par défaut | `fr` | Expérimental, si la langue par défaut n'est pas complète (càd 100%), le bot pourrait ne pas fonctionner correctement.<br>Liste des traductions disponibles [ici](./src/locales/).
## Volumes
| Chemin | Description
| :-------: | :-:
| `/config` | Dossier de configuration, par exemple, c'est ici que la base de donnée est.
# Contribuer
Toute contribution est la bienvenue !

View file

@ -1,4 +1,4 @@
import loadClient from './utils/client';
import loadClient, { quit } from './utils/client';
import loadEvents from './events/loader';
import loadCommands from './commands/loader';
@ -41,6 +41,12 @@ const run = async () => {
});
console.log(`Botanique "${client.user?.username}" v${client.config.version} started!`);
// ^C
process.on('SIGINT', () => quit(client));
// Container force closed
process.on('SIGTERM', () => quit(client));
})
.catch(() => {
throw logStart(client_name, false);

View file

@ -1,5 +1,6 @@
import { Collection } from 'discord.js';
import { SlashCommandBuilder } from '@discordjs/builders';
import { Database } from 'sqlite3';
export {};
@ -34,8 +35,9 @@ declare module 'discord.js' {
interaction: (interaction: CommandInteraction, client: Client) => unknown
}
>,
}
},
/** Store all the localizations */
locales: Map<string, Map<string, string>>
locales: Map<string, Map<string, string>>,
db: Database,
}
}

View file

@ -2,6 +2,7 @@ import { Client, Collection, GatewayIntentBits } from 'discord.js';
import { readFileSync } from 'fs';
import { loadLocales } from './locales';
import '../modules/client';
import { Database } from 'sqlite3';
/** Creation of the client and definition of its properties. */
export default async () => {
@ -26,5 +27,19 @@ export default async () => {
console.log('Translations progression :');
client.locales = await loadLocales(client.config.default_lang);
client.db = new Database(`${
process.env.DOCKERIZED === '1' ? '/config' : './config'
}/db.sqlite3`);
return client;
};
export const quit = (client: Client) => {
// Close DB
client.db.close();
// Close client
client.destroy();
console.log('ciao!');
};