|
|
|
@ -27,45 +27,35 @@ public class ChannelExporter(DiscordClient discord)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Build context
|
|
|
|
|
var context = new ExportContext(discord, request);
|
|
|
|
|
await context.PopulateChannelsAndRolesAsync(cancellationToken);
|
|
|
|
|
|
|
|
|
|
// Export messages
|
|
|
|
|
await using var messageExporter = new MessageExporter(context);
|
|
|
|
|
await messageExporter.EnsureFileIsCreated(cancellationToken);
|
|
|
|
|
|
|
|
|
|
// Check if the channel is empty
|
|
|
|
|
if (request.Channel.IsEmpty)
|
|
|
|
|
{
|
|
|
|
|
throw new DiscordChatExporterException(
|
|
|
|
|
$"Channel '{request.Channel.Name}' "
|
|
|
|
|
+ $"of guild '{request.Guild.Name}' "
|
|
|
|
|
+ $"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(
|
|
|
|
|
throw new ChannelNotExportedException(
|
|
|
|
|
$"Channel '{request.Channel.Name}' "
|
|
|
|
|
+ $"of guild '{request.Guild.Name}' "
|
|
|
|
|
+ $"does not contain any messages within the specified period."
|
|
|
|
|
+ $"does not contain any messages; an empty file will be created."
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check if the 'before' boundary is valid
|
|
|
|
|
if (
|
|
|
|
|
request.Before is not null
|
|
|
|
|
&& !request.Channel.MayHaveMessagesBefore(request.Before.Value)
|
|
|
|
|
)
|
|
|
|
|
// Check if the 'before' and 'after' boundaries are valid
|
|
|
|
|
if ((request.Before is not null && !request.Channel.MayHaveMessagesBefore(request.Before.Value)) ||
|
|
|
|
|
(request.After is not null && !request.Channel.MayHaveMessagesAfter(request.After.Value)))
|
|
|
|
|
{
|
|
|
|
|
throw new DiscordChatExporterException(
|
|
|
|
|
throw new ChannelNotExportedException(
|
|
|
|
|
$"Channel '{request.Channel.Name}' "
|
|
|
|
|
+ $"of guild '{request.Guild.Name}' "
|
|
|
|
|
+ $"does not contain any messages within the specified period."
|
|
|
|
|
+ $"does not contain any messages within the specified period; an empty file will be created."
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Build context
|
|
|
|
|
var context = new ExportContext(discord, request);
|
|
|
|
|
await context.PopulateChannelsAndRolesAsync(cancellationToken);
|
|
|
|
|
|
|
|
|
|
// Export messages
|
|
|
|
|
await using var messageExporter = new MessageExporter(context);
|
|
|
|
|
await foreach (
|
|
|
|
|
var message in discord.GetMessagesAsync(
|
|
|
|
|
request.Channel.Id,
|
|
|
|
@ -98,15 +88,5 @@ public class ChannelExporter(DiscordClient discord)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Throw if no messages were exported
|
|
|
|
|
if (messageExporter.MessagesExported <= 0)
|
|
|
|
|
{
|
|
|
|
|
throw new DiscordChatExporterException(
|
|
|
|
|
$"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."
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|