mirror of
https://github.com/BluemediaDev/muse.git
synced 2025-06-27 17:22:42 +02:00
Create guild settings if not found (#911)
Co-authored-by: Max Isom <codetheweb@users.noreply.github.com>
This commit is contained in:
parent
6926e39c56
commit
02ee8aefc8
7 changed files with 25 additions and 27 deletions
|
@ -8,20 +8,20 @@ import {REST} from '@discordjs/rest';
|
|||
import {Setting} from '@prisma/client';
|
||||
import registerCommandsOnGuild from '../utils/register-commands-on-guild.js';
|
||||
|
||||
export async function createGuildSettings(guild: Guild): Promise<Setting> {
|
||||
export async function createGuildSettings(guildId: string): Promise<Setting> {
|
||||
return prisma.setting.upsert({
|
||||
where: {
|
||||
guildId: guild.id,
|
||||
guildId,
|
||||
},
|
||||
create: {
|
||||
guildId: guild.id,
|
||||
guildId,
|
||||
},
|
||||
update: {},
|
||||
});
|
||||
}
|
||||
|
||||
export default async (guild: Guild): Promise<void> => {
|
||||
await createGuildSettings(guild);
|
||||
await createGuildSettings(guild.id);
|
||||
|
||||
const config = container.get<Config>(TYPES.Config);
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ 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';
|
||||
import {getGuildSettings} from '../utils/get-guild-settings';
|
||||
|
||||
export default async (oldState: VoiceState, _: VoiceState): Promise<void> => {
|
||||
const playerManager = container.get<PlayerManager>(TYPES.Managers.Player);
|
||||
|
@ -12,11 +12,7 @@ export default async (oldState: VoiceState, _: VoiceState): Promise<void> => {
|
|||
|
||||
if (player.voiceConnection) {
|
||||
const voiceChannel: VoiceChannel = oldState.guild.channels.cache.get(player.voiceConnection.joinConfig.channelId!) as VoiceChannel;
|
||||
const settings = await prisma.setting.findUnique({where: {guildId: player.guildId}});
|
||||
|
||||
if (!settings) {
|
||||
throw new Error('Could not find settings for guild');
|
||||
}
|
||||
const settings = await getGuildSettings(player.guildId);
|
||||
|
||||
const {leaveIfNoListeners} = settings;
|
||||
if (!voiceChannel || (getSizeWithoutBots(voiceChannel) === 0 && leaveIfNoListeners)) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue