From dccbd4ab0b85c8e43c3057c9f825dcea38fc1caf Mon Sep 17 00:00:00 2001 From: Serraniel Date: Thu, 16 Dec 2021 14:47:47 +0100 Subject: [PATCH] #105 Only fetch some data if it is required to generate filename --- .../Classes/JobScheduler.cs | 28 +++++++++++++------ 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/Discord Media Loader.Application/Classes/JobScheduler.cs b/Discord Media Loader.Application/Classes/JobScheduler.cs index ff90b4b..4f2e4a2 100644 --- a/Discord Media Loader.Application/Classes/JobScheduler.cs +++ b/Discord Media Loader.Application/Classes/JobScheduler.cs @@ -234,19 +234,29 @@ namespace DML.AppCore.Classes var serverName = "unknown"; string nickname = null; - var socketTextChannel = message.Channel as SocketTextChannel; - if (socketTextChannel != null) + if (fileName.Contains("%guildid%") || fileName.Contains("%nickname%")) { - serverName = socketTextChannel.Guild.Name; - serverName = Path.GetInvalidFileNameChars() - .Aggregate(serverName, (current, c) => current.Replace(c, ' ')); + var socketTextChannel = message.Channel as SocketTextChannel; + if (socketTextChannel != null) + { + // fetch servername + serverName = socketTextChannel.Guild.Name; + serverName = Path.GetInvalidFileNameChars() + .Aggregate(serverName, (current, c) => current.Replace(c, ' ')); - var serverUser = - socketTextChannel.GetUser(message.Author.Id); // can be null if user left the server - if (serverUser != null) - nickname = serverUser.Nickname; + // fetch nickname + if (fileName.Contains("%nickname%")) + { + var serverUser = + socketTextChannel.GetUser(message.Author + .Id); // can be null if user left the server + if (serverUser != null) + nickname = serverUser.Nickname; + } + } } + // fetch channelname var channelName = message.Channel.Name; channelName = Path.GetInvalidFileNameChars() .Aggregate(channelName, (current, c) => current.Replace(c, ' '));