Skip to content

Commit

Permalink
Automatically Set Channel Bitrate
Browse files Browse the repository at this point in the history
  • Loading branch information
ikifar2012 committed Mar 22, 2023
1 parent b0fb2c4 commit c9b375e
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 22 deletions.
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const botgate = require('./utilities/botgate.js');
const pkg = require('./package.json');
const CustomVC = require('./utilities/custom-vc.js');
const autorole = require('./utilities/autorole.js');
const vctools = require('./utilities/vc-tools.js');
global.client = new Client({
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.GuildMessageReactions, GatewayIntentBits.GuildMembers, GatewayIntentBits.GuildVoiceStates, GatewayIntentBits.DirectMessages, GatewayIntentBits.MessageContent, GatewayIntentBits.GuildModeration],
partials: [Partials.Message, Partials.Channel, Partials.Reaction],
Expand Down Expand Up @@ -248,6 +249,7 @@ global.client.on('voiceStateUpdate', async (oldState, newState) => {
if (newUserChannel === createcustomvc) {
CustomVC.Create(newState);
}
await vctools.setBitrate();
});

// listen for button interactions
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "coda-utilities",
"version": "3.0.0",
"version": "3.1.0",
"description": "A general utilities bot for Coda",
"main": "index.js",
"scripts": {
Expand Down
20 changes: 1 addition & 19 deletions utilities/custom-vc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,8 @@ const { ChannelType, PermissionFlagsBits, ActionRowBuilder, ButtonBuilder, Butto
const mariadb = require('../db.js');
const embedcreator = require('../embed.js');
const env = require('../env.js');
const { getMaxBitrate } = require('./vc-tools.js');
collector = false;
// get max bitrate
async function getMaxBitrate() {
// get max bitrate from discord
const guild = global.client.guilds.cache.get(env.discord.guild);
const maxbitrate = await guild.premiumTier;
// convert to bitrate
if (maxbitrate === 0) {
return 96000;
}
if (maxbitrate === 1) {
return 128000;
}
if (maxbitrate === 2) {
return 256000;
}
if (maxbitrate === 3) {
return 384000;
}
}
async function buttonResponder(interaction) {
const buttonid = interaction.customId;
const userchannel = await checkUser(interaction.user.id);
Expand Down
41 changes: 41 additions & 0 deletions utilities/vc-tools.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
const env = require('../env.js');
const embedcreator = require('../embed.js');
async function getMaxBitrate() {
// get max bitrate from discord
const guild = await global.client.guilds.cache.get(env.discord.guild);
const maxbitrate = await guild.premiumTier;
// convert to bitrate
if (maxbitrate === 0) {
return 96000;
}
if (maxbitrate === 1) {
return 128000;
}
if (maxbitrate === 2) {
return 256000;
}
if (maxbitrate === 3) {
return 384000;
}
}
// Set bitrate of each channel to max bitrate
async function setBitrate() {
try {
const guild = await global.client.guilds.cache.get(env.discord.guild);
const maxbitrate = await getMaxBitrate();
const channels = await guild.channels.cache.filter(channel => channel.type === 2 && channel.bitrate !== maxbitrate);
channels.forEach(async channel => {
await channel.setBitrate(maxbitrate);
bitrate = maxbitrate / 1000;
embedcreator.log(`Set bitrate of ${channel} to ${bitrate}kbps`);
});
}
catch (error) {
console.error(error);
embedcreator.sendError(error);
}
}
module.exports = {
getMaxBitrate,
setBitrate,
};

0 comments on commit c9b375e

Please sign in to comment.