diff --git a/DiscordChatExporter.Core/Discord/DiscordClient.cs b/DiscordChatExporter.Core/Discord/DiscordClient.cs index 27bf0e1c..41b9aa04 100644 --- a/DiscordChatExporter.Core/Discord/DiscordClient.cs +++ b/DiscordChatExporter.Core/Discord/DiscordClient.cs @@ -194,7 +194,7 @@ namespace DiscordChatExporter.Core.Discord var parentId = response.GetPropertyOrNull("parent_id")?.GetString().Pipe(Snowflake.Parse); - var category = parentId != null + var category = parentId is not null ? await GetChannelCategoryAsync(parentId.Value) : null; @@ -224,7 +224,7 @@ namespace DiscordChatExporter.Core.Discord // will not appear in the output. // Additionally, it provides the date of the last message, which is used to calculate progress. var lastMessage = await TryGetLastMessageAsync(channelId, before); - if (lastMessage == null || lastMessage.Timestamp < after?.ToDate()) + if (lastMessage is null || lastMessage.Timestamp < after?.ToDate()) yield break; // Keep track of first message in range in order to calculate progress diff --git a/DiscordChatExporter.Core/Exporting/ExportContext.cs b/DiscordChatExporter.Core/Exporting/ExportContext.cs index 929832c1..f6b760c2 100644 --- a/DiscordChatExporter.Core/Exporting/ExportContext.cs +++ b/DiscordChatExporter.Core/Exporting/ExportContext.cs @@ -57,7 +57,7 @@ namespace DiscordChatExporter.Core.Exporting var roles = member?.RoleIds.Join(Roles, i => i, r => r.Id, (_, role) => role); return roles? - .Where(r => r.Color != null) + .Where(r => r.Color is not null) .OrderByDescending(r => r.Position) .Select(r => r.Color) .FirstOrDefault(); diff --git a/DiscordChatExporter.Core/Exporting/ExportRequest.cs b/DiscordChatExporter.Core/Exporting/ExportRequest.cs index c216fdb3..c2c5a9e8 100644 --- a/DiscordChatExporter.Core/Exporting/ExportRequest.cs +++ b/DiscordChatExporter.Core/Exporting/ExportRequest.cs @@ -127,17 +127,17 @@ namespace DiscordChatExporter.Core.Exporting buffer.Append($"{guild.Name} - {channel.Category.Name} - {channel.Name} [{channel.Id}]"); // Date range - if (after != null || before != null) + if (after is not null || before is not null) { buffer.Append(" ("); // Both 'after' and 'before' are set - if (after != null && before != null) + if (after is not null && before is not null) { buffer.Append($"{after?.ToDate():yyyy-MM-dd} to {before?.ToDate():yyyy-MM-dd}"); } // Only 'after' is set - else if (after != null) + else if (after is not null) { buffer.Append($"after {after?.ToDate():yyyy-MM-dd}"); } diff --git a/DiscordChatExporter.Core/Exporting/MediaDownloader.cs b/DiscordChatExporter.Core/Exporting/MediaDownloader.cs index 515b7cc5..007a33b8 100644 --- a/DiscordChatExporter.Core/Exporting/MediaDownloader.cs +++ b/DiscordChatExporter.Core/Exporting/MediaDownloader.cs @@ -62,7 +62,7 @@ namespace DiscordChatExporter.Core.Exporting : (DateTimeOffset?) null ); - if (lastModified != null) + if (lastModified is not null) { File.SetCreationTimeUtc(filePath, lastModified.Value.UtcDateTime); File.SetLastWriteTimeUtc(filePath, lastModified.Value.UtcDateTime); diff --git a/DiscordChatExporter.Core/Exporting/MessageExporter.cs b/DiscordChatExporter.Core/Exporting/MessageExporter.cs index 451006d0..d5b76241 100644 --- a/DiscordChatExporter.Core/Exporting/MessageExporter.cs +++ b/DiscordChatExporter.Core/Exporting/MessageExporter.cs @@ -21,13 +21,13 @@ namespace DiscordChatExporter.Core.Exporting private bool IsPartitionLimitReached() => _messageCount > 0 && - _context.Request.PartitionLimit != null && + _context.Request.PartitionLimit is not null && _context.Request.PartitionLimit != 0 && _messageCount % _context.Request.PartitionLimit == 0; private async ValueTask ResetWriterAsync() { - if (_writer != null) + if (_writer is not null) { await _writer.WritePostambleAsync(); await _writer.DisposeAsync(); @@ -45,7 +45,7 @@ namespace DiscordChatExporter.Core.Exporting } // Writer is still valid - return - if (_writer != null) + if (_writer is not null) return _writer; var filePath = GetPartitionFilePath(_context.Request.OutputBaseFilePath, _partitionIndex); diff --git a/DiscordChatExporter.Core/Exporting/Writers/Html/MessageGroupTemplate.cshtml b/DiscordChatExporter.Core/Exporting/Writers/Html/MessageGroupTemplate.cshtml index 18ca5420..1b9055b4 100644 --- a/DiscordChatExporter.Core/Exporting/Writers/Html/MessageGroupTemplate.cshtml +++ b/DiscordChatExporter.Core/Exporting/Writers/Html/MessageGroupTemplate.cshtml @@ -17,7 +17,7 @@ var userColor = Model.ExportContext.TryGetUserColor(Model.MessageGroup.Author.Id); - var userColorStyle = userColor != null + var userColorStyle = userColor is not null ? $"color: rgb({userColor?.R},{userColor?.G},{userColor?.B})" : null; @@ -25,19 +25,19 @@ ? Model.MessageGroup.Author.Name : userMember?.Nick ?? Model.MessageGroup.Author.Name; - var referencedUserMember = Model.MessageGroup.ReferencedMessage != null + var referencedUserMember = Model.MessageGroup.ReferencedMessage is not null ? Model.ExportContext.TryGetMember(Model.MessageGroup.ReferencedMessage.Author.Id) : null; - var referencedUserColor = Model.MessageGroup.ReferencedMessage != null + var referencedUserColor = Model.MessageGroup.ReferencedMessage is not null ? Model.ExportContext.TryGetUserColor(Model.MessageGroup.ReferencedMessage.Author.Id) : null; - var referencedUserColorStyle = referencedUserColor != null + var referencedUserColorStyle = referencedUserColor is not null ? $"color: rgb({referencedUserColor?.R},{referencedUserColor?.G},{referencedUserColor?.B})" : null; - var referencedUserNick = Model.MessageGroup.ReferencedMessage != null + var referencedUserNick = Model.MessageGroup.ReferencedMessage is not null ? Model.MessageGroup.ReferencedMessage.Author.IsBot ? Model.MessageGroup.ReferencedMessage.Author.Name : referencedUserMember?.Nick ?? Model.MessageGroup.ReferencedMessage.Author.Name @@ -45,12 +45,12 @@ }