merge dev to main #133

Merged
Anri merged 3 commits from dev into main 2024-06-01 21:51:38 +02:00
9 changed files with 826 additions and 456 deletions

1214
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -18,21 +18,21 @@
"license": "AGPL-3.0-only", "license": "AGPL-3.0-only",
"dependencies": { "dependencies": {
"@discord-player/extractor": "^4.4.7", "@discord-player/extractor": "^4.4.7",
"@discordjs/rest": "^2.2.0", "@discordjs/rest": "^2.3.0",
"@distube/ytdl-core": "^4.13.3", "@distube/ytdl-core": "^4.13.3",
"@types/sqlite3": "^3.1.11", "@types/sqlite3": "^3.1.11",
"@types/uuid": "^9.0.8", "@types/uuid": "^9.0.8",
"discord-player": "^6.6.8", "@web-scrobbler/metadata-filter": "^3.1.0",
"discord.js": "^14.14.1", "discord-player": "^6.6.9",
"genius-lyrics": "^4.4.6", "discord.js": "^14.15.2",
"mediaplex": "^0.0.9", "mediaplex": "^0.0.9",
"sqlite3": "^5.1.7", "sqlite3": "^5.1.7",
"typescript": "^5.4.3", "typescript": "^5.4.5",
"uuid": "^9.0.1" "uuid": "^9.0.1"
}, },
"devDependencies": { "devDependencies": {
"@typescript-eslint/eslint-plugin": "~7.4.0", "@typescript-eslint/eslint-plugin": "~7.11.0",
"@typescript-eslint/parser": "~7.4.0", "@typescript-eslint/parser": "~7.11.0",
"dotenv": "~16.4.5", "dotenv": "~16.4.5",
"prettier-eslint": "~16.3.0", "prettier-eslint": "~16.3.0",
"ts-node-dev": "~2.0.0" "ts-node-dev": "~2.0.0"

View file

@ -84,32 +84,35 @@ export default {
} }
try { try {
data = await player.lyrics.search(request); data = await player.lyrics.search({ q: request });
} catch { } catch {
return await interaction.followUp(`❌ | ${loc.get("c_lyrics2")} \`${request}\``); return await interaction.followUp(`❌ | ${loc.get("c_lyrics2")} \`${request}\``);
} }
} else { } else {
const queue = useQueue(interaction.guildId ?? ""); const queue = useQueue(interaction.guildId ?? "");
if (queue) { if (queue) {
const title = queue.history.currentTrack?.title; const track = queue.history.currentTrack;
if (title) { if (track) {
try { try {
data = await player.lyrics.search(title + " " + queue.history.currentTrack?.author); data = await player.lyrics.search({
q: track.cleanTitle + " " + queue.history.currentTrack?.author,
});
} catch { } catch {
return await interaction.followUp(`❌ | ${loc.get("c_lyrics2")} \`${title}\``); return await interaction.followUp(`❌ | ${loc.get("c_lyrics2")} \`${track.title}\``);
} }
} }
} }
} }
if (data) { if (data && data.length > 0) {
const title = data[0];
const limit_desc = 4096; const limit_desc = 4096;
const nb_embed = Math.ceil(data.lyrics.length / limit_desc); const nb_embed = Math.ceil(title.plainLyrics.length / limit_desc);
// TODO: If lyrics < 6000, only send one message with multiples embed // TODO: If lyrics < 6000, only send one message with multiples embed
for (let i = 0, j = 0; i < nb_embed; i++, j += limit_desc) { for (let i = 0, j = 0; i < nb_embed; i++, j += limit_desc) {
// TODO: Better cut in lyrics // TODO: Better cut in lyrics
const lyrics = data.lyrics.slice(j, j + limit_desc); const lyrics = title.plainLyrics.slice(j, j + limit_desc);
let embed; let embed;
switch (i) { switch (i) {
@ -117,23 +120,16 @@ export default {
// First embed // First embed
embed = new EmbedBuilder(); embed = new EmbedBuilder();
embed embed
.setTitle(data.title) .setTitle(title.trackName)
.setURL(data.url) .setAuthor({ name: title.artistName })
.setAuthor({ .setDescription(lyrics);
name: data?.artist.name,
iconURL: data?.artist.image,
url: data?.artist.url,
})
.setDescription(lyrics)
.setThumbnail(data.thumbnail);
break; break;
} }
case nb_embed - 1: { case nb_embed - 1: {
// Footer of last embed in case of multiple embed // Footer of last embed in case of multiple embed
embed = new EmbedBuilder().setDescription(lyrics).setFooter({ embed = new EmbedBuilder().setDescription(lyrics).setFooter({
text: `${data?.artist.name} · ${data.title}`, text: `${title.artistName} · ${title.trackName}`,
iconURL: data?.artist.image,
}); });
break; break;
} }

View file

@ -1,16 +0,0 @@
import { LyricsData } from "@discord-player/extractor";
import { Client } from "genius-lyrics";
type LyricsClient = {
search: (query: string) => Promise<LyricsData | null>;
client: Client;
};
export {};
declare module "discord-player" {
export interface Player {
/** Lyrics client */
lyrics: LyricsClient;
}
}

View file

@ -1,4 +1,3 @@
import { lyricsExtractor } from "@discord-player/extractor";
import { Player } from "discord-player"; 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";
@ -39,6 +38,7 @@ export default async () => {
}; };
const player = Player.singleton(client, { const player = Player.singleton(client, {
skipFFmpeg: true,
ytdlOptions: { ytdlOptions: {
filter: "audioonly", filter: "audioonly",
quality: "highestaudio", quality: "highestaudio",
@ -46,8 +46,6 @@ export default async () => {
}); });
await player.extractors.loadDefault(); await player.extractors.loadDefault();
player.lyrics = lyricsExtractor();
console.log("Translations progression :"); console.log("Translations progression :");
client.locales = await loadLocales(client.config.default_lang); client.locales = await loadLocales(client.config.default_lang);