Settings, encryption, logging

This commit is contained in:
Isaac
2022-07-16 22:18:50 +01:00
parent 97623f3203
commit 79462e83e6
10 changed files with 221 additions and 10 deletions

View File

@@ -2,9 +2,14 @@ const { Client: FrameworkClient }= require('@eartharoid/dbf');
const { Intents } = require('discord.js');
const { PrismaClient } = require('@prisma/client');
const Keyv = require('keyv');
const I18n = require('@eartharoid/i18n');
const fs = require('fs');
const { join } = require('path');
const YAML = require('yaml');
const middleware = require('./lib/prisma');
module.exports = class Client extends FrameworkClient {
constructor() {
constructor(config, log) {
super({
intents: [
Intents.FLAGS.GUILDS,
@@ -12,11 +17,26 @@ module.exports = class Client extends FrameworkClient {
Intents.FLAGS.GUILD_MESSAGES,
],
});
const locales = {};
fs.readdirSync(join(__dirname, 'i18n'))
.filter(file => file.endsWith('.yml'))
.forEach(file => {
const data = fs.readFileSync(join(__dirname, 'i18n/' + file), { encoding: 'utf8' });
const name = file.slice(0, file.length - 4);
locales[name] = YAML.parse(data);
});
/** @type {I18n} */
this.i18n = new I18n('en-GB', locales);
this.config = config;
this.log = log;
}
async login(token) {
/** @type {PrismaClient} */
this.prisma = new PrismaClient();
// this.prisma.$use((params, next) => {})
this.prisma.$use(middleware);
this.keyv = new Keyv();
return super.login(token);
}