mirror of
https://github.com/BluemediaGER/muse.git
synced 2024-11-10 03:55:29 +01:00
Fix resume playback bug
This commit is contained in:
parent
d6c9d4b112
commit
6eb704c5b4
|
@ -35,7 +35,11 @@ COPY --from=builder /usr/app/migrations migrations
|
||||||
|
|
||||||
RUN yarn prisma generate
|
RUN yarn prisma generate
|
||||||
|
|
||||||
|
ARG COMMIT_HASH=unknown
|
||||||
|
|
||||||
ENV DATA_DIR /data
|
ENV DATA_DIR /data
|
||||||
ENV NODE_ENV production
|
ENV NODE_ENV production
|
||||||
|
ENV BUILD_DATE $(date)
|
||||||
|
ENV COMMIT_HASH $COMMIT_HASH
|
||||||
|
|
||||||
CMD ["yarn", "start"]
|
CMD ["yarn", "start"]
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import {AutocompleteInteraction, CommandInteraction} from 'discord.js';
|
import {AutocompleteInteraction, CommandInteraction, GuildMember} from 'discord.js';
|
||||||
import {URL} from 'url';
|
import {URL} from 'url';
|
||||||
import {SlashCommandBuilder} from '@discordjs/builders';
|
import {SlashCommandBuilder} from '@discordjs/builders';
|
||||||
import {inject, injectable} from 'inversify';
|
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 KeyValueCacheProvider from '../services/key-value-cache.js';
|
||||||
import {ONE_HOUR_IN_SECONDS} from '../utils/constants.js';
|
import {ONE_HOUR_IN_SECONDS} from '../utils/constants.js';
|
||||||
import AddQueryToQueue from '../services/add-query-to-queue.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()
|
@injectable()
|
||||||
export default class implements Command {
|
export default class implements Command {
|
||||||
|
@ -33,18 +37,46 @@ export default class implements Command {
|
||||||
private readonly spotify: Spotify;
|
private readonly spotify: Spotify;
|
||||||
private readonly cache: KeyValueCacheProvider;
|
private readonly cache: KeyValueCacheProvider;
|
||||||
private readonly addQueryToQueue: AddQueryToQueue;
|
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.spotify = thirdParty.spotify;
|
||||||
this.cache = cache;
|
this.cache = cache;
|
||||||
this.addQueryToQueue = addQueryToQueue;
|
this.addQueryToQueue = addQueryToQueue;
|
||||||
|
this.playerManager = playerManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line complexity
|
// eslint-disable-next-line complexity
|
||||||
public async execute(interaction: CommandInteraction): Promise<void> {
|
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({
|
await this.addQueryToQueue.addToQueue({
|
||||||
interaction,
|
interaction,
|
||||||
query: interaction.options.getString('query')!.trim(),
|
query: query.trim(),
|
||||||
addToFrontOfQueue: interaction.options.getBoolean('immediate') ?? false,
|
addToFrontOfQueue: interaction.options.getBoolean('immediate') ?? false,
|
||||||
shuffleAdditions: interaction.options.getBoolean('shuffle') ?? false,
|
shuffleAdditions: interaction.options.getBoolean('shuffle') ?? false,
|
||||||
});
|
});
|
||||||
|
|
|
@ -9,6 +9,7 @@ const logBanner = () => {
|
||||||
paypalUser: 'codetheweb',
|
paypalUser: 'codetheweb',
|
||||||
githubSponsor: 'codetheweb',
|
githubSponsor: 'codetheweb',
|
||||||
madeByPrefix: 'Made with 🎶 by ',
|
madeByPrefix: 'Made with 🎶 by ',
|
||||||
|
buildDate: process.env.BUILD_DATE ? new Date(process.env.BUILD_DATE) : undefined,
|
||||||
}).join('\n'));
|
}).join('\n'));
|
||||||
console.log('\n');
|
console.log('\n');
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue