Skip to content

Commit

Permalink
improve ipv6 and cookie format + buildnum fix
Browse files Browse the repository at this point in the history
  • Loading branch information
200percentmicky committed Oct 6, 2023
1 parent adba222 commit 1f3a7cf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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) {
Expand Down
20 changes: 14 additions & 6 deletions src/bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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: [
Expand All @@ -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.
});
Expand Down

0 comments on commit 1f3a7cf

Please sign in to comment.