mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2026-08-15 06:53:13 -06:00
Add path placeholders for threads
This commit is contained in:
parent
9b8985a920
commit
7bfb1c6fcc
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -1,5 +1,6 @@
|
||||||
# User-specific files
|
# User-specific files
|
||||||
.vs/
|
.vs/
|
||||||
|
.vscode/
|
||||||
.idea/
|
.idea/
|
||||||
*.suo
|
*.suo
|
||||||
*.user
|
*.user
|
||||||
|
|
|
||||||
|
|
@ -154,27 +154,39 @@ public partial class ExportRequest
|
||||||
Channel channel,
|
Channel channel,
|
||||||
Snowflake? after,
|
Snowflake? after,
|
||||||
Snowflake? before
|
Snowflake? before
|
||||||
) =>
|
)
|
||||||
Regex.Replace(
|
{
|
||||||
|
string preFormattedPath = Regex.Replace(
|
||||||
path,
|
path,
|
||||||
"%.",
|
"%.",
|
||||||
m =>
|
m =>
|
||||||
PathEx.EscapeFileName(
|
PathEx.EscapeFileName(
|
||||||
m.Value switch
|
m.Value switch
|
||||||
{
|
{
|
||||||
|
// On %T and %P, we have to make sure that we still get name and position of the category if the channel is a thread
|
||||||
"%g" => guild.Id.ToString(),
|
"%g" => guild.Id.ToString(),
|
||||||
"%G" => guild.Name,
|
"%G" => guild.Name,
|
||||||
|
|
||||||
"%t" => channel.Parent?.Id.ToString() ?? "",
|
"%t" => channel.Parent?.Id.ToString() ?? "",
|
||||||
"%T" => channel.Parent?.Name ?? "",
|
"%T"
|
||||||
|
=> channel.IsThread
|
||||||
|
? (channel.Parent?.Parent?.Name ?? "")
|
||||||
|
: channel.Parent?.Name ?? "",
|
||||||
|
|
||||||
"%c" => channel.Id.ToString(),
|
"%c" => channel.Id.ToString(),
|
||||||
"%C" => channel.Name,
|
"%C" => channel.Name,
|
||||||
|
|
||||||
"%p" => channel.Position?.ToString(CultureInfo.InvariantCulture) ?? "0",
|
"%p" => channel.Position?.ToString(CultureInfo.InvariantCulture) ?? "0",
|
||||||
"%P"
|
"%P"
|
||||||
=> channel.Parent?.Position?.ToString(CultureInfo.InvariantCulture)
|
=> channel.IsThread
|
||||||
?? "0",
|
? (
|
||||||
|
channel
|
||||||
|
.Parent?.Parent
|
||||||
|
?.Position
|
||||||
|
?.ToString(CultureInfo.InvariantCulture) ?? ""
|
||||||
|
)
|
||||||
|
: channel.Parent?.Position?.ToString(CultureInfo.InvariantCulture)
|
||||||
|
?? "0",
|
||||||
|
|
||||||
"%a"
|
"%a"
|
||||||
=> after?.ToDate().ToString("yyyy-MM-dd", CultureInfo.InvariantCulture)
|
=> after?.ToDate().ToString("yyyy-MM-dd", CultureInfo.InvariantCulture)
|
||||||
|
|
@ -194,6 +206,31 @@ public partial class ExportRequest
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// We are looking for any structure in the path which contains either %y or %z. If the channel is a thread, we can resolve the placeholders, otherwise, that whole structure needs to be removed.
|
||||||
|
string formattedPath = Regex.Replace(
|
||||||
|
preFormattedPath,
|
||||||
|
@"\\[^\\]*%[yz][^\\]*\\",
|
||||||
|
m =>
|
||||||
|
channel.IsThread
|
||||||
|
? Regex.Replace(
|
||||||
|
m.Value,
|
||||||
|
"%[yz]",
|
||||||
|
n =>
|
||||||
|
n.Value switch
|
||||||
|
{
|
||||||
|
"%y"
|
||||||
|
=> channel
|
||||||
|
.Parent?.Position
|
||||||
|
?.ToString(CultureInfo.InvariantCulture) ?? "",
|
||||||
|
"%z" => channel.Parent?.Name ?? "",
|
||||||
|
_ => n.Value
|
||||||
|
}
|
||||||
|
)
|
||||||
|
: "\\"
|
||||||
|
);
|
||||||
|
return formattedPath;
|
||||||
|
}
|
||||||
|
|
||||||
private static string GetOutputBaseFilePath(
|
private static string GetOutputBaseFilePath(
|
||||||
Guild guild,
|
Guild guild,
|
||||||
Channel channel,
|
Channel channel,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue