From aae98255b19e83ce78aaea389627dbae504910f8 Mon Sep 17 00:00:00 2001 From: Yitong Xiao Date: Sun, 15 Sep 2024 17:53:05 -0400 Subject: [PATCH 01/11] feat: automatically turn down volume when people talks --- .env.example | 1 + CHANGELOG.md | 6 ++++ README.md | 7 +++++ package.json | 2 +- src/managers/player.ts | 7 +++-- src/services/config.ts | 4 +++ src/services/player.ts | 67 +++++++++++++++++++++++++++++++++++++++++- 7 files changed, 90 insertions(+), 4 deletions(-) diff --git a/.env.example b/.env.example index cb4fc19..98c2139 100644 --- a/.env.example +++ b/.env.example @@ -18,3 +18,4 @@ SPOTIFY_CLIENT_SECRET= # BOT_ACTIVITY_TYPE= # BOT_ACTIVITY_URL= # BOT_ACTIVITY= +# TURN_DOWN_VOLUME_WHEN_PEOPLE_SPEAK= \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 4fd8113..84bde24 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +## [2.9.5] - 2024-09-15 + +### Added +- An optional `TURN_DOWN_VOLUME_WHEN_PEOPLE_SPEAK` config to automatically turn + down the volume when people are speaking in the channel +- An optional `TURN_DOWN_VOLUME_WHEN_PEOPLE_SPEAK_TARGET` config to set the target volume when people are speaking in the channel ## [2.9.4] - 2024-08-28 diff --git a/README.md b/README.md index 7fec19f..5fe0ffc 100644 --- a/README.md +++ b/README.md @@ -141,3 +141,10 @@ In the default state, Muse has the status "Online" and the text "Listening to Mu ### Bot-wide commands If you have Muse running in a lot of guilds (10+) you may want to switch to registering commands bot-wide rather than for each guild. (The downside to this is that command updates can take up to an hour to propagate.) To do this, set the environment variable `REGISTER_COMMANDS_ON_BOT` to `true`. + +### Automatically turn down volume when people speak + +You can let the bot automatically turn down the volume when people are speaking +in the channel though environment variable: +- `TURN_DOWN_VOLUME_WHEN_PEOPLE_SPEAK=true` +- `TURN_DOWN_VOLUME_WHEN_PEOPLE_SPEAK_TARGET=70` (optional, default is 70%) diff --git a/package.json b/package.json index 2a2b89a..d61839f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "muse", - "version": "2.9.4", + "version": "2.9.5", "description": "🎧 a self-hosted Discord music bot that doesn't suck ", "repository": "git@github.com:museofficial/muse.git", "author": "Max Isom ", diff --git a/src/managers/player.ts b/src/managers/player.ts index 420cf48..577d9f3 100644 --- a/src/managers/player.ts +++ b/src/managers/player.ts @@ -2,22 +2,25 @@ import {inject, injectable} from 'inversify'; import {TYPES} from '../types.js'; import Player from '../services/player.js'; import FileCacheProvider from '../services/file-cache.js'; +import Config from '../services/config.js'; @injectable() export default class { private readonly guildPlayers: Map; private readonly fileCache: FileCacheProvider; + private readonly config: Config; - constructor(@inject(TYPES.FileCache) fileCache: FileCacheProvider) { + constructor(@inject(TYPES.FileCache) fileCache: FileCacheProvider, @inject(TYPES.Config) config: Config) { this.guildPlayers = new Map(); this.fileCache = fileCache; + this.config = config; } get(guildId: string): Player { let player = this.guildPlayers.get(guildId); if (!player) { - player = new Player(this.fileCache, guildId); + player = new Player(this.fileCache, guildId, this.config); this.guildPlayers.set(guildId, player); } diff --git a/src/services/config.ts b/src/services/config.ts index b6b9aea..ef2a7c9 100644 --- a/src/services/config.ts +++ b/src/services/config.ts @@ -14,6 +14,8 @@ const CONFIG_MAP = { YOUTUBE_API_KEY: process.env.YOUTUBE_API_KEY, SPOTIFY_CLIENT_ID: process.env.SPOTIFY_CLIENT_ID, SPOTIFY_CLIENT_SECRET: process.env.SPOTIFY_CLIENT_SECRET, + TURN_DOWN_VOLUME_WHEN_PEOPLE_SPEAK: process.env.TURN_DOWN_VOLUME_WHEN_PEOPLE_SPEAK === 'true', + TURN_DOWN_VOLUME_WHEN_PEOPLE_SPEAK_TARGET: process.env.TURN_DOWN_VOLUME_WHEN_PEOPLE_SPEAK_TARGET ?? 20, REGISTER_COMMANDS_ON_BOT: process.env.REGISTER_COMMANDS_ON_BOT === 'true', DATA_DIR, CACHE_DIR: path.join(DATA_DIR, 'cache'), @@ -43,6 +45,8 @@ export default class Config { readonly DATA_DIR!: string; readonly CACHE_DIR!: string; readonly CACHE_LIMIT_IN_BYTES!: number; + readonly TURN_DOWN_VOLUME_WHEN_PEOPLE_SPEAK!: boolean; + readonly TURN_DOWN_VOLUME_WHEN_PEOPLE_SPEAK_TARGET!: number; readonly BOT_STATUS!: PresenceStatusData; readonly BOT_ACTIVITY_TYPE!: Exclude; readonly BOT_ACTIVITY_URL!: string; diff --git a/src/services/player.ts b/src/services/player.ts index 5e284a6..00081ca 100644 --- a/src/services/player.ts +++ b/src/services/player.ts @@ -20,6 +20,7 @@ import FileCacheProvider from './file-cache.js'; import debug from '../utils/debug.js'; import {getGuildSettings} from '../utils/get-guild-settings.js'; import {buildPlayingMessageEmbed} from '../utils/build-embed.js'; +import Config from './config.js'; export enum MediaSource { Youtube, @@ -82,9 +83,13 @@ export default class { private readonly fileCache: FileCacheProvider; private disconnectTimer: NodeJS.Timeout | null = null; - constructor(fileCache: FileCacheProvider, guildId: string) { + private readonly channelToSpeakingUsers: Map> = new Map(); + private readonly config: Config; + + constructor(fileCache: FileCacheProvider, guildId: string, config: Config) { this.fileCache = fileCache; this.guildId = guildId; + this.config = config; } async connect(channel: VoiceChannel): Promise { @@ -96,6 +101,7 @@ export default class { this.voiceConnection = joinVoiceChannel({ channelId: channel.id, guildId: channel.guild.id, + selfDeaf: false, adapterCreator: channel.guild.voiceAdapterCreator as DiscordGatewayAdapterCreator, }); @@ -115,6 +121,9 @@ export default class { /* eslint-enable @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call */ this.currentChannel = channel; + if (newState.status === VoiceConnectionStatus.Ready) { + this.registerVoiceActivityListener(); + } }); } @@ -302,6 +311,62 @@ export default class { } } + registerVoiceActivityListener(): void { + if (!this.config.TURN_DOWN_VOLUME_WHEN_PEOPLE_SPEAK || !this.voiceConnection) { + return; + } + + this.voiceConnection.receiver.speaking.on('start', (userId: string) => { + if (!this.currentChannel) { + return; + } + + const member = this.currentChannel.members.get(userId); + const channelId = this.currentChannel?.id; + + if (member) { + if (!this.channelToSpeakingUsers.has(channelId)) { + this.channelToSpeakingUsers.set(channelId, new Set()); + } + + this.channelToSpeakingUsers.get(channelId)?.add(member.id); + } + + this.suppressVoiceWhenPeopleAreSpeaking(); + }); + + this.voiceConnection.receiver.speaking.on('end', (userId: string) => { + if (!this.currentChannel) { + return; + } + + const member = this.currentChannel.members.get(userId); + const channelId = this.currentChannel.id; + if (member) { + if (!this.channelToSpeakingUsers.has(channelId)) { + this.channelToSpeakingUsers.set(channelId, new Set()); + } + + this.channelToSpeakingUsers.get(channelId)?.delete(member.id); + } + + this.suppressVoiceWhenPeopleAreSpeaking(); + }); + } + + suppressVoiceWhenPeopleAreSpeaking(): void { + if (!this.currentChannel) { + return; + } + + const speakingUsers = this.channelToSpeakingUsers.get(this.currentChannel.id); + if (speakingUsers && speakingUsers.size > 0) { + this.setVolume(this.config.TURN_DOWN_VOLUME_WHEN_PEOPLE_SPEAK_TARGET); + } else { + this.setVolume(this.defaultVolume); + } + } + canGoForward(skip: number) { return (this.queuePosition + skip - 1) < this.queue.length; } From d6364ac2aa09aa8b8ac6a48e56682d7f19775846 Mon Sep 17 00:00:00 2001 From: Hazzajenko Date: Fri, 1 Nov 2024 17:31:06 +1100 Subject: [PATCH 02/11] Update CHANGELOG for version 2.9.5 release. Updated env variables with discord commands. --- CHANGELOG.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 84bde24..b2ae2f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,12 +5,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] -## [2.9.5] - 2024-09-15 ### Added -- An optional `TURN_DOWN_VOLUME_WHEN_PEOPLE_SPEAK` config to automatically turn - down the volume when people are speaking in the channel -- An optional `TURN_DOWN_VOLUME_WHEN_PEOPLE_SPEAK_TARGET` config to set the target volume when people are speaking in the channel +- New `/config set-reduce-vol-when-voice` command to automatically turn down the volume when people are speaking in the channel +- New `/config set-reduce-vol-when-voice-target` command to set the target volume percentage (0-100) when people are speaking in the channel + +## [2.9.5] - 2024-10-29 +- Dependency update +- Pull request #1040 merged (Used incorrect PR number, apoligies) ## [2.9.4] - 2024-08-28 From b42f27eba9db787c1986e9d2146f742157905e91 Mon Sep 17 00:00:00 2001 From: Hazzajenko Date: Fri, 1 Nov 2024 17:36:01 +1100 Subject: [PATCH 03/11] Added commands to set whether to reduce the volume when people speak and to set the target volume. --- src/commands/config.ts | 51 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/src/commands/config.ts b/src/commands/config.ts index 91b2578..01d9fe9 100644 --- a/src/commands/config.ts +++ b/src/commands/config.ts @@ -40,6 +40,22 @@ export default class implements Command { .setName('value') .setDescription('whether bot responses to queue additions are only displayed to the requester') .setRequired(true))) + .addSubcommand(subcommand => subcommand + .setName('set-reduce-vol-when-voice') + .setDescription('set whether to turn down the volume when people speak') + .addBooleanOption(option => option + .setName('value') + .setDescription('whether to turn down the volume when people speak') + .setRequired(true))) + .addSubcommand(subcommand => subcommand + .setName('set-reduce-vol-when-voice-target') + .setDescription('set the target volume when people speak') + .addIntegerOption(option => option + .setName('volume') + .setDescription('volume percentage (0 is muted, 100 is max & default)') + .setMinValue(0) + .setMaxValue(100) + .setRequired(true))) .addSubcommand(subcommand => subcommand .setName('set-auto-announce-next-song') .setDescription('set whether to announce the next song in the queue automatically') @@ -197,6 +213,40 @@ export default class implements Command { break; } + case 'set-reduce-vol-when-voice': { + const value = interaction.options.getBoolean('value')!; + + await prisma.setting.update({ + where: { + guildId: interaction.guild!.id, + }, + data: { + turnDownVolumeWhenPeopleSpeak: value, + }, + }); + + await interaction.reply('👍 turn down volume setting updated'); + + break; + } + + case 'set-reduce-vol-when-voice-target': { + const value = interaction.options.getInteger('volume')!; + + await prisma.setting.update({ + where: { + guildId: interaction.guild!.id, + }, + data: { + turnDownVolumeWhenPeopleSpeakTarget: value, + }, + }); + + await interaction.reply('👍 turn down volume target setting updated'); + + break; + } + case 'get': { const embed = new EmbedBuilder().setTitle('Config'); @@ -212,6 +262,7 @@ export default class implements Command { 'Add to queue reponses show for requester only': config.autoAnnounceNextSong ? 'yes' : 'no', 'Default Volume': config.defaultVolume, 'Default queue page size': config.defaultQueuePageSize, + 'Reduce volume when people speak': config.turnDownVolumeWhenPeopleSpeak ? 'yes' : 'no', }; let description = ''; From 53af0074fccad9ddb888e121ecebc497f20aab7f Mon Sep 17 00:00:00 2001 From: Hazzajenko Date: Fri, 1 Nov 2024 17:38:23 +1100 Subject: [PATCH 04/11] Update dotenv line to latest version of muse. Removed obsolete TURN_DOWN_VOLUME_WHEN_PEOPLE_SPEAK and TURN_DOWN_VOLUME_WHEN_PEOPLE_SPEAK_TARGET environment variables and corresponding class properties as we will use the discord commands instead. --- src/services/config.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/services/config.ts b/src/services/config.ts index ef2a7c9..019df07 100644 --- a/src/services/config.ts +++ b/src/services/config.ts @@ -5,7 +5,7 @@ import path from 'path'; import xbytes from 'xbytes'; import {ConditionalKeys} from 'type-fest'; import {ActivityType, PresenceStatusData} from 'discord.js'; -dotenv.config(); +dotenv.config({path: process.env.ENV_FILE ?? path.resolve(process.cwd(), '.env')}); export const DATA_DIR = path.resolve(process.env.DATA_DIR ? process.env.DATA_DIR : './data'); @@ -14,8 +14,6 @@ const CONFIG_MAP = { YOUTUBE_API_KEY: process.env.YOUTUBE_API_KEY, SPOTIFY_CLIENT_ID: process.env.SPOTIFY_CLIENT_ID, SPOTIFY_CLIENT_SECRET: process.env.SPOTIFY_CLIENT_SECRET, - TURN_DOWN_VOLUME_WHEN_PEOPLE_SPEAK: process.env.TURN_DOWN_VOLUME_WHEN_PEOPLE_SPEAK === 'true', - TURN_DOWN_VOLUME_WHEN_PEOPLE_SPEAK_TARGET: process.env.TURN_DOWN_VOLUME_WHEN_PEOPLE_SPEAK_TARGET ?? 20, REGISTER_COMMANDS_ON_BOT: process.env.REGISTER_COMMANDS_ON_BOT === 'true', DATA_DIR, CACHE_DIR: path.join(DATA_DIR, 'cache'), @@ -45,8 +43,6 @@ export default class Config { readonly DATA_DIR!: string; readonly CACHE_DIR!: string; readonly CACHE_LIMIT_IN_BYTES!: number; - readonly TURN_DOWN_VOLUME_WHEN_PEOPLE_SPEAK!: boolean; - readonly TURN_DOWN_VOLUME_WHEN_PEOPLE_SPEAK_TARGET!: number; readonly BOT_STATUS!: PresenceStatusData; readonly BOT_ACTIVITY_TYPE!: Exclude; readonly BOT_ACTIVITY_URL!: string; From a87bf60fe540836c5c7619e8cf33dbe437c235c1 Mon Sep 17 00:00:00 2001 From: Hazzajenko Date: Fri, 1 Nov 2024 17:39:42 +1100 Subject: [PATCH 05/11] Updated Dockerfile to latest version of muse. --- Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile b/Dockerfile index 328c7d9..82f051f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -52,5 +52,6 @@ ENV DATA_DIR=/data ENV NODE_ENV=production ENV COMMIT_HASH=$COMMIT_HASH ENV BUILD_DATE=$BUILD_DATE +ENV ENV_FILE=/config CMD ["tini", "--", "node", "--enable-source-maps", "dist/scripts/migrate-and-start.js"] From 27b1a25e561585ef8f94312894adff9622030adc Mon Sep 17 00:00:00 2001 From: Hazzajenko Date: Fri, 1 Nov 2024 17:41:07 +1100 Subject: [PATCH 06/11] Remove obsolete TURN_DOWN_VOLUME_WHEN_PEOPLE_SPEAK from .env.example --- .env.example | 1 - 1 file changed, 1 deletion(-) diff --git a/.env.example b/.env.example index 98c2139..cb4fc19 100644 --- a/.env.example +++ b/.env.example @@ -18,4 +18,3 @@ SPOTIFY_CLIENT_SECRET= # BOT_ACTIVITY_TYPE= # BOT_ACTIVITY_URL= # BOT_ACTIVITY= -# TURN_DOWN_VOLUME_WHEN_PEOPLE_SPEAK= \ No newline at end of file From ba3f1d60c3c1edcfc057005ea617a22519d75304 Mon Sep 17 00:00:00 2001 From: Hazzajenko Date: Fri, 1 Nov 2024 17:42:09 +1100 Subject: [PATCH 07/11] Remove Config injection from PlayerManager as we are getting the values from prisma. --- src/managers/player.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/managers/player.ts b/src/managers/player.ts index 577d9f3..420cf48 100644 --- a/src/managers/player.ts +++ b/src/managers/player.ts @@ -2,25 +2,22 @@ import {inject, injectable} from 'inversify'; import {TYPES} from '../types.js'; import Player from '../services/player.js'; import FileCacheProvider from '../services/file-cache.js'; -import Config from '../services/config.js'; @injectable() export default class { private readonly guildPlayers: Map; private readonly fileCache: FileCacheProvider; - private readonly config: Config; - constructor(@inject(TYPES.FileCache) fileCache: FileCacheProvider, @inject(TYPES.Config) config: Config) { + constructor(@inject(TYPES.FileCache) fileCache: FileCacheProvider) { this.guildPlayers = new Map(); this.fileCache = fileCache; - this.config = config; } get(guildId: string): Player { let player = this.guildPlayers.get(guildId); if (!player) { - player = new Player(this.fileCache, guildId, this.config); + player = new Player(this.fileCache, guildId); this.guildPlayers.set(guildId, player); } From 825c9a0c530d39b2b1c2f2f02904a866b7398001 Mon Sep 17 00:00:00 2001 From: Hazzajenko Date: Fri, 1 Nov 2024 17:43:39 +1100 Subject: [PATCH 08/11] Refactor player service to use getGuildSettings instead of passing in the config. --- src/services/player.ts | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/services/player.ts b/src/services/player.ts index 00081ca..b833022 100644 --- a/src/services/player.ts +++ b/src/services/player.ts @@ -20,7 +20,7 @@ import FileCacheProvider from './file-cache.js'; import debug from '../utils/debug.js'; import {getGuildSettings} from '../utils/get-guild-settings.js'; import {buildPlayingMessageEmbed} from '../utils/build-embed.js'; -import Config from './config.js'; +import {Setting} from '@prisma/client'; export enum MediaSource { Youtube, @@ -84,12 +84,10 @@ export default class { private disconnectTimer: NodeJS.Timeout | null = null; private readonly channelToSpeakingUsers: Map> = new Map(); - private readonly config: Config; - constructor(fileCache: FileCacheProvider, guildId: string, config: Config) { + constructor(fileCache: FileCacheProvider, guildId: string) { this.fileCache = fileCache; this.guildId = guildId; - this.config = config; } async connect(channel: VoiceChannel): Promise { @@ -105,6 +103,8 @@ export default class { adapterCreator: channel.guild.voiceAdapterCreator as DiscordGatewayAdapterCreator, }); + const guildSettings = await getGuildSettings(this.guildId); + // Workaround to disable keepAlive this.voiceConnection.on('stateChange', (oldState, newState) => { /* eslint-disable @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call */ @@ -122,7 +122,7 @@ export default class { this.currentChannel = channel; if (newState.status === VoiceConnectionStatus.Ready) { - this.registerVoiceActivityListener(); + this.registerVoiceActivityListener(guildSettings); } }); } @@ -311,8 +311,9 @@ export default class { } } - registerVoiceActivityListener(): void { - if (!this.config.TURN_DOWN_VOLUME_WHEN_PEOPLE_SPEAK || !this.voiceConnection) { + registerVoiceActivityListener(guildSettings: Setting) { + const {turnDownVolumeWhenPeopleSpeak, turnDownVolumeWhenPeopleSpeakTarget} = guildSettings; + if (!turnDownVolumeWhenPeopleSpeak || !this.voiceConnection) { return; } @@ -332,7 +333,7 @@ export default class { this.channelToSpeakingUsers.get(channelId)?.add(member.id); } - this.suppressVoiceWhenPeopleAreSpeaking(); + this.suppressVoiceWhenPeopleAreSpeaking(turnDownVolumeWhenPeopleSpeakTarget); }); this.voiceConnection.receiver.speaking.on('end', (userId: string) => { @@ -350,18 +351,18 @@ export default class { this.channelToSpeakingUsers.get(channelId)?.delete(member.id); } - this.suppressVoiceWhenPeopleAreSpeaking(); + this.suppressVoiceWhenPeopleAreSpeaking(turnDownVolumeWhenPeopleSpeakTarget); }); } - suppressVoiceWhenPeopleAreSpeaking(): void { + suppressVoiceWhenPeopleAreSpeaking(turnDownVolumeWhenPeopleSpeakTarget: number): void { if (!this.currentChannel) { return; } const speakingUsers = this.channelToSpeakingUsers.get(this.currentChannel.id); if (speakingUsers && speakingUsers.size > 0) { - this.setVolume(this.config.TURN_DOWN_VOLUME_WHEN_PEOPLE_SPEAK_TARGET); + this.setVolume(turnDownVolumeWhenPeopleSpeakTarget); } else { this.setVolume(this.defaultVolume); } From fe30673e235404a1c11ff6564dc2fc5a72a82da8 Mon Sep 17 00:00:00 2001 From: Hazzajenko Date: Fri, 1 Nov 2024 17:45:01 +1100 Subject: [PATCH 09/11] Update README.md to the latest version of muse. Changed the section to mention the discord commands rather than the env variables. --- README.md | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 5fe0ffc..31b75e5 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,8 @@ docker run -it -v "$(pwd)/data":/data -e DISCORD_TOKEN='' -e SPOTIFY_CLIENT_ID=' This starts Muse and creates a data directory in your current directory. +You can also store your tokens in an environment file and make it available to your container. By default, the container will look for a `/config` environment file. You can customize this path with the `ENV_FILE` environment variable to use with, for example, [docker secrets](https://docs.docker.com/engine/swarm/secrets/). + **Docker Compose**: ```yaml @@ -144,7 +146,9 @@ If you have Muse running in a lot of guilds (10+) you may want to switch to regi ### Automatically turn down volume when people speak -You can let the bot automatically turn down the volume when people are speaking -in the channel though environment variable: -- `TURN_DOWN_VOLUME_WHEN_PEOPLE_SPEAK=true` -- `TURN_DOWN_VOLUME_WHEN_PEOPLE_SPEAK_TARGET=70` (optional, default is 70%) +You can configure the bot to automatically turn down the volume when people are speaking in the channel using the following commands: + +- `/config set-reduce-vol-when-voice true` - Enable automatic volume reduction +- `/config set-reduce-vol-when-voice false` - Disable automatic volume reduction +- `/config set-reduce-vol-when-voice-target ` - Set the target volume percentage when people speak (0-100, default is 70) + From 27d20a59d8f57011c6eca9652f687c1c58a54050 Mon Sep 17 00:00:00 2001 From: Hazzajenko Date: Fri, 1 Nov 2024 17:45:55 +1100 Subject: [PATCH 10/11] Added `turnDownVolumeWhenPeopleSpeak` and `turnDownVolumeWhenPeopleSpeakTarget` fields to the `Setting` model in Prisma --- schema.prisma | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/schema.prisma b/schema.prisma index 65c3aee..4723196 100644 --- a/schema.prisma +++ b/schema.prisma @@ -24,16 +24,18 @@ model KeyValueCache { } model Setting { - guildId String @id - playlistLimit Int @default(50) - secondsToWaitAfterQueueEmpties Int @default(30) - leaveIfNoListeners Boolean @default(true) - queueAddResponseEphemeral Boolean @default(false) - autoAnnounceNextSong Boolean @default(false) - defaultVolume Int @default(100) - defaultQueuePageSize Int @default(10) - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt + guildId String @id + playlistLimit Int @default(50) + secondsToWaitAfterQueueEmpties Int @default(30) + leaveIfNoListeners Boolean @default(true) + queueAddResponseEphemeral Boolean @default(false) + autoAnnounceNextSong Boolean @default(false) + defaultVolume Int @default(100) + defaultQueuePageSize Int @default(10) + turnDownVolumeWhenPeopleSpeak Boolean @default(false) + turnDownVolumeWhenPeopleSpeakTarget Int @default(20) + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt } model FavoriteQuery { From 84419358651f2c8151fe568596be9f150ce38205 Mon Sep 17 00:00:00 2001 From: Hazzajenko Date: Fri, 1 Nov 2024 17:47:22 +1100 Subject: [PATCH 11/11] Add migration for prisma db changes --- .../migration.sql | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 migrations/20241031084730_add_turn_down_volume_when_people_speak/migration.sql diff --git a/migrations/20241031084730_add_turn_down_volume_when_people_speak/migration.sql b/migrations/20241031084730_add_turn_down_volume_when_people_speak/migration.sql new file mode 100644 index 0000000..07be5d9 --- /dev/null +++ b/migrations/20241031084730_add_turn_down_volume_when_people_speak/migration.sql @@ -0,0 +1,21 @@ +-- RedefineTables +PRAGMA foreign_keys=OFF; +CREATE TABLE "new_Setting" ( + "guildId" TEXT NOT NULL PRIMARY KEY, + "playlistLimit" INTEGER NOT NULL DEFAULT 50, + "secondsToWaitAfterQueueEmpties" INTEGER NOT NULL DEFAULT 30, + "leaveIfNoListeners" BOOLEAN NOT NULL DEFAULT true, + "queueAddResponseEphemeral" BOOLEAN NOT NULL DEFAULT false, + "autoAnnounceNextSong" BOOLEAN NOT NULL DEFAULT false, + "defaultVolume" INTEGER NOT NULL DEFAULT 100, + "defaultQueuePageSize" INTEGER NOT NULL DEFAULT 10, + "turnDownVolumeWhenPeopleSpeak" BOOLEAN NOT NULL DEFAULT false, + "turnDownVolumeWhenPeopleSpeakTarget" INTEGER NOT NULL DEFAULT 20, + "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" DATETIME NOT NULL +); +INSERT INTO "new_Setting" ("autoAnnounceNextSong", "createdAt", "defaultQueuePageSize", "defaultVolume", "guildId", "leaveIfNoListeners", "playlistLimit", "queueAddResponseEphemeral", "secondsToWaitAfterQueueEmpties", "updatedAt") SELECT "autoAnnounceNextSong", "createdAt", "defaultQueuePageSize", "defaultVolume", "guildId", "leaveIfNoListeners", "playlistLimit", "queueAddResponseEphemeral", "secondsToWaitAfterQueueEmpties", "updatedAt" FROM "Setting"; +DROP TABLE "Setting"; +ALTER TABLE "new_Setting" RENAME TO "Setting"; +PRAGMA foreign_key_check; +PRAGMA foreign_keys=ON;