chore: merge dev to main #172

Merged
Anri merged 11 commits from dev into main 2024-09-18 18:25:04 +02:00
6 changed files with 1000 additions and 93 deletions
Showing only changes of commit 4155bd0b24 - Show all commits

1037
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -25,6 +25,7 @@
"discord-player-youtubei": "^1.3.1", "discord-player-youtubei": "^1.3.1",
"discord.js": "^14.16.2", "discord.js": "^14.16.2",
"mediaplex": "^0.0.9", "mediaplex": "^0.0.9",
"puppeteer": "^23.4.0",
"sqlite3": "^5.1.7", "sqlite3": "^5.1.7",
"typescript": "^5.6.2", "typescript": "^5.6.2",
"uuid": "^10.0.0" "uuid": "^10.0.0"

View file

@ -1,14 +1,38 @@
import { Player, PlayerEvents, useMainPlayer } from "discord-player"; import { PlayerEvents, useMainPlayer } from "discord-player";
import { Client } from "discord.js"; import { Client } from "discord.js";
import { readdir } from "fs/promises"; import { readdir } from "fs/promises";
import { splitFilenameExtensions } from "../utils/misc"; import { splitFilenameExtensions } from "../utils/misc";
/** Load all the events */ /** Load all the events */
export default async (client: Client) => { export default async (client: Client, isDev: boolean) => {
const events_categories = (await readdir(__dirname)).filter( const events_categories = (await readdir(__dirname)).filter(
(element) => !element.endsWith(".js") && !element.endsWith(".ts"), (element) => !element.endsWith(".js") && !element.endsWith(".ts"),
); );
const player = useMainPlayer();
if (isDev) {
player.on("debug", async (message) => {
console.log(`General player debug event: ${message}`);
});
player.events.on("debug", async (_, message) => {
console.log(`Player debug event: ${message}`);
});
}
player.events.on("error", (_, error) => {
// Emitted when the player queue encounters error
console.error(`General player error event: ${error.message}`);
console.error(error);
});
player.events.on("playerError", (_, error) => {
// Emitted when the audio player errors while streaming audio track
console.error(`Player error event: ${error.message}`);
console.error(error);
});
events_categories.forEach(async (event_category) => { events_categories.forEach(async (event_category) => {
// Retrieve events // Retrieve events
const events = await readdir(`${__dirname}/${event_category}`); const events = await readdir(`${__dirname}/${event_category}`);

View file

@ -21,7 +21,7 @@ export const run = async (isDev: boolean) => {
// Events Discord.JS and Player // Events Discord.JS and Player
const events_name = "Events"; const events_name = "Events";
await loadEvents(client) await loadEvents(client, isDev)
.then(() => console.log(logStart(events_name, true))) .then(() => console.log(logStart(events_name, true)))
.catch((err) => { .catch((err) => {
console.error(err); console.error(err);

View file

@ -5,6 +5,7 @@ import { Database } from "sqlite3";
import "../modules/client"; import "../modules/client";
import { loadLocales } from "./locales"; import { loadLocales } from "./locales";
import { YoutubeiExtractor } from "discord-player-youtubei"; import { YoutubeiExtractor } from "discord-player-youtubei";
import { YoutubeWebTokenRoutine } from "./music";
/** Creation of the client and definition of its properties */ /** Creation of the client and definition of its properties */
export default async () => { export default async () => {
@ -42,6 +43,9 @@ export default async () => {
list: new Collection(), list: new Collection(),
}; };
// Generate tokens
const tokens = await YoutubeWebTokenRoutine(true);
const player = Player.singleton(client, { const player = Player.singleton(client, {
skipFFmpeg: true, skipFFmpeg: true,
ytdlOptions: { ytdlOptions: {
@ -50,7 +54,12 @@ export default async () => {
}, },
}); });
await player.extractors.loadDefault((ext) => ext !== "YouTubeExtractor"); await player.extractors.loadDefault((ext) => ext !== "YouTubeExtractor");
await player.extractors.register(YoutubeiExtractor, {}); await player.extractors.register(YoutubeiExtractor, {
streamOptions: {
useClient: "WEB",
},
trustedTokens: tokens,
});
console.log("Translations progression :"); console.log("Translations progression :");
client.locales = await loadLocales(client.config.default_lang); client.locales = await loadLocales(client.config.default_lang);

View file

@ -2,6 +2,7 @@ import { EmbedBuilder } from "@discordjs/builders";
import { GuildQueue, QueueRepeatMode, Track } from "discord-player"; import { GuildQueue, QueueRepeatMode, Track } from "discord-player";
import { Client } from "discord.js"; import { Client } from "discord.js";
import { getLocale } from "./locales"; import { getLocale } from "./locales";
import { generateTrustedToken, YoutubeiExtractor } from "discord-player-youtubei";
export const embedListQueue = ( export const embedListQueue = (
client: Client, client: Client,
@ -57,3 +58,16 @@ const printRepeatMode = (mode: QueueRepeatMode, loc: Map<string, string>) => {
break; break;
} }
}; };
export const YoutubeWebTokenRoutine = async (first: boolean) => {
// Repeat in one week : 7 * 24 * 60 * 60 * 1000
setTimeout(YoutubeWebTokenRoutine, 604800000, false);
const tokens = await generateTrustedToken();
if (first) {
return tokens;
}
const instance = YoutubeiExtractor.getInstance();
instance?.setTrustedTokens(tokens);
};