-
-
Notifications
You must be signed in to change notification settings - Fork 739
/
Copy pathCacheableEntityExtensions.cs
116 lines (105 loc) · 4.05 KB
/
CacheableEntityExtensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
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());
}
}
}