1
0
mirror of https://github.com/musix-org/musix-oss synced 2024-12-23 16:13:18 +00:00
musix-oss/src/struct/client.js

61 lines
2.3 KiB
JavaScript
Raw Normal View History

2020-02-05 20:02:53 +00:00
const { Client, Collection } = require('discord.js');
const admin = require('firebase-admin');
const serviceAccount = require('./config/serviceAccount.json');
const fs = require('fs');
2020-03-08 09:32:14 +00:00
const path = require('path');
2020-03-19 14:45:05 +00:00
const events = require('../events/events.js');
2020-02-05 20:02:53 +00:00
module.exports = class extends Client {
constructor() {
super({
disableEveryone: true,
disabledEvents: ['TYPING_START']
});
2020-03-19 14:45:05 +00:00
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
});
2020-02-05 20:02:53 +00:00
this.commands = new Collection();
this.commandAliases = new Collection();
this.settingCmd = new Collection();
this.queue = new Map();
this.funcs = {};
this.dispatcher = {};
this.config = require('./config/config.js');
2020-03-12 11:56:31 +00:00
this.messages = require('./config/messages.js');
2020-03-19 14:45:05 +00:00
this.db = admin.firestore();
this.db.FieldValue = require('firebase-admin').firestore.FieldValue;
this.dispatcher.finish = require('../events/dispatcherEvents/finish.js');
2020-03-21 17:49:25 +00:00
this.dispatcher.error = require('../events/dispatcherEvents/error.js');
2020-03-19 14:45:05 +00:00
this.global = {
db: {
guilds: {},
},
};
2020-02-05 20:02:53 +00:00
fs.readdirSync(path.join(__dirname, 'funcs')).forEach(filename => {
this.funcs[filename.slice(0, -3)] = require(`./funcs/${filename}`);
});
const commandFiles = fs.readdirSync(path.join(path.dirname(__dirname), 'commands')).filter(f => f.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`../commands/${file}`);
command.uses = 0;
this.commands.set(command.name, command);
this.commandAliases.set(command.alias, command);
}
const settingFiles = fs.readdirSync(path.join(path.dirname(__dirname), 'commands/settings')).filter(f => f.endsWith('.js'));
for (const file of settingFiles) {
const option = require(`../commands/settings/${file}`);
this.settingCmd.set(option.name, option);
}
2020-03-13 20:31:04 +00:00
if (this.config.devMode) {
this.config.token = this.config.devToken;
}
2020-02-05 20:02:53 +00:00
2020-03-19 14:45:05 +00:00
events(this);
2020-02-05 20:02:53 +00:00
this.login(this.config.token).catch(err => console.log('Failed to login: ' + err));
}
};