From 1f3a7cfc0e791d937196a1f170b9627f08173492 Mon Sep 17 00:00:00 2001 From: 200percentmicky Date: Fri, 6 Oct 2023 01:19:44 -0500 Subject: [PATCH] improve ipv6 and cookie format + buildnum fix --- index.js | 4 ++-- src/bot.js | 20 ++++++++++++++------ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index c4021697..7f0e2955 100644 --- a/index.js +++ b/index.js @@ -20,7 +20,7 @@ require('dotenv').config(); const { ShardingManager } = require('discord.js'); const ChadMusic = require('./src/bot.js'); const logger = require('./src/modules/winstonLogger.js'); -const exec = require('child_process').exec; +const { execSync } = require('child_process'); // Say hello! const { version } = require('./package.json'); @@ -31,7 +31,7 @@ logger.info('/ /___/ / / / /_/ / /_/ / / / / /_/ (__ ) / /__'); logger.info('\\____/_/ /_/\\__,_/\\__,_/_/ /_/\\__,_/____/_/\\___/'); logger.info('/////////////// The Chad Music Bot! ///////////////'); logger.info('Created by Micky D. | @200percentmicky | Micky-kun#3836'); -logger.info('Bot Version: %s (Build %s)', version, exec('git rev-parse --short HEAD')); +logger.info('Bot Version: %s (Build %s)', version, execSync('git rev-parse --short HEAD', { encoding: 'utf-8' }).toString().trim()); logger.info('Loading libraries...'); if (process.versions.node.split('.')[0] < 18) { diff --git a/src/bot.js b/src/bot.js index 9b82aa26..aeccdc28 100644 --- a/src/bot.js +++ b/src/bot.js @@ -31,9 +31,9 @@ const ChadUI = require('./modules/ChadUI'); const ChadUtils = require('./modules/ChadUtils'); const path = require('path'); const fs = require('fs'); -const exec = require('child_process').exec; +const { execSync } = require('child_process'); -const buildNumber = exec('git rev-parse --short HEAD'); +const buildNumber = execSync('git rev-parse --short HEAD', { encoding: 'utf-8' }).toString().trim(); // Let's boogie! class ChadMusic extends AkairoClient { @@ -133,6 +133,16 @@ class ChadMusic extends AkairoClient { this.settings.ensure('global', this.defaultGlobalSettings); + this.agent = () => { + try { + return ytdl.createProxyAgent(undefined, { + localAddress: getRandomIPv6(process.env.IPV6_BLOCK) + }); + } catch { + return undefined; + } + }; + // Music Player. this.player = new DisTube(this, { plugins: [ @@ -148,15 +158,13 @@ class ChadMusic extends AkairoClient { leaveOnEmpty: this.settings.get('global', 'leaveOnEmpty') ?? true, leaveOnFinish: this.settings.get('global', 'leaveOnFinish') ?? true, streamType: this.settings.get('global', 'streamType') ?? 0, - youtubeCookie: JSON.parse(fs.readFileSync('../cookies.json')), + youtubeCookie: JSON.parse(fs.readFileSync(path.join(__dirname, '..', 'cookies.json'))), ytdlOptions: { quality: 'highestaudio', filter: 'audioonly', dlChunkSize: 25000, highWaterMark: 1024, - agent: ytdl.createProxyAgent(undefined, { - localAddress: getRandomIPv6(process.env.IPV6_BLOCK) - }) + agent: this.agent }, nsfw: true // Being handled on a per guild basis, not client-wide. });