/* eslint-disable no-unused-vars */ const { Client, Intents, Collection } = require('discord.js'); const { GUILDS, GUILD_VOICE_STATES, GUILD_MESSAGES, GUILD_MESSAGE_REACTIONS } = Intents.FLAGS; const { Shoukaku, Libraries } = require('shoukaku'); const { LavasfyClient } = require('lavasfy'); const Topgg = require('@top-gg/sdk'); const Utils = require('./Util.js'); const Queue = require('./Queue.js'); const loggerHandler = require('./logger'); const config = require('../../config.json'), LavalinkServer = config.nodes; const ShoukakuOptions = { moveOnDisconnect: false, resumable: false, resumableTimeout: 60, reconnectTries: 30, restTimeout: 60000 }; module.exports = class Aqua extends Client { constructor(options = {}) { super({ allowedMentions: { parse: ['users', 'roles'], repliedUser: true }, intents: [GUILDS, GUILD_VOICE_STATES, GUILD_MESSAGES, GUILD_MESSAGE_REACTIONS], restTimeOffset: 0 }); this.validate(options); this.shoukaku = new Shoukaku(new Libraries.DiscordJS(this), LavalinkServer, ShoukakuOptions); this.queue = new Queue(this); this.commands = new Collection(); this.aliases = new Collection(); this.slashs = new Collection(); this.events = new Collection(); this.utils = new Utils(this); this.topgg = new Topgg.Api(config.Topgg_api); this.logger = new loggerHandler(); this.config = config; this._setupShoukakuEvents(); this.lavasfy = new LavasfyClient({ clientID: config.SPOTIFY_ID, clientSecret: config.SPOTIFY_SECRET, playlistLoadLimit: config.SPOTIFY_PLAYLIST_PAGE_LIMIT, autoResolve: true, audioOnlyResults: true, useSpotifyMetadata: true }, [{ id: `${this.config.nodes.map(m => m.name).join(' ')}`, host: this.config.host, port: this.config.port, password: `${this.config.nodes.map(m => m.auth).join(' ')}`, secure: this.config.LavaSecure }]); require('../mongo.js')(); this.wait = require('util').promisify(setTimeout); this.util = require('../../util.js'); } validate(options) { if (typeof options !== 'object') throw new TypeError('Options should be a type of Object.'); if (!options.token) throw new Error('You must pass the token for the client.'); this.token = options.token; if (!options.prefix) throw new Error('You must pass a prefix for the client.'); if (typeof options.prefix !== 'string') throw new TypeError('Prefix should be a type of String.'); this.prefix = options.prefix; if (!options.owners) throw new Error('You must pass a list of owners for the client.'); if (!Array.isArray(options.owners)) throw new TypeError('Owners should be a type of Array.'); this.owners = options.owners; } _setupShoukakuEvents() { this.shoukaku.on('ready', (name, resumed) => this.logger.log(`LAVALINK => [STATUS] ${name} successfully connected.`, ` This connection is ${resumed ? 'resumed' : 'a new connection'}`)); this.shoukaku.on('error', (name, error) => this.logger.error(`LAVALINK => ${name}: Error Caught.`, error)); this.shoukaku.on('close', (name, code, reason) => this.logger.log(`LAVALINK => ${name}: Closed, Code ${code}`, `Reason ${reason || 'No reason'}.`)); this.shoukaku.on('disconnect', (name, players, moved) => this.logger.log(`LAVALINK => ${name}: Disconnected`, moved ? 'players have been moved' : 'players have been disconnected')); this.shoukaku.on('debug', (name, reason) => this.logger.log(`LAVALINK => ${name}`, reason || 'No reason')); } async init(token = this.token) { this.utils.loadCommands(); this.utils.loadEvents(); this.utils.loadSlash(); super.login(token); } };