DiscordTickets/src/client.js

48 lines
1.2 KiB
JavaScript
Raw Normal View History

2022-05-05 23:29:28 +03:00
const { Client: FrameworkClient }= require('@eartharoid/dbf');
const { Intents } = require('discord.js');
2022-05-06 02:27:27 +03:00
const { PrismaClient } = require('@prisma/client');
2022-07-16 01:19:42 +03:00
const Keyv = require('keyv');
2022-07-17 00:18:50 +03:00
const I18n = require('@eartharoid/i18n');
const fs = require('fs');
const { join } = require('path');
const YAML = require('yaml');
const middleware = require('./lib/prisma');
2022-05-05 23:29:28 +03:00
module.exports = class Client extends FrameworkClient {
2022-07-17 00:18:50 +03:00
constructor(config, log) {
2022-05-05 23:29:28 +03:00
super({
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MEMBERS,
Intents.FLAGS.GUILD_MESSAGES,
],
});
2022-07-17 00:18:50 +03:00
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;
2022-05-05 23:29:28 +03:00
}
2022-05-06 02:27:27 +03:00
2022-05-05 23:29:28 +03:00
async login(token) {
2022-07-17 00:18:50 +03:00
/** @type {PrismaClient} */
2022-05-06 02:27:27 +03:00
this.prisma = new PrismaClient();
2022-07-17 00:18:50 +03:00
this.prisma.$use(middleware);
2022-07-16 01:19:42 +03:00
this.keyv = new Keyv();
2022-05-05 23:29:28 +03:00
return super.login(token);
}
async destroy() {
await this.prisma.$disconnect();
return super.destroy();
}
};