mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2026-05-07 13:28:45 -05:00
Agent-Logs-Url: https://github.com/Tyrrrz/DiscordChatExporter/sessions/58698f45-e22e-4bd4-aec4-31f801051467 Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>
33 lines
1.1 KiB
C#
33 lines
1.1 KiB
C#
using System.Linq;
|
|
using System.Text.Json;
|
|
using System.Threading.Tasks;
|
|
using CliFx.Binding;
|
|
using CliFx.Infrastructure;
|
|
using DiscordChatExporter.Cli.Commands.Base;
|
|
using DiscordChatExporter.Cli.Utils.Json;
|
|
using DiscordChatExporter.Core.Discord.Data;
|
|
using DiscordChatExporter.Core.Utils.Extensions;
|
|
|
|
namespace DiscordChatExporter.Cli.Commands;
|
|
|
|
[Command("list servers", Description = "Gets the list of accessible servers.")]
|
|
public partial class GetGuildsCommand : DiscordCommandBase
|
|
{
|
|
public override async ValueTask ExecuteAsync(IConsole console)
|
|
{
|
|
await base.ExecuteAsync(console);
|
|
|
|
var cancellationToken = console.RegisterCancellationHandler();
|
|
|
|
var guilds = (await Discord.GetUserGuildsAsync(cancellationToken))
|
|
// Show direct messages first
|
|
.OrderByDescending(g => g.Id == Guild.DirectMessages.Id)
|
|
.ThenBy(g => g.Name)
|
|
.ToArray();
|
|
|
|
await console.Output.WriteLineAsync(
|
|
JsonSerializer.Serialize(guilds, CliJsonSerializerContext.Instance.GuildArray)
|
|
);
|
|
}
|
|
}
|