Add option to let user search directly from play

This commit is contained in:
2022-02-27 19:21:50 +07:00
parent 108a4042e2
commit b274332cc9
4 changed files with 75 additions and 10 deletions
+25 -2
View File
@@ -1,4 +1,4 @@
import { Message, CommandInteraction, Interaction, VoiceChannel, MessageActionRow, Permissions, DMChannel, TextChannel } from "discord.js";
import { Message, CommandInteraction, Interaction, VoiceChannel, MessageActionRow, Permissions, MessageButton, TextChannel } from "discord.js";
import { makeErrorEmbed, makeSuccessEmbed, makeProcessingEmbed, sendMessage, sendMessageOrInteractionResponse, makeInfoEmbed } from "../../utils/DiscordMessage";
import DiscordProvider from "../../providers/Discord";
import Environment from "../../providers/Environment";
@@ -181,7 +181,30 @@ export default class Play {
instance.addTrackToQueue(result[0]);
if(result.length > 1) {
// TODO: Let user choose the video
// If the first result title is exact match with the query or first title contains half the space of the query, it's probably a sentence
// then we don't need to show the search results
if(result[0].title === query || result[0].title && (Math.ceil((result[0].title.split(" ").length - 1) / 2) === Math.ceil((query.split(" ").length - 1) / 2))) return;
// The query length is too long to fit in json
if(query.length > 100 - 51) return;
const row = new MessageActionRow()
.addComponents(
new MessageButton()
.setEmoji('🔎')
.setCustomId(JSON.stringify({
module: 'MP_S',
action: 'search',
data: {
q: query
}
}))
.setLabel(' Not this? Search!')
.setStyle('PRIMARY')
)
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.ADDED_QUEUE(data, result[0])], components: [row] });
}
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.ADDED_QUEUE(data, result[0])] });