DiscordTickets/src/client.js

63 lines
1.8 KiB
JavaScript
Raw Normal View History

2022-08-02 19:25:53 +03:00
const { FrameworkClient } = require('@eartharoid/dbf');
2022-08-06 00:21:55 +03:00
const {
GatewayIntentBits, Partials,
} = 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');
2022-08-06 00:21:55 +03:00
const TicketManager = require('./lib/tickets/manager');
const sqliteMiddleware = require('./lib/middleware/prisma-sqlite');
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: [
2022-08-06 00:21:55 +03:00
GatewayIntentBits.DirectMessages,
GatewayIntentBits.DirectMessageReactions,
GatewayIntentBits.DirectMessageTyping,
GatewayIntentBits.MessageContent,
2022-07-18 15:34:29 +03:00
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildMessages,
2022-05-05 23:29:28 +03:00
],
2022-08-06 00:21:55 +03:00
partials: [
Partials.Message,
Partials.Channel,
Partials.Reaction,
],
2022-05-05 23:29:28 +03:00
});
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);
2022-08-06 00:21:55 +03:00
/** @type {TicketManager} */
this.tickets = new TicketManager(this);
2022-07-17 00:18:50 +03:00
this.config = config;
this.log = log;
2022-07-18 23:53:17 +03:00
this.supers = (process.env.SUPER ?? '').split(',');
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();
if (process.env.DB_PROVIDER === 'sqlite') this.prisma.$use(sqliteMiddleware);
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();
}
};