mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2025-05-31 14:58:22 -04:00
Refactor models and add IHasId/IdBasedEqualityComparer
This commit is contained in:
parent
23512dae64
commit
fc38afe6a0
10 changed files with 34 additions and 12 deletions
|
@ -6,7 +6,7 @@ namespace DiscordChatExporter.Core.Models
|
|||
{
|
||||
// https://discordapp.com/developers/docs/resources/channel#attachment-object
|
||||
|
||||
public partial class Attachment
|
||||
public partial class Attachment : IHasId
|
||||
{
|
||||
public string Id { get; }
|
||||
|
||||
|
|
|
@ -2,13 +2,13 @@
|
|||
{
|
||||
// https://discordapp.com/developers/docs/resources/channel#channel-object
|
||||
|
||||
public partial class Channel
|
||||
public partial class Channel : IHasId
|
||||
{
|
||||
public string Id { get; }
|
||||
|
||||
public string? ParentId { get; }
|
||||
|
||||
public string? GuildId { get; }
|
||||
public string GuildId { get; }
|
||||
|
||||
public string Name { get; }
|
||||
|
||||
|
@ -16,7 +16,7 @@
|
|||
|
||||
public ChannelType Type { get; }
|
||||
|
||||
public Channel(string id, string? parentId, string? guildId, string name, string? topic, ChannelType type)
|
||||
public Channel(string id, string? parentId, string guildId, string name, string? topic, ChannelType type)
|
||||
{
|
||||
Id = id;
|
||||
ParentId = parentId;
|
||||
|
@ -32,6 +32,6 @@
|
|||
public partial class Channel
|
||||
{
|
||||
public static Channel CreateDeletedChannel(string id) =>
|
||||
new Channel(id, null, null, "deleted-channel", null, ChannelType.GuildTextChat);
|
||||
new Channel(id, null, "unknown-guild", "deleted-channel", null, ChannelType.GuildTextChat);
|
||||
}
|
||||
}
|
|
@ -6,7 +6,7 @@ namespace DiscordChatExporter.Core.Models
|
|||
{
|
||||
// https://discordapp.com/developers/docs/resources/emoji#emoji-object
|
||||
|
||||
public partial class Emoji
|
||||
public partial class Emoji : IHasId
|
||||
{
|
||||
public string? Id { get; }
|
||||
|
||||
|
|
|
@ -30,7 +30,6 @@ namespace DiscordChatExporter.Core.Models
|
|||
{
|
||||
get
|
||||
{
|
||||
// Absolute value is used to deal with negative values
|
||||
if (Math.Abs(PetaBytes) >= 1)
|
||||
return PetaByteSymbol;
|
||||
|
||||
|
@ -54,7 +53,6 @@ namespace DiscordChatExporter.Core.Models
|
|||
{
|
||||
get
|
||||
{
|
||||
// Absolute value is used to deal with negative values
|
||||
if (Math.Abs(PetaBytes) >= 1)
|
||||
return PetaBytes;
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
{
|
||||
// https://discordapp.string.IsNullOrWhiteSpace(com/developers/docs/resources/guild#guild-object
|
||||
|
||||
public partial class Guild
|
||||
public partial class Guild : IHasId
|
||||
{
|
||||
public string Id { get; }
|
||||
|
||||
|
|
7
DiscordChatExporter.Core.Models/IHasId.cs
Normal file
7
DiscordChatExporter.Core.Models/IHasId.cs
Normal file
|
@ -0,0 +1,7 @@
|
|||
namespace DiscordChatExporter.Core.Models
|
||||
{
|
||||
public interface IHasId
|
||||
{
|
||||
string Id { get; }
|
||||
}
|
||||
}
|
17
DiscordChatExporter.Core.Models/IdBasedEqualityComparer.cs
Normal file
17
DiscordChatExporter.Core.Models/IdBasedEqualityComparer.cs
Normal file
|
@ -0,0 +1,17 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace DiscordChatExporter.Core.Models
|
||||
{
|
||||
public partial class IdBasedEqualityComparer : IEqualityComparer<IHasId>
|
||||
{
|
||||
public bool Equals(IHasId? x, IHasId? y) => StringComparer.Ordinal.Equals(x?.Id, y?.Id);
|
||||
|
||||
public int GetHashCode(IHasId obj) => StringComparer.Ordinal.GetHashCode(obj.Id);
|
||||
}
|
||||
|
||||
public partial class IdBasedEqualityComparer
|
||||
{
|
||||
public static IdBasedEqualityComparer Instance { get; } = new IdBasedEqualityComparer();
|
||||
}
|
||||
}
|
|
@ -5,7 +5,7 @@ namespace DiscordChatExporter.Core.Models
|
|||
{
|
||||
// https://discordapp.com/developers/docs/resources/channel#message-object
|
||||
|
||||
public class Message
|
||||
public class Message : IHasId
|
||||
{
|
||||
public string Id { get; }
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
{
|
||||
// https://discordapp.com/developers/docs/topics/permissions#role-object
|
||||
|
||||
public partial class Role
|
||||
public partial class Role : IHasId
|
||||
{
|
||||
public string Id { get; }
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ namespace DiscordChatExporter.Core.Models
|
|||
{
|
||||
// https://discordapp.com/developers/docs/topics/permissions#role-object
|
||||
|
||||
public partial class User
|
||||
public partial class User : IHasId
|
||||
{
|
||||
public string Id { get; }
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue