aboutsummaryrefslogtreecommitdiff
path: root/src/commands
diff options
context:
space:
mode:
Diffstat (limited to 'src/commands')
-rw-r--r--src/commands/play.ts41
-rw-r--r--src/commands/resume.ts46
2 files changed, 52 insertions, 35 deletions
diff --git a/src/commands/play.ts b/src/commands/play.ts
index 08436c2..a1dd84b 100644
--- a/src/commands/play.ts
+++ b/src/commands/play.ts
@@ -1,4 +1,4 @@
-import {AutocompleteInteraction, CommandInteraction, GuildMember} from 'discord.js';
+import {AutocompleteInteraction, CommandInteraction} from 'discord.js';
import {URL} from 'url';
import {SlashCommandBuilder} from '@discordjs/builders';
import {inject, injectable} from 'inversify';
@@ -10,20 +10,17 @@ 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 {
public readonly slashCommand = new SlashCommandBuilder()
.setName('play')
- .setDescription('play a song or resume playback')
+ .setDescription('play a song')
.addStringOption(option => option
.setName('query')
.setDescription('YouTube URL, Spotify URL, or search query')
- .setAutocomplete(true))
+ .setAutocomplete(true)
+ .setRequired(true))
.addBooleanOption(option => option
.setName('immediate')
.setDescription('add track to the front of the queue'))
@@ -36,42 +33,16 @@ 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, @inject(TYPES.Managers.Player) playerManager: PlayerManager) {
+ constructor(@inject(TYPES.ThirdParty) thirdParty: ThirdParty, @inject(TYPES.KeyValueCache) cache: KeyValueCacheProvider, @inject(TYPES.Services.AddQueryToQueue) addQueryToQueue: AddQueryToQueue) {
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;
- }
+ const query = interaction.options.getString('query')!;
await this.addQueryToQueue.addToQueue({
interaction,
diff --git a/src/commands/resume.ts b/src/commands/resume.ts
new file mode 100644
index 0000000..eddc762
--- /dev/null
+++ b/src/commands/resume.ts
@@ -0,0 +1,46 @@
+import {SlashCommandBuilder} from '@discordjs/builders';
+import {inject, injectable} from 'inversify';
+import Command from '.';
+import {TYPES} from '../types.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';
+import {CommandInteraction, GuildMember} from 'discord.js';
+
+@injectable()
+export default class implements Command {
+ public readonly slashCommand = new SlashCommandBuilder()
+ .setName('resume')
+ .setDescription('resume playback');
+
+ public requiresVC = true;
+
+ private readonly playerManager: PlayerManager;
+
+ constructor(@inject(TYPES.Managers.Player) playerManager: PlayerManager) {
+ this.playerManager = playerManager;
+ }
+
+ // eslint-disable-next-line complexity
+ public async execute(interaction: CommandInteraction): Promise<void> {
+ const player = this.playerManager.get(interaction.guild!.id);
+ const [targetVoiceChannel] = getMemberVoiceChannel(interaction.member as GuildMember) ?? getMostPopularVoiceChannel(interaction.guild!);
+ 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)],
+ });
+ }
+}