Skip to content

Commit 9aa310f

Browse files
authored
feat: add new GetUser command (#308)
1 parent 5d54cde commit 9aa310f

File tree

7 files changed

+77
-1
lines changed

7 files changed

+77
-1
lines changed

src/commands/getUser.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import {schemaCommandFactory} from '../utils/commandFactory';
2+
import {Command} from '../generated/schemas';
3+
4+
export const getUser = schemaCommandFactory(Command.GET_USER);

src/commands/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {getChannel} from './getChannel';
2323
import {getInstanceConnectedParticipants} from './getInstanceConnectedParticipants';
2424
import {getRelationships} from './getRelationships';
2525
import {inviteUserEmbedded} from './inviteUserEmbedded';
26+
import {getUser} from './getUser';
2627

2728
export {Commands, SetActivity};
2829

@@ -50,6 +51,7 @@ function commands(sendCommand: TSendCommand) {
5051
getInstanceConnectedParticipants: getInstanceConnectedParticipants(sendCommand),
5152
getRelationships: getRelationships(sendCommand),
5253
inviteUserEmbedded: inviteUserEmbedded(sendCommand),
54+
getUser: getUser(sendCommand),
5355
};
5456
}
5557

src/generated/schema.json

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@
8888
"gateway.connect",
8989
"account.global_name.update",
9090
"payment_sources.country_code",
91-
"sdk.social_layer"
91+
"sdk.social_layer",
92+
"lobbies.write"
9293
]
9394
}
9495
},
@@ -355,5 +356,36 @@
355356
"additionalProperties": false
356357
},
357358
"response": null
359+
},
360+
"GET_USER": {
361+
"request": {
362+
"type": "object",
363+
"properties": {"id": {"type": "string", "maxLength": 64}},
364+
"required": ["id"],
365+
"additionalProperties": false
366+
},
367+
"response": {
368+
"type": ["object", "null"],
369+
"description": "Discord User",
370+
"properties": {
371+
"id": {"type": "string", "description": "User ID"},
372+
"username": {"type": "string"},
373+
"global_name": {"type": ["string", "null"], "description": "Global Discord name. Not unique."},
374+
"discriminator": {"type": "string", "description": "Global name discriminator. Will be 0 if a unique username"},
375+
"avatar": {"type": ["string", "null"], "description": "User Avatar ID"},
376+
"flags": {"type": "number", "description": "Public user flags"},
377+
"bot": {"type": "boolean", "description": "If a bot user."},
378+
"avatar_decoration_data": {
379+
"type": ["object", "null"],
380+
"description": "Details about avatar decoration",
381+
"properties": {"asset": {"type": "string"}, "skuId": {"type": "string"}, "expiresAt": {"type": "number"}},
382+
"required": ["asset"],
383+
"additionalProperties": false
384+
},
385+
"premium_type": {"type": ["number", "null"], "description": "Nitro premium type"}
386+
},
387+
"required": ["id", "username", "discriminator", "flags", "bot"],
388+
"additionalProperties": false
389+
}
358390
}
359391
}

src/generated/schemas.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,27 @@ export const InviteUserEmbeddedRequestSchema = z.object({
249249
});
250250
export type InviteUserEmbeddedRequest = zInfer<typeof InviteUserEmbeddedRequestSchema>;
251251

252+
// GET_USER
253+
export const GetUserRequestSchema = z.object({id: z.string().max(64)});
254+
export type GetUserRequest = zInfer<typeof GetUserRequestSchema>;
255+
export const GetUserResponseSchema = z.union([
256+
z.object({
257+
id: z.string(),
258+
username: z.string(),
259+
global_name: z.union([z.string(), z.null()]).optional(),
260+
discriminator: z.string(),
261+
avatar: z.union([z.string(), z.null()]).optional(),
262+
flags: z.number(),
263+
bot: z.boolean(),
264+
avatar_decoration_data: z
265+
.union([z.object({asset: z.string(), skuId: z.string().optional(), expiresAt: z.number().optional()}), z.null()])
266+
.optional(),
267+
premium_type: z.union([z.number(), z.null()]).optional(),
268+
}),
269+
z.null(),
270+
]);
271+
export type GetUserResponse = zInfer<typeof GetUserResponseSchema>;
272+
252273
/**
253274
* RPC Commands which support schemas.
254275
*/
@@ -261,6 +282,7 @@ export enum Command {
261282
SHARE_LINK = 'SHARE_LINK',
262283
GET_RELATIONSHIPS = 'GET_RELATIONSHIPS',
263284
INVITE_USER_EMBEDDED = 'INVITE_USER_EMBEDDED',
285+
GET_USER = 'GET_USER',
264286
}
265287

266288
const emptyResponseSchema = z.object({}).optional().nullable();
@@ -302,4 +324,8 @@ export const Schemas = {
302324
request: InviteUserEmbeddedRequestSchema,
303325
response: emptyResponseSchema,
304326
},
327+
[Command.GET_USER]: {
328+
request: GetUserRequestSchema,
329+
response: GetUserResponseSchema,
330+
},
305331
} as const;

src/mock.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,4 +182,14 @@ export const commandsMockDefault: IDiscordSDK['commands'] = {
182182
],
183183
}),
184184
inviteUserEmbedded: () => Promise.resolve(null),
185+
getUser: () => {
186+
return Promise.resolve({
187+
username: 'mock_friend_username',
188+
flags: 0,
189+
bot: false,
190+
discriminator: 'mock_friend_discriminator',
191+
id: 'mock_friend_id_1',
192+
avatar: null,
193+
});
194+
},
185195
};

src/schema/common.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export enum Commands {
3939
SHARE_LINK = 'SHARE_LINK',
4040
GET_RELATIONSHIPS = 'GET_RELATIONSHIPS',
4141
INVITE_USER_EMBEDDED = 'INVITE_USER_EMBEDDED',
42+
GET_USER = 'GET_USER',
4243
}
4344

4445
export const ReceiveFramePayload = zod

src/schema/responses.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ function parseResponseData({cmd, data}: zod.infer<typeof ResponseFrame>) {
185185
case Commands.SHARE_LINK:
186186
case Commands.GET_RELATIONSHIPS:
187187
case Commands.INVITE_USER_EMBEDDED:
188+
case Commands.GET_USER:
188189
const {response} = Schemas[cmd];
189190
return response.parse(data);
190191
default:

0 commit comments

Comments
 (0)