mirror of
https://github.com/BluemediaDev/muse.git
synced 2025-06-27 17:22:42 +02:00
Configurable voice channel leave behavior (#514)
Co-authored-by: Max Isom <hi@maxisom.me>
This commit is contained in:
parent
8e5b3cfa43
commit
4dbb55a721
8 changed files with 123 additions and 11 deletions
|
@ -3,15 +3,23 @@ import container from '../inversify.config.js';
|
|||
import {TYPES} from '../types.js';
|
||||
import PlayerManager from '../managers/player.js';
|
||||
import {getSizeWithoutBots} from '../utils/channels.js';
|
||||
import {prisma} from '../utils/db.js';
|
||||
|
||||
export default (oldState: VoiceState, _: VoiceState): void => {
|
||||
export default async (oldState: VoiceState, _: VoiceState): Promise<void> => {
|
||||
const playerManager = container.get<PlayerManager>(TYPES.Managers.Player);
|
||||
|
||||
const player = playerManager.get(oldState.guild.id);
|
||||
|
||||
if (player.voiceConnection) {
|
||||
const voiceChannel: VoiceChannel = oldState.guild.channels.cache.get(player.voiceConnection.joinConfig.channelId!) as VoiceChannel;
|
||||
if (!voiceChannel || getSizeWithoutBots(voiceChannel) === 0) {
|
||||
const settings = await prisma.setting.findUnique({where: {guildId: player.guildId}});
|
||||
|
||||
if (!settings) {
|
||||
throw new Error('Could not find settings for guild');
|
||||
}
|
||||
|
||||
const {leaveIfNoListeners} = settings;
|
||||
if (!voiceChannel || (getSizeWithoutBots(voiceChannel) === 0 && leaveIfNoListeners)) {
|
||||
player.disconnect();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue