mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2025-05-22 10:55:15 -04:00
Refactor IsTextChannel
and IsVoiceChannel
to extensions
This commit is contained in:
parent
5755334492
commit
2c7986c4e6
10 changed files with 26 additions and 19 deletions
|
@ -33,7 +33,7 @@ public class ExportAllCommand : ExportCommandBase
|
||||||
await foreach (var channel in Discord.GetGuildChannelsAsync(guild.Id, cancellationToken))
|
await foreach (var channel in Discord.GetGuildChannelsAsync(guild.Id, cancellationToken))
|
||||||
{
|
{
|
||||||
// Skip non-text channels
|
// Skip non-text channels
|
||||||
if (!channel.IsTextChannel)
|
if (!channel.Kind.IsText())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
channels.Add(channel);
|
channels.Add(channel);
|
||||||
|
|
|
@ -19,7 +19,7 @@ public class ExportDirectMessagesCommand : ExportCommandBase
|
||||||
|
|
||||||
await console.Output.WriteLineAsync("Fetching channels...");
|
await console.Output.WriteLineAsync("Fetching channels...");
|
||||||
var channels = await Discord.GetGuildChannelsAsync(Guild.DirectMessages.Id, cancellationToken);
|
var channels = await Discord.GetGuildChannelsAsync(Guild.DirectMessages.Id, cancellationToken);
|
||||||
var textChannels = channels.Where(c => c.IsTextChannel).ToArray();
|
var textChannels = channels.Where(c => c.Kind.IsText()).ToArray();
|
||||||
|
|
||||||
await base.ExecuteAsync(console, textChannels);
|
await base.ExecuteAsync(console, textChannels);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ using CliFx.Attributes;
|
||||||
using CliFx.Infrastructure;
|
using CliFx.Infrastructure;
|
||||||
using DiscordChatExporter.Cli.Commands.Base;
|
using DiscordChatExporter.Cli.Commands.Base;
|
||||||
using DiscordChatExporter.Core.Discord;
|
using DiscordChatExporter.Core.Discord;
|
||||||
|
using DiscordChatExporter.Core.Discord.Data;
|
||||||
using DiscordChatExporter.Core.Utils.Extensions;
|
using DiscordChatExporter.Core.Utils.Extensions;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Cli.Commands;
|
namespace DiscordChatExporter.Cli.Commands;
|
||||||
|
@ -27,7 +28,7 @@ public class ExportGuildCommand : ExportCommandBase
|
||||||
|
|
||||||
await console.Output.WriteLineAsync("Fetching channels...");
|
await console.Output.WriteLineAsync("Fetching channels...");
|
||||||
var channels = await Discord.GetGuildChannelsAsync(GuildId, cancellationToken);
|
var channels = await Discord.GetGuildChannelsAsync(GuildId, cancellationToken);
|
||||||
var textChannels = channels.Where(c => c.IsTextChannel).ToArray();
|
var textChannels = channels.Where(c => c.Kind.IsText()).ToArray();
|
||||||
|
|
||||||
await base.ExecuteAsync(console, textChannels);
|
await base.ExecuteAsync(console, textChannels);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ using CliFx.Attributes;
|
||||||
using CliFx.Infrastructure;
|
using CliFx.Infrastructure;
|
||||||
using DiscordChatExporter.Cli.Commands.Base;
|
using DiscordChatExporter.Cli.Commands.Base;
|
||||||
using DiscordChatExporter.Core.Discord;
|
using DiscordChatExporter.Core.Discord;
|
||||||
|
using DiscordChatExporter.Core.Discord.Data;
|
||||||
using DiscordChatExporter.Core.Utils.Extensions;
|
using DiscordChatExporter.Core.Utils.Extensions;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Cli.Commands;
|
namespace DiscordChatExporter.Cli.Commands;
|
||||||
|
@ -27,7 +28,7 @@ public class GetChannelsCommand : TokenCommandBase
|
||||||
var channels = await Discord.GetGuildChannelsAsync(GuildId, cancellationToken);
|
var channels = await Discord.GetGuildChannelsAsync(GuildId, cancellationToken);
|
||||||
|
|
||||||
var textChannels = channels
|
var textChannels = channels
|
||||||
.Where(c => c.IsTextChannel)
|
.Where(c => c.Kind.IsText())
|
||||||
.OrderBy(c => c.Category.Position)
|
.OrderBy(c => c.Category.Position)
|
||||||
.ThenBy(c => c.Name)
|
.ThenBy(c => c.Name)
|
||||||
.ToArray();
|
.ToArray();
|
||||||
|
|
|
@ -19,7 +19,7 @@ public class GetDirectMessageChannelsCommand : TokenCommandBase
|
||||||
var channels = await Discord.GetGuildChannelsAsync(Guild.DirectMessages.Id, cancellationToken);
|
var channels = await Discord.GetGuildChannelsAsync(Guild.DirectMessages.Id, cancellationToken);
|
||||||
|
|
||||||
var textChannels = channels
|
var textChannels = channels
|
||||||
.Where(c => c.IsTextChannel)
|
.Where(c => c.Kind.IsText())
|
||||||
.OrderBy(c => c.Category.Position)
|
.OrderBy(c => c.Category.Position)
|
||||||
.ThenBy(c => c.Name)
|
.ThenBy(c => c.Name)
|
||||||
.ToArray();
|
.ToArray();
|
||||||
|
|
|
@ -14,17 +14,8 @@ public partial record Channel(
|
||||||
ChannelCategory Category,
|
ChannelCategory Category,
|
||||||
string Name,
|
string Name,
|
||||||
int? Position,
|
int? Position,
|
||||||
string? Topic) : IHasId
|
string? Topic
|
||||||
{
|
) : IHasId;
|
||||||
public bool IsTextChannel => Kind is
|
|
||||||
ChannelKind.GuildTextChat or
|
|
||||||
ChannelKind.DirectTextChat or
|
|
||||||
ChannelKind.DirectGroupTextChat or
|
|
||||||
ChannelKind.GuildNews or
|
|
||||||
ChannelKind.GuildStore;
|
|
||||||
|
|
||||||
public bool IsVoiceChannel => !IsTextChannel;
|
|
||||||
}
|
|
||||||
|
|
||||||
public partial record Channel
|
public partial record Channel
|
||||||
{
|
{
|
||||||
|
|
|
@ -12,3 +12,16 @@ public enum ChannelKind
|
||||||
GuildNews,
|
GuildNews,
|
||||||
GuildStore
|
GuildStore
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class ChannelKindExtensions
|
||||||
|
{
|
||||||
|
public static bool IsText(this ChannelKind kind) => kind is
|
||||||
|
ChannelKind.GuildTextChat or
|
||||||
|
ChannelKind.DirectTextChat or
|
||||||
|
ChannelKind.DirectGroupTextChat or
|
||||||
|
ChannelKind.GuildNews or
|
||||||
|
ChannelKind.GuildStore;
|
||||||
|
|
||||||
|
public static bool IsVoice(this ChannelKind kind) => kind is
|
||||||
|
ChannelKind.GuildVoiceChat;
|
||||||
|
}
|
|
@ -158,7 +158,7 @@ internal partial class HtmlMarkdownVisitor : MarkdownVisitor
|
||||||
else if (mention.Kind == MentionKind.Channel)
|
else if (mention.Kind == MentionKind.Channel)
|
||||||
{
|
{
|
||||||
var channel = mention.TargetId?.Pipe(_context.TryGetChannel);
|
var channel = mention.TargetId?.Pipe(_context.TryGetChannel);
|
||||||
var symbol = channel?.IsVoiceChannel == true ? "🔊" : "#";
|
var symbol = channel?.Kind.IsVoice() == true ? "🔊" : "#";
|
||||||
var name = channel?.Name ?? "deleted-channel";
|
var name = channel?.Name ?? "deleted-channel";
|
||||||
|
|
||||||
_buffer
|
_buffer
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using DiscordChatExporter.Core.Discord.Data;
|
||||||
using DiscordChatExporter.Core.Markdown;
|
using DiscordChatExporter.Core.Markdown;
|
||||||
using DiscordChatExporter.Core.Markdown.Parsing;
|
using DiscordChatExporter.Core.Markdown.Parsing;
|
||||||
using DiscordChatExporter.Core.Utils.Extensions;
|
using DiscordChatExporter.Core.Utils.Extensions;
|
||||||
|
@ -58,7 +59,7 @@ internal partial class PlainTextMarkdownVisitor : MarkdownVisitor
|
||||||
_buffer.Append($"#{name}");
|
_buffer.Append($"#{name}");
|
||||||
|
|
||||||
// Voice channel marker
|
// Voice channel marker
|
||||||
if (channel?.IsVoiceChannel == true)
|
if (channel?.Kind.IsVoice() == true)
|
||||||
_buffer.Append(" [voice]");
|
_buffer.Append(" [voice]");
|
||||||
}
|
}
|
||||||
else if (mention.Kind == MentionKind.Role)
|
else if (mention.Kind == MentionKind.Role)
|
||||||
|
|
|
@ -105,7 +105,7 @@ public class DashboardViewModel : PropertyChangedBase
|
||||||
await foreach (var guild in discord.GetUserGuildsAsync())
|
await foreach (var guild in discord.GetUserGuildsAsync())
|
||||||
{
|
{
|
||||||
var channels = await discord.GetGuildChannelsAsync(guild.Id);
|
var channels = await discord.GetGuildChannelsAsync(guild.Id);
|
||||||
guildChannelMap[guild] = channels.Where(c => c.IsTextChannel).ToArray();
|
guildChannelMap[guild] = channels.Where(c => c.Kind.IsText()).ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
_discord = discord;
|
_discord = discord;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue