diff --git a/DiscordChatExporter.Cli/Commands/Base/ExportCommandBase.cs b/DiscordChatExporter.Cli/Commands/Base/ExportCommandBase.cs index 80850a3e..a523c9b2 100644 --- a/DiscordChatExporter.Cli/Commands/Base/ExportCommandBase.cs +++ b/DiscordChatExporter.Cli/Commands/Base/ExportCommandBase.cs @@ -177,7 +177,7 @@ public abstract class ExportCommandBase : DiscordCommandBase // Export var cancellationToken = console.RegisterCancellationHandler(); - var errors = new ConcurrentDictionary(); + var errorsByChannel = new ConcurrentDictionary(); await console.Output.WriteLineAsync($"Exporting {channels.Count} channel(s)..."); await console.CreateProgressTicker().StartAsync(async progressContext => @@ -225,7 +225,7 @@ public abstract class ExportCommandBase : DiscordCommandBase } catch (DiscordChatExporterException ex) when (!ex.IsFatal) { - errors[channel] = ex.Message; + errorsByChannel[channel] = ex.Message; } } ); @@ -235,23 +235,23 @@ public abstract class ExportCommandBase : DiscordCommandBase using (console.WithForegroundColor(ConsoleColor.White)) { await console.Output.WriteLineAsync( - $"Successfully exported {channels.Count - errors.Count} channel(s)." + $"Successfully exported {channels.Count - errorsByChannel.Count} channel(s)." ); } // Print errors - if (errors.Any()) + if (errorsByChannel.Any()) { await console.Output.WriteLineAsync(); using (console.WithForegroundColor(ConsoleColor.Red)) { await console.Error.WriteLineAsync( - $"Failed to export {errors.Count} channel(s):" + $"Failed to export {errorsByChannel.Count} channel(s):" ); } - foreach (var (channel, error) in errors) + foreach (var (channel, error) in errorsByChannel) { await console.Error.WriteAsync($"{channel.Category} / {channel.Name}: "); @@ -264,7 +264,7 @@ public abstract class ExportCommandBase : DiscordCommandBase // Fail the command only if ALL channels failed to export. // If only some channels failed to export, it's okay. - if (errors.Count >= channels.Count) + if (errorsByChannel.Count >= channels.Count) throw new CommandException("Export failed."); } diff --git a/DiscordChatExporter.Core/Exporting/ExportAssetDownloader.cs b/DiscordChatExporter.Core/Exporting/ExportAssetDownloader.cs index 77ab32e0..54fdeb12 100644 --- a/DiscordChatExporter.Core/Exporting/ExportAssetDownloader.cs +++ b/DiscordChatExporter.Core/Exporting/ExportAssetDownloader.cs @@ -25,7 +25,7 @@ internal partial class ExportAssetDownloader private readonly bool _reuse; // File paths of the previously downloaded assets - private readonly Dictionary _pathCache = new(StringComparer.Ordinal); + private readonly Dictionary _previousPathsByUrl = new(StringComparer.Ordinal); public ExportAssetDownloader(string workingDirPath, bool reuse) { @@ -40,12 +40,12 @@ internal partial class ExportAssetDownloader using var _ = await Locker.LockAsync(filePath, cancellationToken); - if (_pathCache.TryGetValue(url, out var cachedFilePath)) + if (_previousPathsByUrl.TryGetValue(url, out var cachedFilePath)) return cachedFilePath; // Reuse existing files if we're allowed to if (_reuse && File.Exists(filePath)) - return _pathCache[url] = filePath; + return _previousPathsByUrl[url] = filePath; Directory.CreateDirectory(_workingDirPath); @@ -80,7 +80,7 @@ internal partial class ExportAssetDownloader } }); - return _pathCache[url] = filePath; + return _previousPathsByUrl[url] = filePath; } } diff --git a/DiscordChatExporter.Core/Exporting/ExportContext.cs b/DiscordChatExporter.Core/Exporting/ExportContext.cs index 20f36ed3..41b35175 100644 --- a/DiscordChatExporter.Core/Exporting/ExportContext.cs +++ b/DiscordChatExporter.Core/Exporting/ExportContext.cs @@ -14,9 +14,9 @@ namespace DiscordChatExporter.Core.Exporting; internal class ExportContext { - private readonly Dictionary _members = new(); - private readonly Dictionary _channels = new(); - private readonly Dictionary _roles = new(); + private readonly Dictionary _membersById = new(); + private readonly Dictionary _channelsById = new(); + private readonly Dictionary _rolesById = new(); private readonly ExportAssetDownloader _assetDownloader; public DiscordClient Discord { get; } @@ -38,10 +38,10 @@ internal class ExportContext public async ValueTask PopulateChannelsAndRolesAsync(CancellationToken cancellationToken = default) { await foreach (var channel in Discord.GetGuildChannelsAsync(Request.Guild.Id, cancellationToken)) - _channels[channel.Id] = channel; + _channelsById[channel.Id] = channel; await foreach (var role in Discord.GetGuildRolesAsync(Request.Guild.Id, cancellationToken)) - _roles[role.Id] = role; + _rolesById[role.Id] = role; } // Because members cannot be pulled in bulk, we need to populate them on demand @@ -50,7 +50,7 @@ internal class ExportContext User? fallbackUser, CancellationToken cancellationToken = default) { - if (_members.ContainsKey(id)) + if (_membersById.ContainsKey(id)) return; var member = await Discord.TryGetGuildMemberAsync(Request.Guild.Id, id, cancellationToken); @@ -67,7 +67,7 @@ internal class ExportContext } // Store the result even if it's null, to avoid re-fetching non-existing members - _members[id] = member; + _membersById[id] = member; } public async ValueTask PopulateMemberAsync(Snowflake id, CancellationToken cancellationToken = default) => @@ -83,11 +83,11 @@ internal class ExportContext var format => instant.ToLocalString(format) }; - public Member? TryGetMember(Snowflake id) => _members.GetValueOrDefault(id); + public Member? TryGetMember(Snowflake id) => _membersById.GetValueOrDefault(id); - public Channel? TryGetChannel(Snowflake id) => _channels.GetValueOrDefault(id); + public Channel? TryGetChannel(Snowflake id) => _channelsById.GetValueOrDefault(id); - public Role? TryGetRole(Snowflake id) => _roles.GetValueOrDefault(id); + public Role? TryGetRole(Snowflake id) => _rolesById.GetValueOrDefault(id); public IReadOnlyList GetUserRoles(Snowflake id) => TryGetMember(id)? .RoleIds