feat: enchance autocompletion & more (#103)
All checks were successful
ci/woodpecker/push/publish Pipeline was successful
All checks were successful
ci/woodpecker/push/publish Pipeline was successful
- Fixing autocompletion crash - Increase autocompletion response from 10 to 25 - Remove search constraint introduced in #97 Co-authored-by: Mylloon <kennel.anri@tutanota.com> Reviewed-on: #103
This commit is contained in:
parent
0904bd0d98
commit
d039c064b7
9 changed files with 38 additions and 30 deletions
|
@ -1,9 +1,9 @@
|
||||||
import { SlashCommandBuilder } from "@discordjs/builders";
|
import { SlashCommandBuilder } from "@discordjs/builders";
|
||||||
import { Locale } from "discord-api-types/v9";
|
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 { getLocale, getLocalizations } from "../../utils/locales";
|
||||||
import { getFilename } from "../../utils/misc";
|
import { getFilename } from "../../utils/misc";
|
||||||
import "../../modules/string";
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
scope: () => [],
|
scope: () => [],
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { SlashCommandBuilder } from "@discordjs/builders";
|
import { SlashCommandBuilder } from "@discordjs/builders";
|
||||||
|
import { Player, SearchResult, useMainPlayer, useQueue } from "discord-player";
|
||||||
import {
|
import {
|
||||||
AutocompleteInteraction,
|
AutocompleteInteraction,
|
||||||
ChatInputCommandInteraction,
|
ChatInputCommandInteraction,
|
||||||
|
@ -7,10 +8,9 @@ import {
|
||||||
GuildResolvable,
|
GuildResolvable,
|
||||||
VoiceBasedChannel,
|
VoiceBasedChannel,
|
||||||
} from "discord.js";
|
} from "discord.js";
|
||||||
import { Metadata } from "../../utils/metadata";
|
|
||||||
import { getLocale, getLocalizations } from "../../utils/locales";
|
import { getLocale, getLocalizations } from "../../utils/locales";
|
||||||
|
import { Metadata } from "../../utils/metadata";
|
||||||
import { getFilename } from "../../utils/misc";
|
import { getFilename } from "../../utils/misc";
|
||||||
import { Player, QueryType, SearchResult, useMainPlayer, useQueue } from "discord-player";
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
scope: () => [],
|
scope: () => [],
|
||||||
|
@ -118,7 +118,6 @@ export default {
|
||||||
const result = await player
|
const result = await player
|
||||||
.search(query, {
|
.search(query, {
|
||||||
requestedBy: interaction.user,
|
requestedBy: interaction.user,
|
||||||
searchEngine: QueryType.YOUTUBE_SEARCH,
|
|
||||||
})
|
})
|
||||||
.then((x) => x);
|
.then((x) => x);
|
||||||
|
|
||||||
|
@ -151,6 +150,7 @@ export default {
|
||||||
},
|
},
|
||||||
|
|
||||||
autocomplete: async (interaction: AutocompleteInteraction) => {
|
autocomplete: async (interaction: AutocompleteInteraction) => {
|
||||||
|
const loc = getLocale(interaction.client, interaction.locale);
|
||||||
const loc_default = interaction.client.locales.get(interaction.client.config.default_lang);
|
const loc_default = interaction.client.locales.get(interaction.client.config.default_lang);
|
||||||
const filename = getFilename(__filename);
|
const filename = getFilename(__filename);
|
||||||
|
|
||||||
|
@ -168,12 +168,12 @@ export default {
|
||||||
const delay = new Promise(function (_, reject) {
|
const delay = new Promise(function (_, reject) {
|
||||||
timeoutId = setTimeout(function () {
|
timeoutId = setTimeout(function () {
|
||||||
reject(new Error());
|
reject(new Error());
|
||||||
}, 2900);
|
}, 2800);
|
||||||
});
|
});
|
||||||
|
|
||||||
/* Create a race between a timeout and the search
|
/* Create a race between a timeout and the search
|
||||||
* At the end, Discord will always receive a response */
|
* At the end, Discord will always receive a response */
|
||||||
const tracks = await Promise.race([
|
let tracks = await Promise.race([
|
||||||
delay,
|
delay,
|
||||||
player.search(query, {
|
player.search(query, {
|
||||||
requestedBy: interaction.user,
|
requestedBy: interaction.user,
|
||||||
|
@ -187,15 +187,22 @@ export default {
|
||||||
return [];
|
return [];
|
||||||
});
|
});
|
||||||
|
|
||||||
// Returns a list of songs with their title
|
// 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(
|
return interaction.respond(
|
||||||
tracks.slice(0, 10).map((t) => ({
|
tracks.map((t) => ({
|
||||||
name: t.title,
|
name: `${t.title} • ${t.author}`,
|
||||||
value: t.url,
|
value: t.url,
|
||||||
}))
|
}))
|
||||||
);
|
);
|
||||||
} else {
|
|
||||||
return interaction.respond([]);
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
return interaction.respond([{ name: loc.get("c_play9"), value: query }]);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
import { SlashCommandBuilder } from "@discordjs/builders";
|
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 { 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 {
|
export default {
|
||||||
scope: () => [],
|
scope: () => [],
|
||||||
|
|
|
@ -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 { getLocale } from "../../utils/locales";
|
||||||
import { isImage, userWithNickname } from "../../utils/misc";
|
import { isImage, userWithNickname } from "../../utils/misc";
|
||||||
import { showDate } from "../../utils/time";
|
import { showDate } from "../../utils/time";
|
||||||
|
|
|
@ -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 loadButtons from "./buttons/loader";
|
||||||
import loadCommands from "./commands/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";
|
import { logStart } from "./utils/misc";
|
||||||
|
|
||||||
|
|
|
@ -90,6 +90,7 @@
|
||||||
"c_play6": "Le bot ne joue rien en ce moment.",
|
"c_play6": "Le bot ne joue rien en ce moment.",
|
||||||
"c_play7": "Joue actuellement",
|
"c_play7": "Joue actuellement",
|
||||||
"c_play8": "Demandé par",
|
"c_play8": "Demandé par",
|
||||||
|
"c_play9": "Aucun résultat trouvé",
|
||||||
|
|
||||||
"c_stop_name": "stop",
|
"c_stop_name": "stop",
|
||||||
"c_stop_desc": "Stop la musique",
|
"c_stop_desc": "Stop la musique",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
|
import { Client } from "discord.js";
|
||||||
import { readdir } from "fs/promises";
|
import { readdir } from "fs/promises";
|
||||||
import { removeExtension } from "../utils/misc";
|
import { removeExtension } from "../utils/misc";
|
||||||
import { Client } from "discord.js";
|
|
||||||
|
|
||||||
export default async (client: Client) => {
|
export default async (client: Client) => {
|
||||||
// Dossier des modals
|
// Dossier des modals
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { Collection } from "discord.js";
|
|
||||||
import { SlashCommandBuilder } from "@discordjs/builders";
|
import { SlashCommandBuilder } from "@discordjs/builders";
|
||||||
|
import { Collection } from "discord.js";
|
||||||
import { Database } from "sqlite3";
|
import { Database } from "sqlite3";
|
||||||
|
|
||||||
export {};
|
export {};
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
|
import { lyricsExtractor } from "@discord-player/extractor";
|
||||||
|
import { Player } from "discord-player";
|
||||||
import { Client, Collection, GatewayIntentBits } from "discord.js";
|
import { Client, Collection, GatewayIntentBits } from "discord.js";
|
||||||
import { readFileSync } from "fs";
|
import { readFileSync } from "fs";
|
||||||
import { loadLocales } from "./locales";
|
|
||||||
import "../modules/client";
|
|
||||||
import { Database } from "sqlite3";
|
import { Database } from "sqlite3";
|
||||||
import { Player } from "discord-player";
|
import "../modules/client";
|
||||||
import { lyricsExtractor } from "@discord-player/extractor";
|
import { loadLocales } from "./locales";
|
||||||
|
|
||||||
/** Creation of the client and definition of its properties. */
|
/** Creation of the client and definition of its properties. */
|
||||||
export default async () => {
|
export default async () => {
|
||||||
|
|
Loading…
Reference in a new issue