diff --git a/schema.prisma b/schema.prisma index 556cd6b7..10cc6247 100644 --- a/schema.prisma +++ b/schema.prisma @@ -28,6 +28,7 @@ model Setting { playlistLimit Int @default(50) secondsToWaitAfterQueueEmpties Int @default(30) leaveIfNoListeners Boolean @default(true) + autoAnnounceNextSong Boolean @default(false) createdAt DateTime @default(now()) updatedAt DateTime @updatedAt } diff --git a/src/commands/config.ts b/src/commands/config.ts index 7f25a2e7..9e6c1deb 100644 --- a/src/commands/config.ts +++ b/src/commands/config.ts @@ -33,6 +33,13 @@ export default class implements Command { .setName('value') .setDescription('whether to leave when everyone else leaves') .setRequired(true))) + .addSubcommand(subcommand => subcommand + .setName('set-auto-announce-new-song') + .setDescription('set whether to announce the next song in the queue automatically') + .addBooleanOption(option => option + .setName('value') + .setDescription('whether to announce the next song in the queue automatically') + .setRequired(true))) .addSubcommand(subcommand => subcommand .setName('get') .setDescription('show all settings')); @@ -97,6 +104,23 @@ export default class implements Command { break; } + case 'set-auto-announce-next-song': { + const value = interaction.options.getBoolean('value')!; + + await prisma.setting.update({ + where: { + guildId: interaction.guild!.id, + }, + data: { + autoAnnounceNextSong: value, + }, + }); + + await interaction.reply('👍 auto announce setting updated'); + + break; + } + case 'get': { const embed = new EmbedBuilder().setTitle('Config'); @@ -108,6 +132,7 @@ export default class implements Command { ? 'never leave' : `${config.secondsToWaitAfterQueueEmpties}s`, 'Leave if there are no listeners': config.leaveIfNoListeners ? 'yes' : 'no', + 'Auto announce next song in queue': config.autoAnnounceNextSong ? 'yes' : 'no', }; let description = ''; diff --git a/src/services/player.ts b/src/services/player.ts index 865eb7b4..ab31b328 100644 --- a/src/services/player.ts +++ b/src/services/player.ts @@ -65,8 +65,8 @@ export default class { public guildId: string; public loopCurrentSong = false; public loopCurrentQueue = false; - public currentChannel: VoiceChannel; - private queue: QueuedSong[] = []; + public currentChannel: VoiceChannel = null; + private queue: QueuedSong[] = []; private queuePosition = 0; private audioPlayer: AudioPlayer | null = null; private nowPlaying: QueuedSong | null = null; @@ -562,9 +562,15 @@ export default class { if (newState.status === AudioPlayerStatus.Idle && this.status === STATUS.PLAYING) { await this.forward(1); - await this.currentChannel.send({ - embeds: this.getCurrent() ? [buildPlayingMessageEmbed(this)] : [], - }); + + //auto announce the next song if set up to + const settings = await getGuildSettings(this.guildId); + const {autoAnnounceNextSong} = settings; + if (autoAnnounceNextSong == true) { + await this.currentChannel.send({ + embeds: this.getCurrent() ? [buildPlayingMessageEmbed(this)] : [], + }); + } } }