-
-
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.
+3,303
−982
Open
Changes from all 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
116 changes: 116 additions & 0 deletions
116
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,116 @@ | ||
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(this IEmote emote, IEmojiModel model) | ||
{ | ||
if (emote == null) | ||
return null; | ||
|
||
model.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; | ||
} | ||
|
||
public static IEmojiModel ToModel<TModel>(this IEmote emote) where TModel : IEmojiModel, new() | ||
{ | ||
if (emote == null) | ||
return null; | ||
|
||
return emote.ToModel(new TModel()); | ||
} | ||
} | ||
} |
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,20 @@ | ||
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(); | ||
} | ||
|
||
public interface ICached | ||
{ | ||
bool IsFreed { get; } | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/Discord.Net.Core/Cache/Models/Application/IPartialApplicationModel.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,16 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Discord | ||
{ | ||
public interface IPartialApplicationModel : IEntityModel<ulong> | ||
{ | ||
string Name { get; set; } | ||
string Icon { get; set; } | ||
string Description { get; set; } | ||
string CoverImage { 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,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; } | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/Discord.Net.Core/Cache/Models/Message/Components/IMessageComponentModel.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,35 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Discord | ||
{ | ||
public interface IMessageComponentModel | ||
{ | ||
ComponentType Type { get; set; } | ||
string CustomId { get; set; } | ||
bool? Disabled { get; set; } | ||
ButtonStyle? Style { get; set; } | ||
string Label { get; set; } | ||
|
||
// emoji | ||
ulong? EmojiId { get; set; } | ||
string EmojiName { get; set; } | ||
bool? EmojiAnimated { get; set; } | ||
|
||
string Url { get; set; } | ||
|
||
IMessageComponentOptionModel[] Options { get; set; } | ||
|
||
string Placeholder { get; set; } | ||
int? MinValues { get; set; } | ||
int? MaxValues { get; set; } | ||
IMessageComponentModel[] Components { get; set; } | ||
int? MinLength { get; set; } | ||
int? MaxLength { get; set; } | ||
bool? Required { get; set; } | ||
string Value { get; set; } | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/Discord.Net.Core/Cache/Models/Message/Components/IMessageComponentOptionModel.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,22 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Discord | ||
{ | ||
public interface IMessageComponentOptionModel | ||
{ | ||
string Label { get; set; } | ||
string Value { get; set; } | ||
string Description { get; set; } | ||
|
||
// emoji | ||
ulong? EmojiId { get; set; } | ||
string EmojiName { get; set; } | ||
bool? EmojiAnimated { get; set; } | ||
|
||
bool? Default { get; set; } | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/Discord.Net.Core/Cache/Models/Message/IAttachmentModel.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,21 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Discord | ||
{ | ||
public interface IAttachmentModel : IEntityModel<ulong> | ||
{ | ||
string FileName { get; set; } | ||
string Description { get; set; } | ||
string ContentType { get; set; } | ||
int Size { get; set; } | ||
string Url { get; set; } | ||
string ProxyUrl { get; set; } | ||
int? Height { get; set; } | ||
int? Width { get; set; } | ||
bool Ephemeral { 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,44 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Discord | ||
{ | ||
public interface IEmbedModel | ||
{ | ||
string Title { get; set; } | ||
EmbedType Type { get; set; } | ||
string Description { get; set; } | ||
string Url { get; set; } | ||
long? Timestamp { get; set; } | ||
uint? Color { get; set; } | ||
string FooterText { get; set; } | ||
string FooterIconUrl { get; set; } | ||
string FooterProxyUrl { get; set; } | ||
string ProviderName { get; set; } | ||
string ProviderUrl { get; set; } | ||
string AuthorName { get; set; } | ||
string AuthorUrl { get; set; } | ||
string AuthorIconUrl { get; set; } | ||
string AuthorProxyIconUrl { get; set; } | ||
IEmbedMediaModel Image { get; set; } | ||
IEmbedMediaModel Thumbnail { get; set; } | ||
IEmbedMediaModel Video { get; set; } | ||
IEmbedFieldModel[] Fields { get; set; } | ||
} | ||
public interface IEmbedMediaModel | ||
{ | ||
string Url { get; set; } | ||
string ProxyUrl { get; set; } | ||
int? Height { get; set; } | ||
int? Width { get; set; } | ||
} | ||
public interface IEmbedFieldModel | ||
{ | ||
string Name { get; set; } | ||
string Value { get; set; } | ||
bool Inline { get; set; } | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/Discord.Net.Core/Cache/Models/Message/IMessageActivityModel.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,14 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Discord | ||
{ | ||
public interface IMessageActivityModel | ||
{ | ||
MessageActivityType? Type { get; set; } | ||
string PartyId { get; set; } | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
src/Discord.Net.Core/Cache/Models/Message/IMessageModel.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 IMessageModel : IEntityModel<ulong> | ||
{ | ||
MessageType Type { get; set; } | ||
ulong ChannelId { get; set; } | ||
ulong? GuildId { get; set; } | ||
ulong AuthorId { get; set; } | ||
bool IsWebhookMessage { get; set; } | ||
string Content { get; set; } | ||
long Timestamp { get; set; } | ||
long? EditedTimestamp { get; set; } | ||
bool IsTextToSpeech { get; set; } | ||
bool MentionEveryone { get; set; } | ||
ulong[] UserMentionIds { get; set; } | ||
ulong[] RoleMentionIds { get; set; } | ||
|
||
IAttachmentModel[] Attachments { get; set; } | ||
IEmbedModel[] Embeds { get; set; } | ||
IReactionMetadataModel[] Reactions { get; set; } | ||
bool Pinned { get; set; } | ||
IMessageActivityModel Activity { get; set; } | ||
IPartialApplicationModel Application { get; set; } | ||
ulong? ApplicationId { get; set; } | ||
|
||
// message reference | ||
ulong? ReferenceMessageId { get; set; } | ||
ulong? ReferenceMessageChannelId { get; set; } | ||
ulong? ReferenceMessageGuildId { get; set; } | ||
|
||
MessageFlags Flags { get; set; } | ||
|
||
// interaction | ||
ulong? InteractionId { get; set; } | ||
string InteractionName { get; set; } | ||
InteractionType? InteractionType { get; set; } | ||
ulong? InteractionUserId { get; set; } | ||
|
||
IMessageComponentModel[] Components { get; set; } | ||
IStickerItemModel[] Stickers { get; set; } | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/Discord.Net.Core/Cache/Models/Message/IReactionModel.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,14 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Discord | ||
{ | ||
public interface IReactionMetadataModel | ||
{ | ||
IEmojiModel Emoji { get; set; } | ||
ulong[] Users { get; set; } | ||
} | ||
} |
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