-
-
Notifications
You must be signed in to change notification settings - Fork 736
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
V4: State and Cache providers #2251
Open
quinchs
wants to merge
12
commits into
4.0
Choose a base branch
from
v4/state-cache-providers
base: 4.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
3e36fbb
initial implementation
quinchs 627f887
Change up model flows
quinchs adcb58e
refactor default state provider
quinchs 17306d5
updates
quinchs d89d13d
Final POC for users
quinchs a4e1f54
Update src/Discord.Net.WebSocket/DiscordSocketConfig.cs
quinchs 9826cf6
Update src/Discord.Net.WebSocket/Entities/Users/SocketGuildUser.cs
quinchs 59c334a
refactor models and remove cache run mode
quinchs 157063c
default model maps
quinchs dc2dafa
custom model factory
quinchs e14e540
Merge branch 'dev' into v4/state-cache-providers
quinchs 67c5094
more work on cache provider
quinchs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
111 changes: 111 additions & 0 deletions
111
src/Discord.Net.Core/Cache/CacheableEntityExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Discord | ||
{ | ||
internal static class CacheableEntityExtensions | ||
{ | ||
public static IActivityModel ToModel<TModel>(this RichGame richGame) where TModel : IActivityModel, new() | ||
{ | ||
return new TModel() | ||
{ | ||
ApplicationId = richGame.ApplicationId, | ||
SmallImage = richGame.SmallAsset?.ImageId, | ||
SmallText = richGame.SmallAsset?.Text, | ||
LargeImage = richGame.LargeAsset?.ImageId, | ||
LargeText = richGame.LargeAsset?.Text, | ||
Details = richGame.Details, | ||
Flags = richGame.Flags, | ||
Name = richGame.Name, | ||
Type = richGame.Type, | ||
JoinSecret = richGame.Secrets?.Join, | ||
SpectateSecret = richGame.Secrets?.Spectate, | ||
MatchSecret = richGame.Secrets?.Match, | ||
State = richGame.State, | ||
PartyId = richGame.Party?.Id, | ||
PartySize = richGame.Party?.Members != null && richGame.Party?.Capacity != null | ||
? new long[] { richGame.Party.Members, richGame.Party.Capacity } | ||
: null, | ||
TimestampEnd = richGame.Timestamps?.End, | ||
TimestampStart = richGame.Timestamps?.Start | ||
}; | ||
} | ||
|
||
public static IActivityModel ToModel<TModel>(this SpotifyGame spotify) where TModel : IActivityModel, new() | ||
{ | ||
return new TModel() | ||
{ | ||
Name = spotify.Name, | ||
SessionId = spotify.SessionId, | ||
SyncId = spotify.TrackId, | ||
LargeText = spotify.AlbumTitle, | ||
Details = spotify.TrackTitle, | ||
State = string.Join(";", spotify.Artists), | ||
TimestampEnd = spotify.EndsAt, | ||
TimestampStart = spotify.StartedAt, | ||
LargeImage = spotify.AlbumArt, | ||
Type = ActivityType.Listening, | ||
Flags = spotify.Flags, | ||
}; | ||
} | ||
|
||
public static IActivityModel ToModel<TModel, TEmoteModel>(this CustomStatusGame custom) | ||
where TModel : IActivityModel, new() | ||
where TEmoteModel : IEmojiModel, new() | ||
{ | ||
return new TModel | ||
{ | ||
Id = "custom", | ||
Type = ActivityType.CustomStatus, | ||
Name = custom.Name, | ||
State = custom.State, | ||
Emoji = custom.Emote.ToModel<TEmoteModel>(), | ||
CreatedAt = custom.CreatedAt | ||
}; | ||
} | ||
|
||
public static IActivityModel ToModel<TModel>(this StreamingGame stream) where TModel : IActivityModel, new() | ||
{ | ||
return new TModel | ||
{ | ||
Name = stream.Name, | ||
Url = stream.Url, | ||
Flags = stream.Flags, | ||
Details = stream.Details | ||
}; | ||
} | ||
|
||
public static IEmojiModel ToModel<TModel>(this IEmote emote) where TModel : IEmojiModel, new() | ||
{ | ||
if (emote == null) | ||
return null; | ||
|
||
var model = new TModel() | ||
{ | ||
Name = emote.Name | ||
}; | ||
|
||
if(emote is GuildEmote guildEmote) | ||
{ | ||
model.Id = guildEmote.Id; | ||
model.IsAnimated = guildEmote.Animated; | ||
model.IsAvailable = guildEmote.IsAvailable; | ||
model.IsManaged = guildEmote.IsManaged; | ||
model.CreatorId = guildEmote.CreatorId; | ||
model.RequireColons = guildEmote.RequireColons; | ||
model.Roles = guildEmote.RoleIds.ToArray(); | ||
} | ||
|
||
if(emote is Emote e) | ||
{ | ||
model.IsAnimated = e.Animated; | ||
model.Id = e.Id; | ||
} | ||
|
||
return model; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Discord | ||
{ | ||
internal interface ICached<TType> : ICached, IDisposable | ||
{ | ||
void Update(TType model); | ||
|
||
TType ToModel(); | ||
|
||
TResult ToModel<TResult>() where TResult : TType, new(); | ||
} | ||
|
||
public interface ICached | ||
{ | ||
bool IsFreed { get; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Discord | ||
{ | ||
public interface IEmojiModel | ||
{ | ||
ulong? Id { get; set; } | ||
string Name { get; set; } | ||
ulong[] Roles { get; set; } | ||
bool RequireColons { get; set; } | ||
bool IsManaged { get; set; } | ||
bool IsAnimated { get; set; } | ||
bool IsAvailable { get; set; } | ||
|
||
ulong? CreatorId { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Discord | ||
{ | ||
public interface IEntityModel<TId> where TId : IEquatable<TId> | ||
{ | ||
TId Id { get; set; } | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
src/Discord.Net.Core/Cache/Models/Presense/IActivityModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Discord | ||
{ | ||
public interface IActivityModel | ||
{ | ||
string Id { get; set; } | ||
string Url { get; set; } | ||
string Name { get; set; } | ||
ActivityType Type { get; set; } | ||
string Details { get; set; } | ||
string State { get; set; } | ||
ActivityProperties Flags { get; set; } | ||
DateTimeOffset CreatedAt { get; set; } | ||
IEmojiModel Emoji { get; set; } | ||
ulong? ApplicationId { get; set; } | ||
string SyncId { get; set; } | ||
string SessionId { get; set; } | ||
|
||
|
||
#region Assets | ||
string LargeImage { get; set; } | ||
string LargeText { get; set; } | ||
string SmallImage { get; set; } | ||
string SmallText { get; set; } | ||
#endregion | ||
|
||
#region Party | ||
string PartyId { get; set; } | ||
long[] PartySize { get; set; } | ||
#endregion | ||
|
||
#region Secrets | ||
string JoinSecret { get; set; } | ||
string SpectateSecret { get; set; } | ||
string MatchSecret { get; set; } | ||
#endregion | ||
|
||
#region Timestamps | ||
DateTimeOffset? TimestampStart { get; set; } | ||
DateTimeOffset? TimestampEnd { get; set; } | ||
#endregion | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/Discord.Net.Core/Cache/Models/Presense/IPresenceModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Discord | ||
{ | ||
public interface IPresenceModel : IEntityModel<ulong> | ||
{ | ||
ulong UserId { get; set; } | ||
ulong? GuildId { get; set; } | ||
UserStatus Status { get; set; } | ||
ClientType[] ActiveClients { get; set; } | ||
IActivityModel[] Activities { get; set; } | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/Discord.Net.Core/Cache/Models/Users/ICurrentUserModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Discord | ||
{ | ||
public interface ICurrentUserModel : IUserModel | ||
{ | ||
bool? IsVerified { get; set; } | ||
string Email { get; set; } | ||
bool? IsMfaEnabled { get; set; } | ||
UserProperties Flags { get; set; } | ||
PremiumType PremiumType { get; set; } | ||
string Locale { get; set; } | ||
UserProperties PublicFlags { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Discord | ||
{ | ||
public interface IMemberModel : IEntityModel<ulong> | ||
{ | ||
//IUserModel User { get; set; } | ||
string Nickname { get; set; } | ||
string GuildAvatar { get; set; } | ||
ulong[] Roles { get; set; } | ||
DateTimeOffset JoinedAt { get; set; } | ||
DateTimeOffset? PremiumSince { get; set; } | ||
bool IsDeaf { get; set; } | ||
bool IsMute { get; set; } | ||
bool? IsPending { get; set; } | ||
DateTimeOffset? CommunicationsDisabledUntil { get; set; } | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/Discord.Net.Core/Cache/Models/Users/IThreadMemberModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Discord | ||
{ | ||
public interface IThreadMemberModel : IEntityModel<ulong> | ||
{ | ||
ulong? ThreadId { get; set; } | ||
ulong? UserId { get; set; } | ||
DateTimeOffset JoinedAt { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Discord | ||
{ | ||
public interface IUserModel : IEntityModel<ulong> | ||
{ | ||
string Username { get; set; } | ||
string Discriminator { get; set; } | ||
bool? IsBot { get; set; } | ||
string Avatar { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any reason why these methods arent returning the generic type parameters? We could downcast it later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really, its just whats there atm. it could change once I implement the rest of the entities