Compare commits

...

2 commits

Author SHA1 Message Date
008efd77a9
* Add config/ folder and SQLITE database
* Cleanup docker image and update node from 16 to 18
2022-07-28 15:31:11 +02:00
1481614be6
install sqlite3 2022-07-28 12:58:07 +02:00
8 changed files with 1584 additions and 69 deletions

3
.gitignore vendored
View file

@ -9,3 +9,6 @@ docker-compose.yml
# JS generated files
dist/
# Databse
*.sqlite3

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 !

1605
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -16,8 +16,10 @@
"license": "GPL-3.0-only",
"dependencies": {
"@discordjs/rest": "^1.0.1",
"@types/sqlite3": "^3.1.8",
"discord-api-types": "^0.36.0",
"discord.js": "^14.0.3",
"sqlite3": "^5.0.10",
"typescript": "^4.7.4"
},
"devDependencies": {

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!');
};