Skip to content

Commit

Permalink
Wire up configuration option for auto announce next song
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Mike committed Mar 2, 2024
1 parent dc8815f commit 6e43d69
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
1 change: 1 addition & 0 deletions schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
25 changes: 25 additions & 0 deletions src/commands/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down Expand Up @@ -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');

Expand All @@ -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 = '';
Expand Down
16 changes: 11 additions & 5 deletions src/services/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Check failure on line 68 in src/services/player.ts

View workflow job for this annotation

GitHub Actions / Type Check

Type 'null' is not assignable to type 'VoiceChannel'.
private queue: QueuedSong[] = [];
private queuePosition = 0;
private audioPlayer: AudioPlayer | null = null;
private nowPlaying: QueuedSong | null = null;
Expand Down Expand Up @@ -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)] : [],
});

Check failure on line 565 in src/services/player.ts

View workflow job for this annotation

GitHub Actions / Lint

Trailing spaces not allowed
//auto announce the next song if set up to

Check failure on line 566 in src/services/player.ts

View workflow job for this annotation

GitHub Actions / Lint

Comments should not begin with a lowercase character

Check failure on line 566 in src/services/player.ts

View workflow job for this annotation

GitHub Actions / Lint

Expected exception block, space or tab after '//' in comment
const settings = await getGuildSettings(this.guildId);
const {autoAnnounceNextSong} = settings;
if (autoAnnounceNextSong == true) {

Check failure on line 569 in src/services/player.ts

View workflow job for this annotation

GitHub Actions / Lint

This expression unnecessarily compares a boolean value to a boolean instead of using it directly

Check failure on line 569 in src/services/player.ts

View workflow job for this annotation

GitHub Actions / Lint

Expected '===' and instead saw '=='
await this.currentChannel.send({
embeds: this.getCurrent() ? [buildPlayingMessageEmbed(this)] : [],
});
}
}
}

Expand Down

0 comments on commit 6e43d69

Please sign in to comment.