aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMax Isom <[email protected]>2022-01-29 12:06:11 -0500
committerMax Isom <[email protected]>2022-01-29 12:06:11 -0500
commit6eb704c5b4f7a92e254f14eab962ac8bc76a081b (patch)
treec39c5ecd3fa31c4c17cf87a2747800660575a56c /src
parentd6c9d4b1128c5cddda74b3a84575388670edf221 (diff)
downloadmuse-6eb704c5b4f7a92e254f14eab962ac8bc76a081b.tar.xz
muse-6eb704c5b4f7a92e254f14eab962ac8bc76a081b.zip
Fix resume playback bug
Diffstat (limited to 'src')
-rw-r--r--src/commands/play.ts38
-rw-r--r--src/utils/log-banner.ts1
2 files changed, 36 insertions, 3 deletions
diff --git a/src/commands/play.ts b/src/commands/play.ts
index e8d565c..2d2fc6d 100644
--- a/src/commands/play.ts
+++ b/src/commands/play.ts
@@ -1,4 +1,4 @@
-import {AutocompleteInteraction, CommandInteraction} from 'discord.js';
+import {AutocompleteInteraction, CommandInteraction, GuildMember} from 'discord.js';
import {URL} from 'url';
import {SlashCommandBuilder} from '@discordjs/builders';
import {inject, injectable} from 'inversify';
@@ -10,6 +10,10 @@ import getYouTubeAndSpotifySuggestionsFor from '../utils/get-youtube-and-spotify
import KeyValueCacheProvider from '../services/key-value-cache.js';
import {ONE_HOUR_IN_SECONDS} from '../utils/constants.js';
import AddQueryToQueue from '../services/add-query-to-queue.js';
+import PlayerManager from '../managers/player.js';
+import {STATUS} from '../services/player.js';
+import {buildPlayingMessageEmbed} from '../utils/build-embed.js';
+import {getMemberVoiceChannel, getMostPopularVoiceChannel} from '../utils/channels.js';
@injectable()
export default class implements Command {
@@ -33,18 +37,46 @@ export default class implements Command {
private readonly spotify: Spotify;
private readonly cache: KeyValueCacheProvider;
private readonly addQueryToQueue: AddQueryToQueue;
+ private readonly playerManager: PlayerManager;
- constructor(@inject(TYPES.ThirdParty) thirdParty: ThirdParty, @inject(TYPES.KeyValueCache) cache: KeyValueCacheProvider, @inject(TYPES.Services.AddQueryToQueue) addQueryToQueue: AddQueryToQueue) {
+ constructor(@inject(TYPES.ThirdParty) thirdParty: ThirdParty, @inject(TYPES.KeyValueCache) cache: KeyValueCacheProvider, @inject(TYPES.Services.AddQueryToQueue) addQueryToQueue: AddQueryToQueue, @inject(TYPES.Managers.Player) playerManager: PlayerManager) {
this.spotify = thirdParty.spotify;
this.cache = cache;
this.addQueryToQueue = addQueryToQueue;
+ this.playerManager = playerManager;
}
// eslint-disable-next-line complexity
public async execute(interaction: CommandInteraction): Promise<void> {
+ const query = interaction.options.getString('query');
+
+ const player = this.playerManager.get(interaction.guild!.id);
+ const [targetVoiceChannel] = getMemberVoiceChannel(interaction.member as GuildMember) ?? getMostPopularVoiceChannel(interaction.guild!);
+
+ if (!query) {
+ if (player.status === STATUS.PLAYING) {
+ throw new Error('already playing, give me a song name');
+ }
+
+ // Must be resuming play
+ if (!player.getCurrent()) {
+ throw new Error('nothing to play');
+ }
+
+ await player.connect(targetVoiceChannel);
+ await player.play();
+
+ await interaction.reply({
+ content: 'the stop-and-go light is now green',
+ embeds: [buildPlayingMessageEmbed(player)],
+ });
+
+ return;
+ }
+
await this.addQueryToQueue.addToQueue({
interaction,
- query: interaction.options.getString('query')!.trim(),
+ query: query.trim(),
addToFrontOfQueue: interaction.options.getBoolean('immediate') ?? false,
shuffleAdditions: interaction.options.getBoolean('shuffle') ?? false,
});
diff --git a/src/utils/log-banner.ts b/src/utils/log-banner.ts
index 0ad6466..9cde988 100644
--- a/src/utils/log-banner.ts
+++ b/src/utils/log-banner.ts
@@ -9,6 +9,7 @@ const logBanner = () => {
paypalUser: 'codetheweb',
githubSponsor: 'codetheweb',
madeByPrefix: 'Made with 🎶 by ',
+ buildDate: process.env.BUILD_DATE ? new Date(process.env.BUILD_DATE) : undefined,
}).join('\n'));
console.log('\n');
};