mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2025-05-31 06:48:23 -04:00
parent
492003c75a
commit
e493357a9f
4 changed files with 81 additions and 50 deletions
28
DiscordChatExporter.Cli/Internal/InlineProgress.cs
Normal file
28
DiscordChatExporter.Cli/Internal/InlineProgress.cs
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace DiscordChatExporter.Cli.Internal
|
||||||
|
{
|
||||||
|
internal class InlineProgress : IProgress<double>, IDisposable
|
||||||
|
{
|
||||||
|
private readonly int _posX;
|
||||||
|
private readonly int _posY;
|
||||||
|
|
||||||
|
public InlineProgress()
|
||||||
|
{
|
||||||
|
_posX = Console.CursorLeft;
|
||||||
|
_posY = Console.CursorTop;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Report(double progress)
|
||||||
|
{
|
||||||
|
Console.SetCursorPosition(_posX, _posY);
|
||||||
|
Console.WriteLine($"{progress:P1}");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
Console.SetCursorPosition(_posX, _posY);
|
||||||
|
Console.WriteLine("Completed ✓");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using DiscordChatExporter.Cli.Internal;
|
||||||
using DiscordChatExporter.Cli.Verbs.Options;
|
using DiscordChatExporter.Cli.Verbs.Options;
|
||||||
using DiscordChatExporter.Core.Helpers;
|
using DiscordChatExporter.Core.Helpers;
|
||||||
using DiscordChatExporter.Core.Services;
|
using DiscordChatExporter.Core.Services;
|
||||||
|
@ -28,9 +29,13 @@ namespace DiscordChatExporter.Cli.Verbs
|
||||||
if (Options.MessageGroupLimit > 0)
|
if (Options.MessageGroupLimit > 0)
|
||||||
settingsService.MessageGroupLimit = Options.MessageGroupLimit;
|
settingsService.MessageGroupLimit = Options.MessageGroupLimit;
|
||||||
|
|
||||||
|
// Track progress
|
||||||
|
Console.Write($"Exporting channel [{Options.ChannelId}]... ");
|
||||||
|
using (var progress = new InlineProgress())
|
||||||
|
{
|
||||||
// Get chat log
|
// Get chat log
|
||||||
var chatLog = await dataService.GetChatLogAsync(Options.GetToken(), Options.ChannelId,
|
var chatLog = await dataService.GetChatLogAsync(Options.GetToken(), Options.ChannelId,
|
||||||
Options.After, Options.Before);
|
Options.After, Options.Before, progress);
|
||||||
|
|
||||||
// Generate file path if not set or is a directory
|
// Generate file path if not set or is a directory
|
||||||
var filePath = Options.OutputPath;
|
var filePath = Options.OutputPath;
|
||||||
|
@ -46,9 +51,7 @@ namespace DiscordChatExporter.Cli.Verbs
|
||||||
|
|
||||||
// Export
|
// Export
|
||||||
exportService.ExportChatLog(chatLog, filePath, Options.ExportFormat, Options.PartitionLimit);
|
exportService.ExportChatLog(chatLog, filePath, Options.ExportFormat, Options.PartitionLimit);
|
||||||
|
}
|
||||||
// Print result
|
|
||||||
Console.WriteLine($"Exported chat to [{filePath}]");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -3,6 +3,7 @@ using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using DiscordChatExporter.Cli.Internal;
|
||||||
using DiscordChatExporter.Cli.Verbs.Options;
|
using DiscordChatExporter.Cli.Verbs.Options;
|
||||||
using DiscordChatExporter.Core.Exceptions;
|
using DiscordChatExporter.Core.Exceptions;
|
||||||
using DiscordChatExporter.Core.Helpers;
|
using DiscordChatExporter.Core.Helpers;
|
||||||
|
@ -42,12 +43,13 @@ namespace DiscordChatExporter.Cli.Verbs
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Print current channel name
|
// Track progress
|
||||||
Console.WriteLine($"Exporting chat from [{channel.Name}]...");
|
Console.Write($"Exporting channel [{channel.Name}]... ");
|
||||||
|
using (var progress = new InlineProgress())
|
||||||
|
{
|
||||||
// Get chat log
|
// Get chat log
|
||||||
var chatLog = await dataService.GetChatLogAsync(Options.GetToken(), channel,
|
var chatLog = await dataService.GetChatLogAsync(Options.GetToken(), channel,
|
||||||
Options.After, Options.Before);
|
Options.After, Options.Before, progress);
|
||||||
|
|
||||||
// Generate default file name
|
// Generate default file name
|
||||||
var fileName = ExportHelper.GetDefaultExportFileName(Options.ExportFormat, chatLog.Guild,
|
var fileName = ExportHelper.GetDefaultExportFileName(Options.ExportFormat, chatLog.Guild,
|
||||||
|
@ -58,9 +60,7 @@ namespace DiscordChatExporter.Cli.Verbs
|
||||||
|
|
||||||
// Export
|
// Export
|
||||||
exportService.ExportChatLog(chatLog, filePath, Options.ExportFormat, Options.PartitionLimit);
|
exportService.ExportChatLog(chatLog, filePath, Options.ExportFormat, Options.PartitionLimit);
|
||||||
|
}
|
||||||
// Print result
|
|
||||||
Console.WriteLine($"Exported chat to [{filePath}]");
|
|
||||||
}
|
}
|
||||||
catch (HttpErrorStatusCodeException ex) when (ex.StatusCode == HttpStatusCode.Forbidden)
|
catch (HttpErrorStatusCodeException ex) when (ex.StatusCode == HttpStatusCode.Forbidden)
|
||||||
{
|
{
|
||||||
|
|
|
@ -3,6 +3,7 @@ using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using DiscordChatExporter.Cli.Internal;
|
||||||
using DiscordChatExporter.Cli.Verbs.Options;
|
using DiscordChatExporter.Cli.Verbs.Options;
|
||||||
using DiscordChatExporter.Core.Exceptions;
|
using DiscordChatExporter.Core.Exceptions;
|
||||||
using DiscordChatExporter.Core.Helpers;
|
using DiscordChatExporter.Core.Helpers;
|
||||||
|
@ -43,12 +44,13 @@ namespace DiscordChatExporter.Cli.Verbs
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Print current channel name
|
// Track progress
|
||||||
Console.WriteLine($"Exporting chat from [{channel.Name}]...");
|
Console.Write($"Exporting channel [{channel.Name}]... ");
|
||||||
|
using (var progress = new InlineProgress())
|
||||||
|
{
|
||||||
// Get chat log
|
// Get chat log
|
||||||
var chatLog = await dataService.GetChatLogAsync(Options.GetToken(), channel,
|
var chatLog = await dataService.GetChatLogAsync(Options.GetToken(), channel,
|
||||||
Options.After, Options.Before);
|
Options.After, Options.Before, progress);
|
||||||
|
|
||||||
// Generate default file name
|
// Generate default file name
|
||||||
var fileName = ExportHelper.GetDefaultExportFileName(Options.ExportFormat, chatLog.Guild,
|
var fileName = ExportHelper.GetDefaultExportFileName(Options.ExportFormat, chatLog.Guild,
|
||||||
|
@ -59,9 +61,7 @@ namespace DiscordChatExporter.Cli.Verbs
|
||||||
|
|
||||||
// Export
|
// Export
|
||||||
exportService.ExportChatLog(chatLog, filePath, Options.ExportFormat, Options.PartitionLimit);
|
exportService.ExportChatLog(chatLog, filePath, Options.ExportFormat, Options.PartitionLimit);
|
||||||
|
}
|
||||||
// Print result
|
|
||||||
Console.WriteLine($"Exported chat to [{filePath}]");
|
|
||||||
}
|
}
|
||||||
catch (HttpErrorStatusCodeException ex) when (ex.StatusCode == HttpStatusCode.Forbidden)
|
catch (HttpErrorStatusCodeException ex) when (ex.StatusCode == HttpStatusCode.Forbidden)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue