aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHazzajenko <[email protected]>2024-11-01 17:43:39 +1100
committerHazzajenko <[email protected]>2024-11-01 17:43:39 +1100
commit825c9a0c530d39b2b1c2f2f02904a866b7398001 (patch)
treeaa0238a26a7a26a50e8b5ff55d62f6252c1d42b5 /src
parentba3f1d60c3c1edcfc057005ea617a22519d75304 (diff)
downloadmuse-825c9a0c530d39b2b1c2f2f02904a866b7398001.tar.xz
muse-825c9a0c530d39b2b1c2f2f02904a866b7398001.zip
Refactor player service to use getGuildSettings instead of passing in the config.
Diffstat (limited to 'src')
-rw-r--r--src/services/player.ts23
1 files 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<string, Set<string>> = 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<void> {
@@ -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);
}