mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2026-04-04 03:23:05 -06:00
Agent-Logs-Url: https://github.com/Tyrrrz/DiscordChatExporter/sessions/27f23ff6-5b39-46d3-a7dc-387749ee63fa Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>
59 lines
1.9 KiB
C#
59 lines
1.9 KiB
C#
using System;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using CliFx.Binding;
|
|
using CliFx.Infrastructure;
|
|
using DiscordChatExporter.Cli.Commands.Base;
|
|
using DiscordChatExporter.Core.Discord.Data;
|
|
using DiscordChatExporter.Core.Utils.Extensions;
|
|
|
|
namespace DiscordChatExporter.Cli.Commands;
|
|
|
|
[Command("list channels dm", Description = "Gets the list of direct message channels.")]
|
|
public partial class GetDirectChannelsCommand : DiscordCommandBase
|
|
{
|
|
public override async ValueTask ExecuteAsync(IConsole console)
|
|
{
|
|
await base.ExecuteAsync(console);
|
|
|
|
var cancellationToken = console.RegisterCancellationHandler();
|
|
|
|
var channels = (
|
|
await Discord.GetGuildChannelsAsync(Guild.DirectMessages.Id, cancellationToken)
|
|
)
|
|
.OrderByDescending(c => c.LastMessageId)
|
|
.ThenBy(c => c.Name)
|
|
.ToArray();
|
|
|
|
var channelIdMaxLength = channels
|
|
.Select(c => c.Id.ToString().Length)
|
|
.OrderDescending()
|
|
.FirstOrDefault();
|
|
|
|
// If output is redirected, print only channel IDs (one per line) for easy piping
|
|
if (console.IsOutputRedirected)
|
|
{
|
|
foreach (var channel in channels)
|
|
await console.Output.WriteLineAsync(channel.Id.ToString());
|
|
}
|
|
else
|
|
{
|
|
foreach (var channel in channels)
|
|
{
|
|
// Channel ID
|
|
await console.Output.WriteAsync(
|
|
channel.Id.ToString().PadRight(channelIdMaxLength, ' ')
|
|
);
|
|
|
|
// Separator
|
|
using (console.WithForegroundColor(ConsoleColor.DarkGray))
|
|
await console.Output.WriteAsync(" | ");
|
|
|
|
// Channel name
|
|
using (console.WithForegroundColor(ConsoleColor.White))
|
|
await console.Output.WriteLineAsync(channel.GetHierarchicalName());
|
|
}
|
|
}
|
|
}
|
|
}
|