|
|
|
@ -1,12 +1,11 @@
|
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text.Json;
|
|
|
|
|
using DiscordChatExporter.Domain.Discord.Models.Common;
|
|
|
|
|
using DiscordChatExporter.Domain.Utilities;
|
|
|
|
|
using DiscordChatExporter.Core.Discord.Data.Common;
|
|
|
|
|
using DiscordChatExporter.Core.Utils.Extensions;
|
|
|
|
|
using JsonExtensions.Reading;
|
|
|
|
|
using Tyrrrz.Extensions;
|
|
|
|
|
|
|
|
|
|
namespace DiscordChatExporter.Domain.Discord.Models
|
|
|
|
|
namespace DiscordChatExporter.Core.Discord.Data
|
|
|
|
|
{
|
|
|
|
|
// https://discord.com/developers/docs/resources/channel#channel-object-channel-types
|
|
|
|
|
// Order of enum fields needs to match the order in the docs.
|
|
|
|
@ -22,7 +21,7 @@ namespace DiscordChatExporter.Domain.Discord.Models
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// https://discord.com/developers/docs/resources/channel#channel-object
|
|
|
|
|
public partial class Channel : IHasIdAndPosition
|
|
|
|
|
public partial class Channel : IHasId, IHasPosition
|
|
|
|
|
{
|
|
|
|
|
public Snowflake Id { get; }
|
|
|
|
|
|
|
|
|
@ -45,12 +44,19 @@ namespace DiscordChatExporter.Domain.Discord.Models
|
|
|
|
|
|
|
|
|
|
public string? Topic { get; }
|
|
|
|
|
|
|
|
|
|
public Channel(Snowflake id, ChannelType type, Snowflake guildId, ChannelCategory? category, string name, int? position, string? topic)
|
|
|
|
|
public Channel(
|
|
|
|
|
Snowflake id,
|
|
|
|
|
ChannelType type,
|
|
|
|
|
Snowflake guildId,
|
|
|
|
|
ChannelCategory? category,
|
|
|
|
|
string name,
|
|
|
|
|
int? position,
|
|
|
|
|
string? topic)
|
|
|
|
|
{
|
|
|
|
|
Id = id;
|
|
|
|
|
Type = type;
|
|
|
|
|
GuildId = guildId;
|
|
|
|
|
Category = category ?? GetDefaultCategory(type);
|
|
|
|
|
Category = category ?? GetFallbackCategory(type);
|
|
|
|
|
Name = name;
|
|
|
|
|
Position = position;
|
|
|
|
|
Topic = topic;
|
|
|
|
@ -62,19 +68,19 @@ namespace DiscordChatExporter.Domain.Discord.Models
|
|
|
|
|
|
|
|
|
|
public partial class Channel
|
|
|
|
|
{
|
|
|
|
|
private static ChannelCategory GetDefaultCategory(ChannelType channelType) => new(
|
|
|
|
|
Snowflake.Zero,
|
|
|
|
|
channelType switch
|
|
|
|
|
{
|
|
|
|
|
ChannelType.GuildTextChat => "Text",
|
|
|
|
|
ChannelType.DirectTextChat => "Private",
|
|
|
|
|
ChannelType.DirectGroupTextChat => "Group",
|
|
|
|
|
ChannelType.GuildNews => "News",
|
|
|
|
|
ChannelType.GuildStore => "Store",
|
|
|
|
|
_ => "Default"
|
|
|
|
|
},
|
|
|
|
|
0
|
|
|
|
|
);
|
|
|
|
|
private static ChannelCategory GetFallbackCategory(ChannelType channelType) => new(
|
|
|
|
|
Snowflake.Zero,
|
|
|
|
|
channelType switch
|
|
|
|
|
{
|
|
|
|
|
ChannelType.GuildTextChat => "Text",
|
|
|
|
|
ChannelType.DirectTextChat => "Private",
|
|
|
|
|
ChannelType.DirectGroupTextChat => "Group",
|
|
|
|
|
ChannelType.GuildNews => "News",
|
|
|
|
|
ChannelType.GuildStore => "Store",
|
|
|
|
|
_ => "Default"
|
|
|
|
|
},
|
|
|
|
|
0
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
public static Channel Parse(JsonElement json, ChannelCategory? category = null, int? position = null)
|
|
|
|
|
{
|
|
|
|
@ -82,7 +88,7 @@ namespace DiscordChatExporter.Domain.Discord.Models
|
|
|
|
|
var guildId = json.GetPropertyOrNull("guild_id")?.GetString().Pipe(Snowflake.Parse);
|
|
|
|
|
var topic = json.GetPropertyOrNull("topic")?.GetString();
|
|
|
|
|
|
|
|
|
|
var type = (ChannelType)json.GetProperty("type").GetInt32();
|
|
|
|
|
var type = (ChannelType) json.GetProperty("type").GetInt32();
|
|
|
|
|
|
|
|
|
|
var name =
|
|
|
|
|
json.GetPropertyOrNull("name")?.GetString() ??
|
|
|
|
@ -95,7 +101,7 @@ namespace DiscordChatExporter.Domain.Discord.Models
|
|
|
|
|
id,
|
|
|
|
|
type,
|
|
|
|
|
guildId ?? Guild.DirectMessages.Id,
|
|
|
|
|
category ?? GetDefaultCategory(type),
|
|
|
|
|
category ?? GetFallbackCategory(type),
|
|
|
|
|
name,
|
|
|
|
|
position,
|
|
|
|
|
topic
|