From 783bdc144caab424da2adf75e608011b1d29eaa8 Mon Sep 17 00:00:00 2001 From: Manuel <30572287+manuel-rw@users.noreply.github.com> Date: Sun, 19 Feb 2023 12:19:35 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=8A=20Add=20logging=20levels=20and=20d?= =?UTF-8?q?ebug=20for=20problem?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app.module.ts | 13 +++++++------ src/commands/play.comands.ts | 29 +++++++++++++++++++++-------- src/main.ts | 14 +++++++++++++- 3 files changed, 41 insertions(+), 15 deletions(-) diff --git a/src/app.module.ts b/src/app.module.ts index 20dc028..ba19405 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -1,18 +1,19 @@ -import { Module } from '@nestjs/common'; -import * as Joi from 'joi'; - import { DiscordModule } from '@discord-nestjs/core'; + +import { Module } from '@nestjs/common'; import { ConfigModule } from '@nestjs/config'; import { EventEmitterModule } from '@nestjs/event-emitter'; import { ScheduleModule } from '@nestjs/schedule'; -import { DiscordConfigService } from './clients/discord/discord.config.service'; -import { DiscordClientModule } from './clients/discord/discord.module'; -import { JellyfinClientModule } from './clients/jellyfin/jellyfin.module'; +import * as Joi from 'joi'; + import { CommandModule } from './commands/command.module'; import { HealthModule } from './health/health.module'; import { PlaybackModule } from './playback/playback.module'; import { UpdatesModule } from './updates/updates.module'; +import { DiscordConfigService } from './clients/discord/discord.config.service'; +import { DiscordClientModule } from './clients/discord/discord.module'; +import { JellyfinClientModule } from './clients/jellyfin/jellyfin.module'; @Module({ imports: [ diff --git a/src/commands/play.comands.ts b/src/commands/play.comands.ts index 4c6fcc3..530278d 100644 --- a/src/commands/play.comands.ts +++ b/src/commands/play.comands.ts @@ -1,5 +1,4 @@ import { TransformPipe } from '@discord-nestjs/common'; - import { Command, DiscordTransformedCommand, @@ -8,7 +7,11 @@ import { TransformedCommandExecutionContext, UsePipes, } from '@discord-nestjs/core'; + +import { RemoteImageResult } from '@jellyfin/sdk/lib/generated-client/models'; + import { Logger } from '@nestjs/common/services'; + import { ComponentType, Events, @@ -16,19 +19,17 @@ import { Interaction, InteractionReplyOptions, } from 'discord.js'; -import { JellyfinSearchService } from '../clients/jellyfin/jellyfin.search.service'; -import { TrackRequestDto } from '../models/track-request.dto'; -import { DiscordMessageService } from '../clients/discord/discord.message.service'; - -import { RemoteImageResult } from '@jellyfin/sdk/lib/generated-client/models'; -import { DiscordVoiceService } from '../clients/discord/discord.voice.service'; -import { JellyfinStreamBuilderService } from '../clients/jellyfin/jellyfin.stream.builder.service'; import { BaseJellyfinAudioPlayable, searchResultAsJellyfinAudio, } from '../models/jellyfinAudioItems'; +import { TrackRequestDto } from '../models/track-request.dto'; import { PlaybackService } from '../playback/playback.service'; +import { DiscordMessageService } from '../clients/discord/discord.message.service'; +import { DiscordVoiceService } from '../clients/discord/discord.voice.service'; +import { JellyfinSearchService } from '../clients/jellyfin/jellyfin.search.service'; +import { JellyfinStreamBuilderService } from '../clients/jellyfin/jellyfin.stream.builder.service'; import { chooseSuitableRemoteImage } from '../utils/remoteImages/remoteImages'; import { trimStringToFixedLength } from '../utils/stringUtils/stringUtils'; @@ -160,6 +161,10 @@ export class PlayItemCommand const guildMember = interaction.member as GuildMember; + this.logger.debug( + `Trying to join the voice channel of ${guildMember.displayName}`, + ); + const tryResult = this.discordVoiceService.tryJoinChannelAndEstablishVoiceConnection( guildMember, @@ -178,12 +183,20 @@ export class PlayItemCommand return; } + this.logger.debug('Successfully joined the voice channel'); + const bitrate = guildMember.voice.channel.bitrate; const valueParts = interaction.values[0].split('_'); const type = valueParts[0]; const id = valueParts[1]; + this.logger.debug( + `Searching for the content using the values [${interaction.values.join( + ', ', + )}]`, + ); + switch (type) { case 'track': const item = await this.jellyfinSearchService.getById(id); diff --git a/src/main.ts b/src/main.ts index e65c8db..eab8408 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,8 +1,20 @@ +import { LogLevel } from '@nestjs/common/services'; import { NestFactory } from '@nestjs/core'; + import { AppModule } from './app.module'; +function getLoggingLevels(): LogLevel[] { + if (process.env.DEBUG) { + return ['log', 'error', 'warn', 'debug']; + } + + return ['log', 'error', 'warn']; +} + async function bootstrap() { - const app = await NestFactory.create(AppModule); + const app = await NestFactory.create(AppModule, { + logger: getLoggingLevels(), + }); app.enableShutdownHooks(); await app.listen(process.env.PORT || 3000); }