mirror of
https://github.com/BluemediaDev/muse.git
synced 2025-05-09 19:51:36 +02:00
Bump packages, add debug logging
This commit is contained in:
parent
6eb704c5b4
commit
9d8275bbda
4 changed files with 48 additions and 78 deletions
|
@ -1,5 +1,4 @@
|
|||
import {inject, injectable} from 'inversify';
|
||||
import {Client} from 'discord.js';
|
||||
import {TYPES} from '../types.js';
|
||||
import Player from '../services/player.js';
|
||||
import FileCacheProvider from '../services/file-cache.js';
|
||||
|
@ -7,12 +6,10 @@ import FileCacheProvider from '../services/file-cache.js';
|
|||
@injectable()
|
||||
export default class {
|
||||
private readonly guildPlayers: Map<string, Player>;
|
||||
private readonly discordClient: Client;
|
||||
private readonly fileCache: FileCacheProvider;
|
||||
|
||||
constructor(@inject(TYPES.FileCache) fileCache: FileCacheProvider, @inject(TYPES.Client) client: Client) {
|
||||
constructor(@inject(TYPES.FileCache) fileCache: FileCacheProvider) {
|
||||
this.guildPlayers = new Map();
|
||||
this.discordClient = client;
|
||||
this.fileCache = fileCache;
|
||||
}
|
||||
|
||||
|
@ -20,7 +17,7 @@ export default class {
|
|||
let player = this.guildPlayers.get(guildId);
|
||||
|
||||
if (!player) {
|
||||
player = new Player(this.discordClient, this.fileCache, guildId);
|
||||
player = new Player(this.fileCache, guildId);
|
||||
|
||||
this.guildPlayers.set(guildId, player);
|
||||
}
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
import {VoiceChannel, Snowflake, Client, TextChannel} from 'discord.js';
|
||||
import {VoiceChannel, Snowflake} from 'discord.js';
|
||||
import {Readable} from 'stream';
|
||||
import hasha from 'hasha';
|
||||
import ytdl from 'ytdl-core';
|
||||
import {WriteStream} from 'fs-capacitor';
|
||||
import ffmpeg from 'fluent-ffmpeg';
|
||||
import shuffle from 'array-shuffle';
|
||||
import errorMsg from '../utils/error-msg.js';
|
||||
import {AudioPlayer, AudioPlayerStatus, createAudioPlayer, createAudioResource, joinVoiceChannel, StreamType, VoiceConnection, VoiceConnectionStatus} from '@discordjs/voice';
|
||||
import FileCacheProvider from './file-cache.js';
|
||||
import debug from '../utils/debug.js';
|
||||
|
||||
export interface QueuedPlaylist {
|
||||
title: string;
|
||||
|
@ -49,11 +49,9 @@ export default class {
|
|||
|
||||
private positionInSeconds = 0;
|
||||
|
||||
private readonly discordClient: Client;
|
||||
private readonly fileCache: FileCacheProvider;
|
||||
|
||||
constructor(client: Client, fileCache: FileCacheProvider, guildId: string) {
|
||||
this.discordClient = client;
|
||||
constructor(fileCache: FileCacheProvider, guildId: string) {
|
||||
this.fileCache = fileCache;
|
||||
this.guildId = guildId;
|
||||
}
|
||||
|
@ -62,7 +60,6 @@ export default class {
|
|||
const conn = joinVoiceChannel({
|
||||
channelId: channel.id,
|
||||
guildId: channel.guild.id,
|
||||
// @ts-expect-error (see https://github.com/discordjs/voice/issues/166)
|
||||
adapterCreator: channel.guild.voiceAdapterCreator,
|
||||
});
|
||||
|
||||
|
@ -150,9 +147,11 @@ export default class {
|
|||
const stream = await this.getStream(currentSong.url);
|
||||
this.audioPlayer = createAudioPlayer();
|
||||
this.voiceConnection.subscribe(this.audioPlayer);
|
||||
this.audioPlayer.play(createAudioResource(stream, {
|
||||
const resource = createAudioResource(stream, {
|
||||
inputType: StreamType.WebmOpus,
|
||||
}));
|
||||
});
|
||||
|
||||
this.audioPlayer.play(resource);
|
||||
|
||||
this.attachListeners();
|
||||
|
||||
|
@ -167,14 +166,13 @@ export default class {
|
|||
this.lastSongURL = currentSong.url;
|
||||
}
|
||||
} catch (error: unknown) {
|
||||
const currentSong = this.getCurrent();
|
||||
await this.forward(1);
|
||||
|
||||
if ((error as {statusCode: number}).statusCode === 410 && currentSong) {
|
||||
const channelId = currentSong.addedInChannelId;
|
||||
|
||||
if (channelId) {
|
||||
await (this.discordClient.channels.cache.get(channelId) as TextChannel).send(errorMsg(`${currentSong.title} is unavailable`));
|
||||
debug(`${currentSong.title} is unavailable`);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -405,6 +403,9 @@ export default class {
|
|||
.on('error', error => {
|
||||
console.error(error);
|
||||
reject(error);
|
||||
})
|
||||
.on('start', command => {
|
||||
debug(`Spawned ffmpeg with ${command as string}`);
|
||||
});
|
||||
|
||||
youtubeStream.pipe(capacitor);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue