Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyrrrz committed Nov 17, 2023
1 parent 576ee73 commit 008c2e6
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 19 deletions.
4 changes: 2 additions & 2 deletions DiscordChatExporter.Cli.Tests/Infra/ExportWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ Snowflake messageId
if (message is null)
{
throw new InvalidOperationException(
$"Message #{messageId} does not exist in the export of channel #{channelId}."
$"Message #{messageId} not found in the export of channel #{channelId}."
);
}

Expand All @@ -129,7 +129,7 @@ Snowflake messageId
if (message.ValueKind == JsonValueKind.Undefined)
{
throw new InvalidOperationException(
$"Message #{messageId} does not exist in the export of channel #{channelId}."
$"Message #{messageId} not found in the export of channel #{channelId}."
);
}

Expand Down
3 changes: 1 addition & 2 deletions DiscordChatExporter.Cli/Commands/Base/ExportCommandBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,7 @@ protected async ValueTask ExportAsync(IConsole console, IReadOnlyList<Channel> c
throw new CommandException(
"Attempted to export multiple channels, but the output path is neither a directory nor a template. "
+ "If the provided output path is meant to be treated as a directory, make sure it ends with a slash. "
+ "Provided output path: "
+ OutputPath
+ $"Provided output path: '{OutputPath}'."
);
}

Expand Down
2 changes: 1 addition & 1 deletion DiscordChatExporter.Core/Discord/DiscordClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ public async IAsyncEnumerable<Message> GetMessagesAsync(
if (!application.IsMessageContentIntentEnabled)
{
throw new DiscordChatExporterException(
"Bot account does not have the Message Content Intent enabled.",
"Provided bot account does not have the Message Content Intent enabled.",
true
);
}
Expand Down
16 changes: 8 additions & 8 deletions DiscordChatExporter.Core/Discord/Snowflake.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,26 @@ public partial record struct Snowflake
public static Snowflake FromDate(DateTimeOffset instant) =>
new(((ulong)instant.ToUnixTimeMilliseconds() - 1420070400000UL) << 22);

public static Snowflake? TryParse(string? str, IFormatProvider? formatProvider = null)
public static Snowflake? TryParse(string? value, IFormatProvider? formatProvider = null)
{
if (string.IsNullOrWhiteSpace(str))
if (string.IsNullOrWhiteSpace(value))
return null;

// As number
if (ulong.TryParse(str, NumberStyles.None, formatProvider, out var value))
return new Snowflake(value);
if (ulong.TryParse(value, NumberStyles.None, formatProvider, out var number))
return new Snowflake(number);

// As date
if (DateTimeOffset.TryParse(str, formatProvider, DateTimeStyles.None, out var instant))
if (DateTimeOffset.TryParse(value, formatProvider, DateTimeStyles.None, out var instant))
return FromDate(instant);

return null;
}

public static Snowflake Parse(string str, IFormatProvider? formatProvider) =>
TryParse(str, formatProvider) ?? throw new FormatException($"Invalid snowflake '{str}'.");
public static Snowflake Parse(string value, IFormatProvider? formatProvider) =>
TryParse(value, formatProvider) ?? throw new FormatException($"Invalid snowflake '{value}'.");

public static Snowflake Parse(string str) => Parse(str, null);
public static Snowflake Parse(string value) => Parse(value, null);
}

public partial record struct Snowflake : IComparable<Snowflake>, IComparable
Expand Down
24 changes: 18 additions & 6 deletions DiscordChatExporter.Core/Exporting/ChannelExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ public async ValueTask ExportChannelAsync(
if (request.Channel.Kind == ChannelKind.GuildForum)
{
throw new DiscordChatExporterException(
$"Channel '{request.Channel.Name}' (#{request.Channel.Id}) is a forum and cannot be exported directly. "
$"Channel '{request.Channel.Name}' (#{request.Channel.Id}) "
+ $"of guild '{request.Guild.Name}' (#{request.Guild.Id}) "
+ $"is a forum and cannot be exported directly. "
+ "You need to pull its threads and export them individually."
);
}
Expand All @@ -31,15 +33,19 @@ public async ValueTask ExportChannelAsync(
if (request.Channel.IsEmpty)
{
throw new DiscordChatExporterException(
$"Channel '{request.Channel.Name}' (#{request.Channel.Id}) does not contain any messages."
$"Channel '{request.Channel.Name}' (#{request.Channel.Id}) "
+ $"of guild '{request.Guild.Name}' (#{request.Guild.Id}) "
+ $"does not contain any messages."
);
}

// Check if the 'after' boundary is valid
if (request.After is not null && !request.Channel.MayHaveMessagesAfter(request.After.Value))
{
throw new DiscordChatExporterException(
$"Channel '{request.Channel.Name}' (#{request.Channel.Id}) does not contain any messages within the specified period."
$"Channel '{request.Channel.Name}' (#{request.Channel.Id}) "
+ $"of guild '{request.Guild.Name}' (#{request.Guild.Id}) "
+ $"does not contain any messages within the specified period."
);
}

Expand All @@ -50,7 +56,9 @@ request.Before is not null
)
{
throw new DiscordChatExporterException(
$"Channel '{request.Channel.Name}' (#{request.Channel.Id}) does not contain any messages within the specified period."
$"Channel '{request.Channel.Name}' (#{request.Channel.Id}) "
+ $"of guild '{request.Guild.Name}' (#{request.Guild.Id}) "
+ $"does not contain any messages within the specified period."
);
}

Expand Down Expand Up @@ -84,7 +92,9 @@ var message in _discord.GetMessagesAsync(
{
// Provide more context to the exception, to simplify debugging based on error messages
throw new DiscordChatExporterException(
$"Failed to export message #{message.Id} in channel '{request.Channel.Name}' (#{request.Channel.Id}).",
$"Failed to export message #{message.Id} "
+ $"in channel '{request.Channel.Name}' (#{request.Channel.Id}) "
+ $"of guild '{request.Guild.Name} (#{request.Guild.Id})'.",
ex is not DiscordChatExporterException dex || dex.IsFatal,
ex
);
Expand All @@ -95,7 +105,9 @@ var message in _discord.GetMessagesAsync(
if (messageExporter.MessagesExported <= 0)
{
throw new DiscordChatExporterException(
$"Channel '{request.Channel.Name}' (#{request.Channel.Id}) does not contain any matching messages within the specified period."
$"Channel '{request.Channel.Name}' (#{request.Channel.Id}) "
+ $"of guild '{request.Guild.Name}' (#{request.Guild.Id}) "
+ $"does not contain any matching messages within the specified period."
);
}
}
Expand Down

0 comments on commit 008c2e6

Please sign in to comment.