From 49283ae699344b96289047336535a63dd9944f58 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Tue, 8 Aug 2023 22:04:53 +0200 Subject: [PATCH 1/6] increase autocompletion list --- src/commands/music/play.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/commands/music/play.ts b/src/commands/music/play.ts index c48489c..34a5bd3 100644 --- a/src/commands/music/play.ts +++ b/src/commands/music/play.ts @@ -173,7 +173,7 @@ export default { /* Create a race between a timeout and the search * At the end, Discord will always receive a response */ - const tracks = await Promise.race([ + let tracks = await Promise.race([ delay, player.search(query, { requestedBy: interaction.user, @@ -187,7 +187,11 @@ export default { return []; }); - // Returns a list of songs with their title + // Slice the list if needed + if (tracks.length > 25) { + tracks = tracks.slice(0, 25); + } + return interaction.respond( tracks.slice(0, 10).map((t) => ({ name: t.title, -- 2.45.2 From c5f62e36abfe4cac209d64448a30f0a3b6d044ce Mon Sep 17 00:00:00 2001 From: Mylloon Date: Tue, 8 Aug 2023 22:06:06 +0200 Subject: [PATCH 2/6] Add author to the list --- src/commands/music/play.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/commands/music/play.ts b/src/commands/music/play.ts index 34a5bd3..a32bff1 100644 --- a/src/commands/music/play.ts +++ b/src/commands/music/play.ts @@ -192,9 +192,10 @@ export default { tracks = tracks.slice(0, 25); } + // Returns a list of songs with their title and author return interaction.respond( - tracks.slice(0, 10).map((t) => ({ - name: t.title, + tracks.map((t) => ({ + name: `${t.title} • ${t.author}`, value: t.url, })) ); -- 2.45.2 From c15a1ac60ef1b440617ad49a4045cd4515f85eec Mon Sep 17 00:00:00 2001 From: Mylloon Date: Tue, 8 Aug 2023 22:09:57 +0200 Subject: [PATCH 3/6] less time to respond --- src/commands/music/play.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/music/play.ts b/src/commands/music/play.ts index a32bff1..2403730 100644 --- a/src/commands/music/play.ts +++ b/src/commands/music/play.ts @@ -168,7 +168,7 @@ export default { const delay = new Promise(function (_, reject) { timeoutId = setTimeout(function () { reject(new Error()); - }, 2900); + }, 2800); }); /* Create a race between a timeout and the search -- 2.45.2 From c3b710656f62fc89f2bf687a6e3b272f785e6069 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Tue, 8 Aug 2023 22:16:44 +0200 Subject: [PATCH 4/6] sort imports --- src/commands/misc/help.ts | 4 ++-- src/commands/music/stop.ts | 8 ++++---- src/events/message/messageCreate.ts | 2 +- src/load.ts | 6 +++--- src/modals/loader.ts | 2 +- src/modules/client.ts | 2 +- src/utils/client.ts | 8 ++++---- 7 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/commands/misc/help.ts b/src/commands/misc/help.ts index 8d5bcd3..0353e59 100644 --- a/src/commands/misc/help.ts +++ b/src/commands/misc/help.ts @@ -1,9 +1,9 @@ import { SlashCommandBuilder } from "@discordjs/builders"; import { Locale } from "discord-api-types/v9"; -import { Client, ChatInputCommandInteraction, EmbedBuilder, Colors } from "discord.js"; +import { ChatInputCommandInteraction, Client, Colors, EmbedBuilder } from "discord.js"; +import "../../modules/string"; import { getLocale, getLocalizations } from "../../utils/locales"; import { getFilename } from "../../utils/misc"; -import "../../modules/string"; export default { scope: () => [], diff --git a/src/commands/music/stop.ts b/src/commands/music/stop.ts index e6432a9..6a58220 100644 --- a/src/commands/music/stop.ts +++ b/src/commands/music/stop.ts @@ -1,9 +1,9 @@ import { SlashCommandBuilder } from "@discordjs/builders"; -import { ChatInputCommandInteraction, Client, GuildResolvable } from "discord.js"; -import { Metadata } from "../../utils/metadata"; -import { getLocale, getLocalizations } from "../../utils/locales"; -import { getFilename } from "../../utils/misc"; import { Player, useMainPlayer } from "discord-player"; +import { ChatInputCommandInteraction, Client, GuildResolvable } from "discord.js"; +import { getLocale, getLocalizations } from "../../utils/locales"; +import { Metadata } from "../../utils/metadata"; +import { getFilename } from "../../utils/misc"; export default { scope: () => [], diff --git a/src/events/message/messageCreate.ts b/src/events/message/messageCreate.ts index c147430..21a94a3 100644 --- a/src/events/message/messageCreate.ts +++ b/src/events/message/messageCreate.ts @@ -1,4 +1,4 @@ -import { Client, GuildMember, Message, TextBasedChannel, EmbedBuilder } from "discord.js"; +import { Client, EmbedBuilder, GuildMember, Message, TextBasedChannel } from "discord.js"; import { getLocale } from "../../utils/locales"; import { isImage, userWithNickname } from "../../utils/misc"; import { showDate } from "../../utils/time"; diff --git a/src/load.ts b/src/load.ts index 7e3d793..870e7eb 100644 --- a/src/load.ts +++ b/src/load.ts @@ -1,8 +1,8 @@ -import loadClient, { quit } from "./utils/client"; -import loadEvents from "./events/loader"; -import loadModals from "./modals/loader"; import loadButtons from "./buttons/loader"; import loadCommands from "./commands/loader"; +import loadEvents from "./events/loader"; +import loadModals from "./modals/loader"; +import loadClient, { quit } from "./utils/client"; import { logStart } from "./utils/misc"; diff --git a/src/modals/loader.ts b/src/modals/loader.ts index bd5d958..c8d622e 100644 --- a/src/modals/loader.ts +++ b/src/modals/loader.ts @@ -1,6 +1,6 @@ +import { Client } from "discord.js"; import { readdir } from "fs/promises"; import { removeExtension } from "../utils/misc"; -import { Client } from "discord.js"; export default async (client: Client) => { // Dossier des modals diff --git a/src/modules/client.ts b/src/modules/client.ts index 769687f..8d4f519 100644 --- a/src/modules/client.ts +++ b/src/modules/client.ts @@ -1,5 +1,5 @@ -import { Collection } from "discord.js"; import { SlashCommandBuilder } from "@discordjs/builders"; +import { Collection } from "discord.js"; import { Database } from "sqlite3"; export {}; diff --git a/src/utils/client.ts b/src/utils/client.ts index 8d52dc0..8aa3330 100644 --- a/src/utils/client.ts +++ b/src/utils/client.ts @@ -1,10 +1,10 @@ +import { lyricsExtractor } from "@discord-player/extractor"; +import { Player } from "discord-player"; import { Client, Collection, GatewayIntentBits } from "discord.js"; import { readFileSync } from "fs"; -import { loadLocales } from "./locales"; -import "../modules/client"; import { Database } from "sqlite3"; -import { Player } from "discord-player"; -import { lyricsExtractor } from "@discord-player/extractor"; +import "../modules/client"; +import { loadLocales } from "./locales"; /** Creation of the client and definition of its properties. */ export default async () => { -- 2.45.2 From 010b40800b367e2bcc1c6b53e067465479b12b75 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Tue, 8 Aug 2023 22:19:50 +0200 Subject: [PATCH 5/6] remove searchengine constraint --- src/commands/music/play.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/commands/music/play.ts b/src/commands/music/play.ts index 2403730..1a9bc30 100644 --- a/src/commands/music/play.ts +++ b/src/commands/music/play.ts @@ -1,4 +1,5 @@ import { SlashCommandBuilder } from "@discordjs/builders"; +import { Player, SearchResult, useMainPlayer, useQueue } from "discord-player"; import { AutocompleteInteraction, ChatInputCommandInteraction, @@ -7,10 +8,9 @@ import { GuildResolvable, VoiceBasedChannel, } from "discord.js"; -import { Metadata } from "../../utils/metadata"; import { getLocale, getLocalizations } from "../../utils/locales"; +import { Metadata } from "../../utils/metadata"; import { getFilename } from "../../utils/misc"; -import { Player, QueryType, SearchResult, useMainPlayer, useQueue } from "discord-player"; export default { scope: () => [], @@ -118,7 +118,6 @@ export default { const result = await player .search(query, { requestedBy: interaction.user, - searchEngine: QueryType.YOUTUBE_SEARCH, }) .then((x) => x); -- 2.45.2 From 37f18f6920bc2430d45e1e27821fb886086c6db6 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Tue, 8 Aug 2023 22:25:43 +0200 Subject: [PATCH 6/6] Prevents the bot to send empty data to discord --- src/commands/music/play.ts | 29 ++++++++++++++++------------- src/locales/fr.json | 1 + 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/commands/music/play.ts b/src/commands/music/play.ts index 1a9bc30..26da0e2 100644 --- a/src/commands/music/play.ts +++ b/src/commands/music/play.ts @@ -150,6 +150,7 @@ export default { }, autocomplete: async (interaction: AutocompleteInteraction) => { + const loc = getLocale(interaction.client, interaction.locale); const loc_default = interaction.client.locales.get(interaction.client.config.default_lang); const filename = getFilename(__filename); @@ -186,20 +187,22 @@ export default { return []; }); - // Slice the list if needed - if (tracks.length > 25) { - tracks = tracks.slice(0, 25); - } + // If tracks found + if (tracks.length > 0) { + // Slice the list if needed + if (tracks.length > 25) { + tracks = tracks.slice(0, 25); + } - // Returns a list of songs with their title and author - return interaction.respond( - tracks.map((t) => ({ - name: `${t.title} • ${t.author}`, - value: t.url, - })) - ); - } else { - return interaction.respond([]); + // Returns a list of songs with their title and author + return interaction.respond( + tracks.map((t) => ({ + name: `${t.title} • ${t.author}`, + value: t.url, + })) + ); + } } + return interaction.respond([{ name: loc.get("c_play9"), value: query }]); }, }; diff --git a/src/locales/fr.json b/src/locales/fr.json index fce91b8..b634f29 100644 --- a/src/locales/fr.json +++ b/src/locales/fr.json @@ -90,6 +90,7 @@ "c_play6": "Le bot ne joue rien en ce moment.", "c_play7": "Joue actuellement", "c_play8": "Demandé par", + "c_play9": "Aucun résultat trouvé", "c_stop_name": "stop", "c_stop_desc": "Stop la musique", -- 2.45.2