Refactor and rename project to yawaflua.Discord.Net; add core entities and interfaces for Discord OAuth2 integration

This commit is contained in:
Dmitri Shimanski
2025-08-22 06:48:43 +03:00
parent 423bc8def0
commit e0d2b65fff
37 changed files with 867 additions and 382 deletions

9
Interfaces/IDiscord.cs Normal file
View File

@@ -0,0 +1,9 @@
using yawaflua.Discord.Net.Interfaces.Models;
namespace yawaflua.Discord.Net.Interfaces;
public interface IDiscord
{
Task<IToken?> GetTokenAsync(string code);
ISession? CreateSession();
}

View File

@@ -0,0 +1,7 @@
namespace yawaflua.Discord.Net.Interfaces.Models;
public interface IAvatarDecoration
{
public string AssetHash { get; set; }
public ulong AssetArticular { get; set; }
}

View File

@@ -0,0 +1,17 @@
using yawaflua.Discord.Net.Entities.Enums;
namespace yawaflua.Discord.Net.Interfaces.Models;
public interface IConnection
{
public string Id { get; set; }
public string Name { get; set; }
public ConnectionType Type { get; set; }
public bool? Revoked { get; set; }
public object[] Integrations { get; set; }
public bool? Verified { get; set; }
public bool? FriendSync { get; set; }
public bool? ShowActivity { get; set; }
public bool? TwoWayLink { get; set; }
public ConnectionVisibility? Visibility { get; set; }
}

View File

@@ -0,0 +1,19 @@
using yawaflua.Discord.Net.Entities.Enums;
namespace yawaflua.Discord.Net.Interfaces.Models;
public interface IGuild
{
public ulong Id { get; set; }
public string Name { get; set; }
public string? IconHash { get; set; }
public string? BannerHash { get; set; }
public bool IsOwner { get; set; }
public string Permissions { get; set; }
public IEnumerable<GuildFeature> Features { get; set; }
public int ApproximateMemberCount { get; set; }
public int ApproximatePresenceCount { get; set; }
public string GetIconUrl(int size = 128);
public string GetBannerUrl(int size = 128);
}

View File

@@ -0,0 +1,18 @@
namespace yawaflua.Discord.Net.Interfaces.Models;
public interface IGuildMember
{
public IUser User { get; set; }
public string? Nick { get; set; }
public string? AvatarHash { get; set; }
public string? BannerHash { get; set; }
public List<IRole> Roles { get; set; }
public DateTime JoinedAt { get; set; }
public DateTime? PremiumSince { get; set; }
public bool IsDeaf { get; set; }
public bool IsMute { get; set; }
public int Flags { get; set; }
public bool IsPending { get; set; }
public DateTime? CommunicationDisabledUntil { get; set; }
public IAvatarDecoration? AvatarDecoration { get; set; }
}

View File

@@ -0,0 +1,25 @@
using yawaflua.Discord.Net.Entities.Enums;
namespace yawaflua.Discord.Net.Interfaces.Models;
public interface IRole
{
public ulong Id { get; set; }
public string Name { get; set; }
[Obsolete("Deprecated integer representation of hexadecimal color code")]
public int Color { get; set; }
public IRoleColor Colors { get; set; }
public bool IsHoisted { get; set; }
public bool IsManaged { get; set; }
public bool IsMentionable { get; set; }
public int Position { get; set; }
public ulong? Permissions { get; set; }
public string? IconHash { get; set; }
public string? UnicodeEmoji { get; set; }
public Dictionary<RoleTags, ulong?>? Tags { get; set; }
}

View File

@@ -0,0 +1,8 @@
namespace yawaflua.Discord.Net.Interfaces.Models;
public interface IRoleColor
{
public int Primary { get; set; }
public int? Secondary { get; set; }
public int? Tertiary { get; set; }
}

View File

@@ -0,0 +1,16 @@
namespace yawaflua.Discord.Net.Interfaces.Models;
public interface ISession
{
Task<IList<IGuild>?> GetGuildsAsync(CancellationToken cancellationToken = default);
Task<IGuildMember?> GetGuildMemberAsync(ulong guildId, CancellationToken cancellationToken = default);
Task<IGuildMember?> AddMemberToGuildAsync(ulong guildId, ulong userId, CancellationToken cancellationToken = default);
Task<IUser?> GetCurrentUserAsync(CancellationToken cancellationToken = default);
Task<IConnection?> GetConnectionAsync(CancellationToken cancellationToken = default);
string GetAuthorizationUrl(string state);
IToken GetToken(CancellationToken cancellationToken = default);
}

View File

