diff --git a/index.js b/index.js index 7463490..44c2878 100644 --- a/index.js +++ b/index.js @@ -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], @@ -248,6 +249,7 @@ global.client.on('voiceStateUpdate', async (oldState, newState) => { if (newUserChannel === createcustomvc) { CustomVC.Create(newState); } + await vctools.setBitrate(); }); // listen for button interactions diff --git a/package-lock.json b/package-lock.json index 94e241c..70a1087 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "coda-utilities", - "version": "3.0.0", + "version": "3.1.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "coda-utilities", - "version": "3.0.0", + "version": "3.1.0", "license": "ISC", "dependencies": { "@discordjs/rest": "^1.6.0", diff --git a/package.json b/package.json index bf47587..eebe141 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/utilities/custom-vc.js b/utilities/custom-vc.js index c09d903..9f19b39 100644 --- a/utilities/custom-vc.js +++ b/utilities/custom-vc.js @@ -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); diff --git a/utilities/vc-tools.js b/utilities/vc-tools.js new file mode 100644 index 0000000..6777875 --- /dev/null +++ b/utilities/vc-tools.js @@ -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, +}; \ No newline at end of file