-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtypes.ts
More file actions
307 lines (288 loc) · 7.92 KB
/
types.ts
File metadata and controls
307 lines (288 loc) · 7.92 KB
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
/**
* Namespace for API response types and helpers
*/
export namespace API {
/**
* A successful API response
* @template T The type of the data returned
*/
export type SuccessfulAPIResponse<T> = {
/** Whether the response was successful (always true) */
success: true;
/** The data returned by the API */
data: T;
};
/**
* An errored API response
*/
export type ErroredAPIResponse = {
/** Whether the response was successful (always false) */
success: false;
/** Error information */
error: {
/** Error message */
message: string;
/** Error code */
code: string;
};
};
/**
* Either a successful or errored API response
* @template T The type of the data returned if successful
*/
export type EitherAPIResponse<T> = SuccessfulAPIResponse<T> | ErroredAPIResponse;
/**
* Checks if the response was successful
* @param response The response from the fetch request
* @param body The body of the response
* @returns Whether the response was successful
*/
export function isSuccess<T>(
response: Response,
body: EitherAPIResponse<T>
): body is SuccessfulAPIResponse<T> {
return response.ok && body.success;
}
/**
* Checks if the response was an error
* @param response The response from the fetch request
* @param body The body of the response
* @returns Whether the response was an error
*/
export function isErrored<T>(
response: Response,
body: EitherAPIResponse<T>
): body is ErroredAPIResponse {
return !isSuccess(response, body);
}
}
/**
* The routes that Lanyard and this library support
*/
export namespace Routes {
export type GetPresence = API.EitherAPIResponse<Types.Presence>;
}
/**
* The types that the API consumes and returns
*/
export namespace Types {
/**
* A Discord snowflake (unique identifier for Discord entities)
*/
export type Snowflake = `${bigint}`;
/**
* The status of a Discord user
*/
export type DiscordStatus = 'online' | 'idle' | 'dnd' | 'offline';
/**
* The presence of a Discord user
*/
export interface Presence {
/** Spotify activity information, or null if not listening */
spotify: Spotify | null;
/** Custom key-value data set by the user */
kv: Record<string, string>;
/** Whether the user is currently listening to Spotify */
listening_to_spotify: boolean;
/** Discord user information */
discord_user: DiscordUser;
/** The user's Discord status */
discord_status: DiscordStatus;
/** Array of Discord activities */
activities: Activity[];
/** Whether the user is active on Discord web */
active_on_discord_web: boolean;
/** Whether the user is active on Discord mobile */
active_on_discord_mobile: boolean;
/** Whether the user is active on Discord desktop */
active_on_discord_desktop: boolean;
/** Whether the user is active on Discord embedded */
active_on_discord_embedded: boolean;
}
/**
* Information about a user listening to Spotify
*/
export interface Spotify {
/** The Spotify track ID, or null if not available */
track_id: string | null;
/** Timestamps for the Spotify song */
timestamps: Timestamps;
/** The song title */
song: string;
/** The artist name, or null if not available */
artist: string | null;
/** The album art URL, or null if not available */
album_art_url: string | null;
/** The album name, or null if not available */
album: string | null;
}
/**
* Timestamps for a Spotify song
*/
export interface Timestamps {
/** Start time in milliseconds since epoch */
start: number;
/** End time in milliseconds since epoch */
end: number;
}
/**
* Information about a Discord user, which is explicitly different to presence
*/
export interface DiscordUser {
/** The user's Discord username */
username: string;
/** Public flags on the user's account */
public_flags: number;
/** The user's unique Discord ID */
id: Snowflake;
/**
* @deprecated Use {@link global_name user.global_name} instead.
* The user's display name (deprecated)
*/
display_name: string | null;
/** The user's global display name */
global_name: string | null;
/** The user's Discord discriminator (legacy, usually '0') */
discriminator: string;
/** Whether the user is a bot */
bot: boolean;
/** Avatar decoration data for the user, if any */
avatar_decoration_data: {
/** The asset string for the avatar decoration */
asset: string;
/** The SKU ID for the avatar decoration */
sku_id: bigint;
} | null;
/** The user's avatar hash, or null if none */
avatar: string | null;
/**
* @deprecated Use {@link primary_guild user.primary_guild} instead.
* The user's clan information (deprecated)
*/
clan?: Clan;
/** The user's primary guild information */
primary_guild?: Clan;
/** The user's collectibles, such as nameplates */
collectibles?: Collectibles | null;
}
/**
* Information about a Discord clan
*/
export interface Clan {
/** The clan's tag */
tag: string;
/** The guild ID associated with the clan */
identity_guild_id: string;
/** The badge hash for the clan */
badge: string;
/** Whether identity is enabled for the clan */
identity_enabled: boolean;
}
/**
* Information about a Discord activity
*/
export interface Activity {
/** The activity type (numeric Discord constant) */
type: number;
/** The activity state (e.g., what the user is doing) */
state: string;
/** The activity name */
name: string;
/** The activity ID */
id: string;
/** The emoji associated with the activity, if any */
emoji?: Emoji;
/** When the activity was created (ms since epoch) */
created_at: number;
/** Timestamps for the activity, if any */
timestamps?: Timestamps;
/** The sync ID for the activity, if any */
sync_id?: string;
/** The session ID for the activity, if any */
session_id?: string;
/** The party information for the activity, if any */
party?: Party;
/** Activity flags, if any */
flags?: number;
/** Details about the activity, if any */
details?: string;
/** Assets associated with the activity, if any */
assets?: Assets;
/** The application ID for the activity, if any */
application_id?: Snowflake;
}
/**
* Information about a Discord emoji
*/
export interface Emoji {
/** The emoji name */
name: string;
/** The emoji ID */
id: Snowflake;
/** Whether the emoji is animated */
animated: boolean;
}
/**
* Information about a Discord party
*/
export interface Party {
/** The party size as [min, max], if available */
size?: [min: number, max: number];
/** The party ID */
id: string;
}
/**
* Information about a Discord activity's assets
*/
export interface Assets {
/** Small text for the asset, if any */
small_text?: string;
/** Small image for the asset, if any */
small_image?: string;
/** Large text for the asset, if any */
large_text?: string;
/** Large image for the asset, if any */
large_image?: string;
}
/**
* Information about Discord collectibles, such as nameplates.
*/
export interface Collectibles {
/**
* The user's nameplate collectible, which gives a background to the username in the member list.
*/
nameplate?: NameplateCollectible;
}
/**
* The well-known nameplate palettes
*
* These were sourced from the Discord Webpack bundle.
*/
export enum WellKnownNameplatePalettes {
NONE = 'none',
CRIMSON = 'crimson',
BERRY = 'berry',
SKY = 'sky',
TEAL = 'teal',
FOREST = 'forest',
BUBBLE_GUM = 'bubble_gum',
VIOLET = 'violet',
COBALT = 'cobalt',
CLOVER = 'clover',
}
/**
* Information about a nameplate collectible.
*/
export interface NameplateCollectible {
/** The i18n label for the nameplate */
label: string;
/** The SKU ID for the nameplate */
sku_id: string;
/** The asset path for the nameplate */
asset: string;
/** The expiration date for the nameplate, or null if it does not expire */
expires_at: string | null;
/** The palette name for the nameplate */
palette: WellKnownNameplatePalettes | (string & {});
}
}