@@ -0,0 +1,14 @@
namespace yawaflua.Discord.Net.Interfaces.Models;
public interface IToken
{
public string? AccessToken { get; set; }
public int ExpiresIn { get; set; }
public string? RefreshToken { get; set; }
public string? Scope { get; set; }
public string? TokenType { get; set; }
Task RevokeAsync(CancellationToken cancellationToken = default);
Task RefreshAsync(CancellationToken cancellationToken = default);
}

115
Interfaces/Models/IUser.cs Normal file
View File

@@ -0,0 +1,115 @@
using yawaflua.Discord.Net.Entities.Enums;
namespace yawaflua.Discord.Net.Interfaces.Models;
public interface IUser
{
/// <summary>
/// the user's id
/// </summary>
/// <seealso href="https://discord.com/developers/docs/resources/user#user-object">User-object</seealso>
public ulong Id { get; set; }
/// <summary>
/// the user's username, not unique across the platform
/// </summary>
/// <seealso href="https://discord.com/developers/docs/resources/user#user-object">User-object</seealso>
public string Username { get; set; }
/// <summary>
/// the user's display name, if it is set. For bots, this is the application name
/// </summary>
public string GlobalName { get; set; }
/// <summary>
/// the user's Discord-tag (Obsolete)
/// </summary>
/// <seealso href="https://discord.com/developers/docs/resources/user#user-object">User-object</seealso>
public string Discriminator { get; set; }
/// <summary>
/// the user's avatar hash
/// </summary>
/// <seealso href="https://discord.com/developers/docs/reference#image-formatting">Image formatting</seealso>
/// <seealso href="https://discord.com/developers/docs/resources/user#user-object">User-object</seealso>
public string? AvatarHash { get; set; }
/// <summary>
/// the user's banner hash
/// </summary>
/// <seealso href="https://discord.com/developers/docs/reference#image-formatting">Image formatting</seealso>
/// <seealso href="https://discord.com/developers/docs/resources/user#user-object">User-object</seealso>
/// <remarks>Available in the User object only if the user has a banner set.</remarks>
/// <example>https://cdn.discordapp.com/banners/{user.id}/{banner}.png?size=512</example>
public string? Banner { get; set; }
/// <summary>
/// whether the user belongs to an OAuth2 application
/// </summary>
/// <seealso href="https://discord.com/developers/docs/resources/user#user-object">User-object</seealso>
public bool? Bot { get; set; }
/// <summary>
/// whether the user is an Official Discord System user (part of the urgent message system)
/// </summary>
/// <seealso href="https://discord.com/developers/docs/resources/user#user-object">User-object</seealso>
public bool? System { get; set; }
/// <summary>
/// whether the user has two factor enabled on their account
/// </summary>
/// <seealso href="https://discord.com/developers/docs/resources/user#user-object">User-object</seealso>
public bool? MfaEnabled { get; set; }
/// <summary>
/// the user's banner color encoded as an integer representation of hexadecimal color code
/// </summary>
/// <seealso href="https://discord.com/developers/docs/resources/user#user-object">User-object</seealso>
public int? AccentColor { get; set; }
/// <summary>
/// the user's chosen language option
/// </summary>
/// <seealso href="https://discord.com/developers/docs/resources/user#user-object">User-object</seealso>
public string? Locale { get; set; }
/// <summary>
/// whether the email on this account has been verified
/// </summary>
/// <seealso href="https://discord.com/developers/docs/resources/user#user-object">User-object</seealso>
public bool? Verified { get; set; }
/// <summary>
/// the user's email
/// </summary>
/// <seealso href="https://discord.com/developers/docs/resources/user#user-object">User-object</seealso>
public string? Email { get; set; }
/// <summary>
/// the flags on a user's account
/// </summary>
/// <seealso href="https://discord.com/developers/docs/resources/user#user-object">User-object</seealso>
/// <seealso href="https://discord.com/developers/docs/resources/user#user-object-user-flags">User flags</seealso>
public UserFlag? Flags { get; set; }
/// <summary>
/// the type of Nitro subscription on a user's account
/// </summary>
/// <seealso href="https://discord.com/developers/docs/resources/user#user-object">User-object</seealso>
public PremiumType? PremiumType { get; set; }
/// <summary>
/// the public flags on a user's account
/// </summary>
/// <seealso href="https://discord.com/developers/docs/resources/user#user-object">User-object</seealso>
public UserFlag? PublicFlags { get; set; }
/// <summary>
/// data for the user's avatar decoration
/// </summary>
/// <seealso href="https://discord.com/developers/docs/resources/user#user-object">User-object</seealso>
public IAvatarDecoration? AvatarDecoration { get; set; }
public string GetAvatarUrl(int size = 128);
public string GetBannerUrl(int size = 128);
}