From bbfa459ad14517d19492b118cbdbfcb07d76a9d2 Mon Sep 17 00:00:00 2001 From: TannerGabriel Date: Sat, 30 Dec 2023 19:25:18 +0100 Subject: [PATCH 1/3] feat: Add option to change default volume Signed-off-by: TannerGabriel --- README.md | 6 +++++- commands/play.js | 9 +++++---- commands/resume.js | 1 - config.json | 3 ++- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index e2daa74d..eb1020b7 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,11 @@ After cloning the project and installing all dependencies, you need to add your ### Changing the status -You can change the status of your discord bot by editing the `activity` and `activityType` variables inside of the `config.json` file. `activityType` needs to be set to an integer with the following [options](https://discord-api-types.dev/api/discord-api-types-v10/enum/ActivityType). +You can change the status of your discord bot by editing the `activity` and `activityType` variables inside the `config.json` file. `activityType` needs to be set to an integer with the following [options](https://discord-api-types.dev/api/discord-api-types-v10/enum/ActivityType). + +### Changing the default volume + +The default volume can be adjusted by changing the volume variable inside the `config.json` file. If you only want to adjust the volume for a single song/playlist instead, use the volume command instead. ### Starting the application diff --git a/commands/play.js b/commands/play.js index e835e9cb..cd43357d 100644 --- a/commands/play.js +++ b/commands/play.js @@ -1,6 +1,7 @@ -const {GuildMember, ApplicationCommandOptionType} = require('discord.js'); -const {QueryType, useMainPlayer} = require('discord-player'); +const {ApplicationCommandOptionType} = require('discord.js'); +const {useMainPlayer} = require('discord-player'); const {isInVoiceChannel} = require("../utils/voicechannel"); +const config = require('./config.json'); module.exports = { name: 'play', @@ -29,7 +30,7 @@ module.exports = { return void interaction.followUp({content: 'No results were found!'}); try { - const res = await player.play(interaction.member.voice.channel.id, searchResult, { + await player.play(interaction.member.voice.channel.id, searchResult, { nodeOptions: { metadata: { channel: interaction.channel, @@ -40,7 +41,7 @@ module.exports = { leaveOnEmpty: true, leaveOnEnd: false, bufferingTimeout: 0, - volume: 10, + volume: config.volume || 10, //defaultFFmpegFilters: ['lofi', 'bassboost', 'normalizer'] } }); diff --git a/commands/resume.js b/commands/resume.js index 310e15d4..ea1e7cfa 100644 --- a/commands/resume.js +++ b/commands/resume.js @@ -1,4 +1,3 @@ -const {GuildMember} = require('discord.js'); const {useQueue} = require("discord-player"); const {isInVoiceChannel} = require("../utils/voicechannel"); diff --git a/config.json b/config.json index 782f6675..9809aa6a 100644 --- a/config.json +++ b/config.json @@ -1,4 +1,5 @@ { "activityType": "0", - "activity": "your music selections" + "activity": "your music selections", + "volume": 10 } \ No newline at end of file From 72c133b95fbd5f487f2fc3249cfdec63d5accb85 Mon Sep 17 00:00:00 2001 From: TannerGabriel Date: Thu, 8 Feb 2024 21:34:59 +0100 Subject: [PATCH 2/3] Save volume using conf package Signed-off-by: TannerGabriel --- .prettierrc.json | 4 +- commands/play.js | 27 +++-- commands/volume.js | 28 ++--- config.json | 6 +- index.js | 11 +- package-lock.json | 297 +++++++++++++++++++++++++++++++++++++++++++++ package.json | 1 + 7 files changed, 338 insertions(+), 36 deletions(-) diff --git a/.prettierrc.json b/.prettierrc.json index f61120c0..462af08a 100644 --- a/.prettierrc.json +++ b/.prettierrc.json @@ -8,7 +8,7 @@ "requirePragma": false, "semi": true, "singleQuote": true, - "tabWidth": 2, + "tabWidth": 4, "trailingComma": "all", "useTabs": false, "vueIndentScriptAndStyle": true, @@ -20,4 +20,4 @@ } } ] - } \ No newline at end of file + } diff --git a/commands/play.js b/commands/play.js index cd43357d..f00b607a 100644 --- a/commands/play.js +++ b/commands/play.js @@ -1,7 +1,6 @@ const {ApplicationCommandOptionType} = require('discord.js'); const {useMainPlayer} = require('discord-player'); -const {isInVoiceChannel} = require("../utils/voicechannel"); -const config = require('./config.json'); +const {isInVoiceChannel} = require('../utils/voicechannel'); module.exports = { name: 'play', @@ -15,35 +14,37 @@ module.exports = { }, ], async execute(interaction) { + const {default: Conf} = await import('conf'); try { - const inVoiceChannel = isInVoiceChannel(interaction) + const inVoiceChannel = isInVoiceChannel(interaction); if (!inVoiceChannel) { - return + return; } await interaction.deferReply(); - const player = useMainPlayer() + const player = useMainPlayer(); const query = interaction.options.getString('query'); - const searchResult = await player.search(query) - if (!searchResult.hasTracks()) - return void interaction.followUp({content: 'No results were found!'}); + const searchResult = await player.search(query); + if (!searchResult.hasTracks()) return void interaction.followUp({content: 'No results were found!'}); try { + const config = new Conf({projectName: 'volume'}); + await player.play(interaction.member.voice.channel.id, searchResult, { nodeOptions: { metadata: { channel: interaction.channel, client: interaction.guild?.members.me, - requestedBy: interaction.user.username + requestedBy: interaction.user.username, }, leaveOnEmptyCooldown: 300000, leaveOnEmpty: true, leaveOnEnd: false, bufferingTimeout: 0, - volume: config.volume || 10, + volume: config.get('volume') || 10, //defaultFFmpegFilters: ['lofi', 'bassboost', 'normalizer'] - } + }, }); await interaction.followUp({ @@ -51,8 +52,8 @@ module.exports = { }); } catch (error) { await interaction.editReply({ - content: 'An error has occurred!' - }) + content: 'An error has occurred!', + }); return console.log(error); } } catch (error) { diff --git a/commands/volume.js b/commands/volume.js index da749231..fa004eac 100644 --- a/commands/volume.js +++ b/commands/volume.js @@ -1,6 +1,6 @@ -const {GuildMember, ApplicationCommandOptionType} = require('discord.js'); -const {useQueue} = require("discord-player"); -const {isInVoiceChannel} = require("../utils/voicechannel"); +const {ApplicationCommandOptionType} = require('discord.js'); +const {useQueue} = require('discord-player'); +const {isInVoiceChannel} = require('../utils/voicechannel'); module.exports = { name: 'volume', @@ -14,25 +14,25 @@ module.exports = { }, ], async execute(interaction) { - const inVoiceChannel = isInVoiceChannel(interaction) - if (!inVoiceChannel) { - return - } + const {default: Conf} = await import('conf'); + const inVoiceChannel = isInVoiceChannel(interaction); await interaction.deferReply(); - const queue = useQueue(interaction.guild.id); - if (!queue || !queue.currentTrack) - return void interaction.followUp({ - content: '❌ | No music is being played!', - }); let volume = interaction.options.getInteger('volume'); volume = Math.max(0, volume); volume = Math.min(200, volume); - const success = queue.node.setVolume(volume); + + // Set the general volume (persisted) + const config = new Conf({projectName: 'volume'}); + config.set('volume', volume); + + // Set the volume of the current queue + const queue = useQueue(interaction.guild.id); + if (inVoiceChannel && queue && queue.currentTrack) queue.node.setVolume(volume); return void interaction.followUp({ - content: success ? `🔊 | Volume set to ${volume}!` : '❌ | Something went wrong!', + content: `🔊 | Volume set to ${volume}!`, }); }, }; diff --git a/config.json b/config.json index 9809aa6a..558816b2 100644 --- a/config.json +++ b/config.json @@ -1,5 +1,5 @@ { "activityType": "0", - "activity": "your music selections", - "volume": 10 -} \ No newline at end of file + "activity": "your music selections" +} + diff --git a/index.js b/index.js index c16c475b..ff5f8986 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,4 @@ -require('dotenv').config() +require('dotenv').config(); const fs = require('fs'); const Discord = require('discord.js'); @@ -22,7 +22,7 @@ console.log(client.commands); const player = new Player(client); -player.extractors.loadDefault().then(r => console.log('Extractors loaded successfully')) +player.extractors.loadDefault().then(r => console.log('Extractors loaded successfully')); // Still needs to be refactored for 0.6 /*player.events.on('connection', (queue) => { @@ -86,8 +86,8 @@ client.on('ready', function () { console.log('Ready!'); client.user.presence.set({ activities: [{name: config.activity, type: Number(config.activityType)}], - status: Discord.Status.Ready - }) + status: Discord.Status.Ready, + }); }); client.once('reconnecting', () => { @@ -121,6 +121,9 @@ client.on('interactionCreate', async interaction => { try { if (interaction.commandName == 'ban' || interaction.commandName == 'userinfo') { command.execute(interaction, client); + } else if (interaction.commandName == 'volume' || interaction.commandName == 'play') { + command.execute(interaction); + // command.execute(interaction, config) } else { command.execute(interaction); } diff --git a/package-lock.json b/package-lock.json index 5cf3e58f..13570cb6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,6 +11,7 @@ "dependencies": { "@discord-player/extractor": "^4.4.1", "@discordjs/opus": "^0.9.0", + "conf": "^12.0.0", "discord-player": "^6.6.2", "discord.js": "^14.12.1", "dotenv": "^16.3.1", @@ -260,6 +261,37 @@ "node": ">= 6.0.0" } }, + "node_modules/ajv": { + "version": "8.12.0", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.12.0.tgz", + "integrity": "sha512-sRu1kpcO9yLtYxBKvqfTeh9KzZEwO3STyX1HT+4CaDzC6HpTGYhIhPIzj9XuKU7KYDwnaeh5hcOwjy1QuJzBPA==", + "dependencies": { + "fast-deep-equal": "^3.1.1", + "json-schema-traverse": "^1.0.0", + "require-from-string": "^2.0.2", + "uri-js": "^4.2.2" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/epoberezkin" + } + }, + "node_modules/ajv-formats": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/ajv-formats/-/ajv-formats-2.1.1.tgz", + "integrity": "sha512-Wx0Kx52hxE7C18hkMEggYlEifqWZtYaRgouJor+WMdPnQyEK13vgEWyVNup7SoeeoLMsr4kf5h6dOW11I15MUA==", + "dependencies": { + "ajv": "^8.0.0" + }, + "peerDependencies": { + "ajv": "^8.0.0" + }, + "peerDependenciesMeta": { + "ajv": { + "optional": true + } + } + }, "node_modules/ansi-regex": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", @@ -290,6 +322,15 @@ "resolved": "https://registry.npmjs.org/async/-/async-3.2.4.tgz", "integrity": "sha512-iAB+JbDEGXhyIUavoDl9WP/Jj106Kz9DEn1DPgYw5ruDn0e3Wgi3sKFm55sASdGBNOQB8F59d9qQ7deqrHA8wQ==" }, + "node_modules/atomically": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/atomically/-/atomically-2.0.2.tgz", + "integrity": "sha512-Xfmb4q5QV7uqTlVdMSTtO5eF4DCHfNOdaPyKlbFShkzeNP+3lj3yjjcbdjSmEY4+pDBKJ9g26aP+ImTe88UHoQ==", + "dependencies": { + "stubborn-fs": "^1.2.5", + "when-exit": "^2.0.0" + } + }, "node_modules/balanced-match": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", @@ -377,6 +418,28 @@ "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==" }, + "node_modules/conf": { + "version": "12.0.0", + "resolved": "https://registry.npmjs.org/conf/-/conf-12.0.0.tgz", + "integrity": "sha512-fIWyWUXrJ45cHCIQX+Ck1hrZDIf/9DR0P0Zewn3uNht28hbt5OfGUq8rRWsxi96pZWPyBEd0eY9ama01JTaknA==", + "dependencies": { + "ajv": "^8.12.0", + "ajv-formats": "^2.1.1", + "atomically": "^2.0.2", + "debounce-fn": "^5.1.2", + "dot-prop": "^8.0.2", + "env-paths": "^3.0.0", + "json-schema-typed": "^8.0.1", + "semver": "^7.5.4", + "uint8array-extras": "^0.3.0" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/console-control-strings": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/console-control-strings/-/console-control-strings-1.1.0.tgz", @@ -416,6 +479,20 @@ "node": ">= 12" } }, + "node_modules/debounce-fn": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/debounce-fn/-/debounce-fn-5.1.2.tgz", + "integrity": "sha512-Sr4SdOZ4vw6eQDvPYNxHogvrxmCIld/VenC5JbNrFwMiwd7lY/Z18ZFfo+EWNG4DD9nFlAujWAo/wGuOPHmy5A==", + "dependencies": { + "mimic-fn": "^4.0.0" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/debug": { "version": "4.3.4", "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", @@ -545,6 +622,20 @@ "url": "https://github.com/fb55/domutils?sponsor=1" } }, + "node_modules/dot-prop": { + "version": "8.0.2", + "resolved": "https://registry.npmjs.org/dot-prop/-/dot-prop-8.0.2.tgz", + "integrity": "sha512-xaBe6ZT4DHPkg0k4Ytbvn5xoxgpG0jOS1dYxSOwAHPuNLjP3/OzN0gH55SrLqpx8cBfSaVt91lXYkApjb+nYdQ==", + "dependencies": { + "type-fest": "^3.8.0" + }, + "engines": { + "node": ">=16" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/dotenv": { "version": "16.3.1", "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.3.1.tgz", @@ -572,6 +663,17 @@ "url": "https://github.com/fb55/entities?sponsor=1" } }, + "node_modules/env-paths": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/env-paths/-/env-paths-3.0.0.tgz", + "integrity": "sha512-dtJUTepzMW3Lm/NPxRf3wP4642UWhjL2sQxc+ym2YMj1m/H2zDNQOlezafzkHwn6sMstjHTwG6iQQsctDW/b1A==", + "engines": { + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/fast-deep-equal": { "version": "3.1.3", "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", @@ -840,6 +942,16 @@ "url": "https://opencollective.com/node-fetch" } }, + "node_modules/json-schema-traverse": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz", + "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==" + }, + "node_modules/json-schema-typed": { + "version": "8.0.1", + "resolved": "https://registry.npmjs.org/json-schema-typed/-/json-schema-typed-8.0.1.tgz", + "integrity": "sha512-XQmWYj2Sm4kn4WeTYvmpKEbyPsL7nBsb647c7pMe6l02/yx2+Jfc4dT6UZkEXnIUb5LhD55r2HPsJ1milQ4rDg==" + }, "node_modules/libsodium": { "version": "0.7.11", "resolved": "https://registry.npmjs.org/libsodium/-/libsodium-0.7.11.tgz", @@ -913,6 +1025,17 @@ "semver": "bin/semver.js" } }, + "node_modules/mimic-fn": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-4.0.0.tgz", + "integrity": "sha512-vqiC06CuhBTUdZH+RYl8sFrL096vA45Ok5ISO6sE/Mr1jRbGH4Csnhi8f3wKVl7x8mO4Au7Ir9D3Oyv1VYMFJw==", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/miniget": { "version": "4.2.3", "resolved": "https://registry.npmjs.org/miniget/-/miniget-4.2.3.tgz", @@ -1170,6 +1293,14 @@ } } }, + "node_modules/punycode": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz", + "integrity": "sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==", + "engines": { + "node": ">=6" + } + }, "node_modules/readable-stream": { "version": "3.6.2", "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.2.tgz", @@ -1198,6 +1329,14 @@ "url": "https://github.com/sponsors/Borewit" } }, + "node_modules/require-from-string": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/require-from-string/-/require-from-string-2.0.2.tgz", + "integrity": "sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==", + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/reverbnation-scraper": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/reverbnation-scraper/-/reverbnation-scraper-2.0.0.tgz", @@ -1352,6 +1491,11 @@ "url": "https://github.com/sponsors/Borewit" } }, + "node_modules/stubborn-fs": { + "version": "1.2.5", + "resolved": "https://registry.npmjs.org/stubborn-fs/-/stubborn-fs-1.2.5.tgz", + "integrity": "sha512-H2N9c26eXjzL/S/K+i/RHHcFanE74dptvvjM8iwzwbVcWY/zjBbgRqF3K0DY4+OD+uTTASTBvDoxPDaPN02D7g==" + }, "node_modules/tar": { "version": "6.1.15", "resolved": "https://registry.npmjs.org/tar/-/tar-6.1.15.tgz", @@ -1399,6 +1543,28 @@ "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.6.1.tgz", "integrity": "sha512-t0hLfiEKfMUoqhG+U1oid7Pva4bbDPHYfJNiB7BiIjRkj1pyC++4N3huJfqY6aRH6VTB0rvtzQwjM4K6qpfOig==" }, + "node_modules/type-fest": { + "version": "3.13.1", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-3.13.1.tgz", + "integrity": "sha512-tLq3bSNx+xSpwvAJnzrK0Ep5CLNWjvFTOp71URMaAEWBfRb9nnJiBoUe0tF8bI4ZFO3omgBR6NvnbzVUT3Ly4g==", + "engines": { + "node": ">=14.16" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/uint8array-extras": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/uint8array-extras/-/uint8array-extras-0.3.0.tgz", + "integrity": "sha512-erJsJwQ0tKdwuqI0359U8ijkFmfiTcq25JvvzRVc1VP+2son1NJRXhxcAKJmAW3ajM8JSGAfsAXye8g4s+znxA==", + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/undici": { "version": "5.22.1", "resolved": "https://registry.npmjs.org/undici/-/undici-5.22.1.tgz", @@ -1415,6 +1581,14 @@ "resolved": "https://registry.npmjs.org/unfetch/-/unfetch-5.0.0.tgz", "integrity": "sha512-3xM2c89siXg0nHvlmYsQ2zkLASvVMBisZm5lF3gFDqfF2xonNStDJyMpvaOBe0a1Edxmqrf2E0HBdmy9QyZaeg==" }, + "node_modules/uri-js": { + "version": "4.4.1", + "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.4.1.tgz", + "integrity": "sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg==", + "dependencies": { + "punycode": "^2.1.0" + } + }, "node_modules/util-deprecate": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", @@ -1447,6 +1621,11 @@ "resolved": "https://registry.npmjs.org/when/-/when-3.7.8.tgz", "integrity": "sha512-5cZ7mecD3eYcMiCH4wtRPA5iFJZ50BJYDfckI5RRpQiktMiYTcn0ccLTZOvcbBume+1304fQztxeNzNS9Gvrnw==" }, + "node_modules/when-exit": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/when-exit/-/when-exit-2.1.2.tgz", + "integrity": "sha512-u9J+toaf3CCxCAzM/484qNAxQE75rFdVgiFEEV8Xps2gzYhf0tx73s1WXDQhkwV17E3MxRMz40m7Ekd2/121Lg==" + }, "node_modules/which": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz", @@ -1705,6 +1884,25 @@ "debug": "4" } }, + "ajv": { + "version": "8.12.0", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.12.0.tgz", + "integrity": "sha512-sRu1kpcO9yLtYxBKvqfTeh9KzZEwO3STyX1HT+4CaDzC6HpTGYhIhPIzj9XuKU7KYDwnaeh5hcOwjy1QuJzBPA==", + "requires": { + "fast-deep-equal": "^3.1.1", + "json-schema-traverse": "^1.0.0", + "require-from-string": "^2.0.2", + "uri-js": "^4.2.2" + } + }, + "ajv-formats": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/ajv-formats/-/ajv-formats-2.1.1.tgz", + "integrity": "sha512-Wx0Kx52hxE7C18hkMEggYlEifqWZtYaRgouJor+WMdPnQyEK13vgEWyVNup7SoeeoLMsr4kf5h6dOW11I15MUA==", + "requires": { + "ajv": "^8.0.0" + } + }, "ansi-regex": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", @@ -1729,6 +1927,15 @@ "resolved": "https://registry.npmjs.org/async/-/async-3.2.4.tgz", "integrity": "sha512-iAB+JbDEGXhyIUavoDl9WP/Jj106Kz9DEn1DPgYw5ruDn0e3Wgi3sKFm55sASdGBNOQB8F59d9qQ7deqrHA8wQ==" }, + "atomically": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/atomically/-/atomically-2.0.2.tgz", + "integrity": "sha512-Xfmb4q5QV7uqTlVdMSTtO5eF4DCHfNOdaPyKlbFShkzeNP+3lj3yjjcbdjSmEY4+pDBKJ9g26aP+ImTe88UHoQ==", + "requires": { + "stubborn-fs": "^1.2.5", + "when-exit": "^2.0.0" + } + }, "balanced-match": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", @@ -1798,6 +2005,22 @@ "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==" }, + "conf": { + "version": "12.0.0", + "resolved": "https://registry.npmjs.org/conf/-/conf-12.0.0.tgz", + "integrity": "sha512-fIWyWUXrJ45cHCIQX+Ck1hrZDIf/9DR0P0Zewn3uNht28hbt5OfGUq8rRWsxi96pZWPyBEd0eY9ama01JTaknA==", + "requires": { + "ajv": "^8.12.0", + "ajv-formats": "^2.1.1", + "atomically": "^2.0.2", + "debounce-fn": "^5.1.2", + "dot-prop": "^8.0.2", + "env-paths": "^3.0.0", + "json-schema-typed": "^8.0.1", + "semver": "^7.5.4", + "uint8array-extras": "^0.3.0" + } + }, "console-control-strings": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/console-control-strings/-/console-control-strings-1.1.0.tgz", @@ -1825,6 +2048,14 @@ "resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-4.0.1.tgz", "integrity": "sha512-0R9ikRb668HB7QDxT1vkpuUBtqc53YyAwMwGeUFKRojY/NWKvdZ+9UYtRfGmhqNbRkTSVpMbmyhXipFFv2cb/A==" }, + "debounce-fn": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/debounce-fn/-/debounce-fn-5.1.2.tgz", + "integrity": "sha512-Sr4SdOZ4vw6eQDvPYNxHogvrxmCIld/VenC5JbNrFwMiwd7lY/Z18ZFfo+EWNG4DD9nFlAujWAo/wGuOPHmy5A==", + "requires": { + "mimic-fn": "^4.0.0" + } + }, "debug": { "version": "4.3.4", "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", @@ -1914,6 +2145,14 @@ "domhandler": "^5.0.3" } }, + "dot-prop": { + "version": "8.0.2", + "resolved": "https://registry.npmjs.org/dot-prop/-/dot-prop-8.0.2.tgz", + "integrity": "sha512-xaBe6ZT4DHPkg0k4Ytbvn5xoxgpG0jOS1dYxSOwAHPuNLjP3/OzN0gH55SrLqpx8cBfSaVt91lXYkApjb+nYdQ==", + "requires": { + "type-fest": "^3.8.0" + } + }, "dotenv": { "version": "16.3.1", "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.3.1.tgz", @@ -1929,6 +2168,11 @@ "resolved": "https://registry.npmjs.org/entities/-/entities-4.5.0.tgz", "integrity": "sha512-V0hjH4dGPh9Ao5p0MoRY6BVqtwCjhz6vI5LT8AJ55H+4g9/4vbHx1I54fS0XuclLhDHArPQCiMjDxjaL8fPxhw==" }, + "env-paths": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/env-paths/-/env-paths-3.0.0.tgz", + "integrity": "sha512-dtJUTepzMW3Lm/NPxRf3wP4642UWhjL2sQxc+ym2YMj1m/H2zDNQOlezafzkHwn6sMstjHTwG6iQQsctDW/b1A==" + }, "fast-deep-equal": { "version": "3.1.3", "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", @@ -2124,6 +2368,16 @@ } } }, + "json-schema-traverse": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz", + "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==" + }, + "json-schema-typed": { + "version": "8.0.1", + "resolved": "https://registry.npmjs.org/json-schema-typed/-/json-schema-typed-8.0.1.tgz", + "integrity": "sha512-XQmWYj2Sm4kn4WeTYvmpKEbyPsL7nBsb647c7pMe6l02/yx2+Jfc4dT6UZkEXnIUb5LhD55r2HPsJ1milQ4rDg==" + }, "libsodium": { "version": "0.7.11", "resolved": "https://registry.npmjs.org/libsodium/-/libsodium-0.7.11.tgz", @@ -2184,6 +2438,11 @@ } } }, + "mimic-fn": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-4.0.0.tgz", + "integrity": "sha512-vqiC06CuhBTUdZH+RYl8sFrL096vA45Ok5ISO6sE/Mr1jRbGH4Csnhi8f3wKVl7x8mO4Au7Ir9D3Oyv1VYMFJw==" + }, "miniget": { "version": "4.2.3", "resolved": "https://registry.npmjs.org/miniget/-/miniget-4.2.3.tgz", @@ -2342,6 +2601,11 @@ "integrity": "sha512-IQdl0Q01m4LrkN1EGIE9lphov5Hy7WWlH6ulf5QdGePLlPas9p2mhgddTEHrlaXYjjFToM1/rWuwF37VF4taaA==", "requires": {} }, + "punycode": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz", + "integrity": "sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==" + }, "readable-stream": { "version": "3.6.2", "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.2.tgz", @@ -2360,6 +2624,11 @@ "readable-stream": "^3.6.0" } }, + "require-from-string": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/require-from-string/-/require-from-string-2.0.2.tgz", + "integrity": "sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==" + }, "reverbnation-scraper": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/reverbnation-scraper/-/reverbnation-scraper-2.0.0.tgz", @@ -2466,6 +2735,11 @@ "peek-readable": "^4.1.0" } }, + "stubborn-fs": { + "version": "1.2.5", + "resolved": "https://registry.npmjs.org/stubborn-fs/-/stubborn-fs-1.2.5.tgz", + "integrity": "sha512-H2N9c26eXjzL/S/K+i/RHHcFanE74dptvvjM8iwzwbVcWY/zjBbgRqF3K0DY4+OD+uTTASTBvDoxPDaPN02D7g==" + }, "tar": { "version": "6.1.15", "resolved": "https://registry.npmjs.org/tar/-/tar-6.1.15.tgz", @@ -2503,6 +2777,16 @@ "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.6.1.tgz", "integrity": "sha512-t0hLfiEKfMUoqhG+U1oid7Pva4bbDPHYfJNiB7BiIjRkj1pyC++4N3huJfqY6aRH6VTB0rvtzQwjM4K6qpfOig==" }, + "type-fest": { + "version": "3.13.1", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-3.13.1.tgz", + "integrity": "sha512-tLq3bSNx+xSpwvAJnzrK0Ep5CLNWjvFTOp71URMaAEWBfRb9nnJiBoUe0tF8bI4ZFO3omgBR6NvnbzVUT3Ly4g==" + }, + "uint8array-extras": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/uint8array-extras/-/uint8array-extras-0.3.0.tgz", + "integrity": "sha512-erJsJwQ0tKdwuqI0359U8ijkFmfiTcq25JvvzRVc1VP+2son1NJRXhxcAKJmAW3ajM8JSGAfsAXye8g4s+znxA==" + }, "undici": { "version": "5.22.1", "resolved": "https://registry.npmjs.org/undici/-/undici-5.22.1.tgz", @@ -2516,6 +2800,14 @@ "resolved": "https://registry.npmjs.org/unfetch/-/unfetch-5.0.0.tgz", "integrity": "sha512-3xM2c89siXg0nHvlmYsQ2zkLASvVMBisZm5lF3gFDqfF2xonNStDJyMpvaOBe0a1Edxmqrf2E0HBdmy9QyZaeg==" }, + "uri-js": { + "version": "4.4.1", + "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.4.1.tgz", + "integrity": "sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg==", + "requires": { + "punycode": "^2.1.0" + } + }, "util-deprecate": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", @@ -2545,6 +2837,11 @@ "resolved": "https://registry.npmjs.org/when/-/when-3.7.8.tgz", "integrity": "sha512-5cZ7mecD3eYcMiCH4wtRPA5iFJZ50BJYDfckI5RRpQiktMiYTcn0ccLTZOvcbBume+1304fQztxeNzNS9Gvrnw==" }, + "when-exit": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/when-exit/-/when-exit-2.1.2.tgz", + "integrity": "sha512-u9J+toaf3CCxCAzM/484qNAxQE75rFdVgiFEEV8Xps2gzYhf0tx73s1WXDQhkwV17E3MxRMz40m7Ekd2/121Lg==" + }, "which": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz", diff --git a/package.json b/package.json index 5f14b21e..5738be90 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "dependencies": { "@discord-player/extractor": "^4.4.1", "@discordjs/opus": "^0.9.0", + "conf": "^12.0.0", "discord-player": "^6.6.2", "discord.js": "^14.12.1", "dotenv": "^16.3.1", From 3c22e9cc5b255acf6ef1c7e467d2b76313cf2dbd Mon Sep 17 00:00:00 2001 From: TannerGabriel Date: Thu, 8 Feb 2024 21:43:02 +0100 Subject: [PATCH 3/3] Refactoring Signed-off-by: TannerGabriel --- README.md | 3 --- commands/volume.js | 2 +- index.js | 3 --- 3 files changed, 1 insertion(+), 7 deletions(-) diff --git a/README.md b/README.md index eb1020b7..b62b0cd1 100644 --- a/README.md +++ b/README.md @@ -56,9 +56,6 @@ After cloning the project and installing all dependencies, you need to add your You can change the status of your discord bot by editing the `activity` and `activityType` variables inside the `config.json` file. `activityType` needs to be set to an integer with the following [options](https://discord-api-types.dev/api/discord-api-types-v10/enum/ActivityType). -### Changing the default volume - -The default volume can be adjusted by changing the volume variable inside the `config.json` file. If you only want to adjust the volume for a single song/playlist instead, use the volume command instead. ### Starting the application diff --git a/commands/volume.js b/commands/volume.js index fa004eac..8ea628ec 100644 --- a/commands/volume.js +++ b/commands/volume.js @@ -15,7 +15,6 @@ module.exports = { ], async execute(interaction) { const {default: Conf} = await import('conf'); - const inVoiceChannel = isInVoiceChannel(interaction); await interaction.deferReply(); @@ -29,6 +28,7 @@ module.exports = { // Set the volume of the current queue const queue = useQueue(interaction.guild.id); + const inVoiceChannel = isInVoiceChannel(interaction); if (inVoiceChannel && queue && queue.currentTrack) queue.node.setVolume(volume); return void interaction.followUp({ diff --git a/index.js b/index.js index ff5f8986..955e5e44 100644 --- a/index.js +++ b/index.js @@ -121,9 +121,6 @@ client.on('interactionCreate', async interaction => { try { if (interaction.commandName == 'ban' || interaction.commandName == 'userinfo') { command.execute(interaction, client); - } else if (interaction.commandName == 'volume' || interaction.commandName == 'play') { - command.execute(interaction); - // command.execute(interaction, config) } else { command.execute(interaction); }