From 55baa35cba861c57bfbb14c8e9015418505ea98c Mon Sep 17 00:00:00 2001 From: Serraniel Date: Sun, 5 Dec 2021 19:10:40 +0100 Subject: [PATCH 1/2] #96 Added nickname to filename variables --- .../Classes/JobScheduler.cs | 47 +++++++++++-------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/Discord Media Loader.Application/Classes/JobScheduler.cs b/Discord Media Loader.Application/Classes/JobScheduler.cs index 3af4e48..b5ccb03 100644 --- a/Discord Media Loader.Application/Classes/JobScheduler.cs +++ b/Discord Media Loader.Application/Classes/JobScheduler.cs @@ -7,7 +7,6 @@ using System.Threading.Tasks; using Discord; using Discord.WebSocket; using DML.Application.Classes; -using SweetLib.Utils; using SweetLib.Utils.Extensions; using SweetLib.Utils.Logger; @@ -15,14 +14,14 @@ namespace DML.AppCore.Classes { public class JobScheduler { - private ulong messageScanned = 0; - private ulong totalAttachments = 0; - private ulong attachmentsDownloaded = 0; - - private bool Run { get; set; } = false; - public List JobList { get; set; } = new List(); + private ulong attachmentsDownloaded; + private ulong messageScanned; public Dictionary> RunningJobs = new Dictionary>(); - internal int RunningThreads { get; set; } = 0; + private ulong totalAttachments; + + private bool Run { get; set; } + public List JobList { get; set; } = new List(); + internal int RunningThreads { get; set; } internal ulong MessagesScanned { @@ -91,7 +90,6 @@ namespace DML.AppCore.Classes { Logger.Info("Started JobScheduler..."); while (Run) - { try { Logger.Debug("Entering job list handler loop..."); @@ -108,6 +106,7 @@ namespace DML.AppCore.Classes Logger.Trace("Checking if job is already performed..."); hasJob = RunningJobs.ContainsKey(job.Id); } + Logger.Trace("Unlocked scheduler."); if (!hasJob) @@ -121,6 +120,7 @@ namespace DML.AppCore.Classes Logger.Trace("Adding job to running jobs."); RunningJobs.Add(job.Id, queue); } + Logger.Trace("Unlocked scheduler."); Logger.Trace("Issuing job message scan..."); @@ -130,10 +130,7 @@ namespace DML.AppCore.Classes continue; Logger.Trace($"Adding {messages.Count} messages to queue..."); - foreach (var msg in messages) - { - queue.Enqueue(msg); - } + foreach (var msg in messages) queue.Enqueue(msg); Logger.Trace($"Added {queue.Count} messages to queue."); if (messages.Count != queue.Count) @@ -155,6 +152,7 @@ namespace DML.AppCore.Classes RunningThreads++; startedDownload = true; } + Logger.Trace("Unlocked scheduler."); } @@ -167,7 +165,6 @@ namespace DML.AppCore.Classes { Logger.Error(ex.Message); } - } }); } @@ -184,6 +181,7 @@ namespace DML.AppCore.Classes Logger.Warn($"Associating job not found! JobId: {jobId}"); return; } + Logger.Trace("Found job."); Queue queue; @@ -196,8 +194,10 @@ namespace DML.AppCore.Classes Logger.Warn($"Queue for job {jobId} not found!"); return; } + Logger.Trace("Queue found."); } + Logger.Trace("Unlocked scheduler."); Logger.Debug($"Messages to process for job {jobId}: {queue.Count}"); @@ -212,8 +212,10 @@ namespace DML.AppCore.Classes Logger.Warn($"Queue for job {jobId} not found!"); return; } + Logger.Trace("Continue working..."); } + Logger.Trace("Unlocked scheduler."); Logger.Trace("Dequeueing message..."); @@ -221,7 +223,6 @@ namespace DML.AppCore.Classes Logger.Debug($"Attachments for message {message.Id}: {message.Attachments.Count}"); foreach (var a in message.Attachments) - { try { var fileName = Path.Combine(Core.Settings.OperatingFolder, Core.Settings.FileNameScheme); @@ -231,16 +232,20 @@ namespace DML.AppCore.Classes var extensionRequired = !fileName.EndsWith("%name%"); var serverName = "unknown"; + string nickname = null; var socketTextChannel = message.Channel as SocketTextChannel; if (socketTextChannel != null) { serverName = socketTextChannel.Guild.Name; - serverName = Path.GetInvalidFileNameChars().Aggregate(serverName, (current, c) => current.Replace(c, ' ')); + serverName = Path.GetInvalidFileNameChars() + .Aggregate(serverName, (current, c) => current.Replace(c, ' ')); + nickname = socketTextChannel.GetUser(message.Author.Id).Nickname; } var channelName = message.Channel.Name; - channelName = Path.GetInvalidFileNameChars().Aggregate(channelName, (current, c) => current.Replace(c, ' ')); + channelName = Path.GetInvalidFileNameChars() + .Aggregate(channelName, (current, c) => current.Replace(c, ' ')); fileName = fileName.Replace("%guild%", serverName) @@ -249,7 +254,9 @@ namespace DML.AppCore.Classes .Replace("%name%", a.Filename) .Replace("%id%", a.Id.ToString()) .Replace("%userid%", message.Author.Id.ToString()) - .Replace("%username%", message.Author.Username); + .Replace("%username%", message.Author.Username) + .Replace("%nickname%", + !string.IsNullOrEmpty(nickname) ? nickname : message.Author.Username); if (extensionRequired) fileName += Path.GetExtension(a.Filename); @@ -287,7 +294,6 @@ namespace DML.AppCore.Classes { AttachmentsDownloaded++; } - } } } finally @@ -300,8 +306,9 @@ namespace DML.AppCore.Classes Logger.Trace("Decreasing thread count..."); RunningThreads--; } + Logger.Trace("Unlocked scheduler."); } } } -} +} \ No newline at end of file -- 2.43.5 From cf06a34183eec27ee342b7326ab6bcdbc0e88915 Mon Sep 17 00:00:00 2001 From: Serraniel Date: Sun, 5 Dec 2021 19:14:46 +0100 Subject: [PATCH 2/2] #96 Added nickname to explanation resource --- .../Properties/Resources.Designer.cs | 3 ++- Discord Media Loader.Application/Properties/Resources.resx | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Discord Media Loader.Application/Properties/Resources.Designer.cs b/Discord Media Loader.Application/Properties/Resources.Designer.cs index b3b8c9e..c41858d 100644 --- a/Discord Media Loader.Application/Properties/Resources.Designer.cs +++ b/Discord Media Loader.Application/Properties/Resources.Designer.cs @@ -86,7 +86,8 @@ namespace DML.Application.Properties { ///%channel% -> channel name ///%timestamp% -> message timestamp (Unix timestamp) ///%name% -> attachment filename - ///%username% -> author name + ///%username% -> author username + ///%nickname% -> author nickname (if unassigned, username will be used) ///%id% -> attachment id (given by Discord) ///%userid% -> author id (given by discord) ähnelt. /// diff --git a/Discord Media Loader.Application/Properties/Resources.resx b/Discord Media Loader.Application/Properties/Resources.resx index 9d23682..c7f9ce5 100644 --- a/Discord Media Loader.Application/Properties/Resources.resx +++ b/Discord Media Loader.Application/Properties/Resources.resx @@ -139,7 +139,8 @@ Flaticons (Roundicons Circle Flat) - Flaticon Basic License %channel% -> channel name %timestamp% -> message timestamp (Unix timestamp) %name% -> attachment filename -%username% -> author name +%username% -> author username +%nickname% -> author nickname (if unassigned, username will be used) %id% -> attachment id (given by Discord) %userid% -> author id (given by discord) -- 2.43.5