Skip to content

Commit 5d54cde

Browse files
authored
feat: add activity invite command (#305)
* feat: add activity invite command * fix: remove unused args * fix: update invite command to the new command name * fix: include schema changes for GET_RELATIONSHIPS * fix: remove unused scope
1 parent 7d3b134 commit 5d54cde

File tree

7 files changed

+49
-23
lines changed

7 files changed

+49
-23
lines changed

src/commands/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {initiateImageUpload} from './initiateImageUpload';
2222
import {getChannel} from './getChannel';
2323
import {getInstanceConnectedParticipants} from './getInstanceConnectedParticipants';
2424
import {getRelationships} from './getRelationships';
25+
import {inviteUserEmbedded} from './inviteUserEmbedded';
2526

2627
export {Commands, SetActivity};
2728

@@ -48,6 +49,7 @@ function commands(sendCommand: TSendCommand) {
4849
initiateImageUpload: initiateImageUpload(sendCommand),
4950
getInstanceConnectedParticipants: getInstanceConnectedParticipants(sendCommand),
5051
getRelationships: getRelationships(sendCommand),
52+
inviteUserEmbedded: inviteUserEmbedded(sendCommand),
5153
};
5254
}
5355

src/commands/inviteUserEmbedded.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 inviteUserEmbedded = schemaCommandFactory(Command.INVITE_USER_EMBEDDED);

src/generated/schema.json

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@
238238
"properties": {
239239
"type": {"type": "number"},
240240
"user": {
241-
"type": ["object", "null"],
241+
"type": "object",
242242
"description": "Discord User",
243243
"properties": {
244244
"id": {"type": "string", "description": "User ID"},
@@ -338,13 +338,22 @@
338338
"additionalProperties": false
339339
}
340340
},
341-
"required": ["type"],
341+
"required": ["type", "user"],
342342
"additionalProperties": false
343343
}
344344
}
345345
},
346346
"required": ["relationships"],
347347
"additionalProperties": false
348348
}
349+
},
350+
"INVITE_USER_EMBEDDED": {
351+
"request": {
352+
"type": "object",
353+
"properties": {"user_id": {"type": "string"}, "content": {"type": "string", "minLength": 0, "maxLength": 1024}},
354+
"required": ["user_id"],
355+
"additionalProperties": false
356+
},
357+
"response": null
349358
}
350359
}

src/generated/schemas.ts

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ export const AuthenticateResponseSchema = z.object({
7575
'account.global_name.update',
7676
'payment_sources.country_code',
7777
'sdk.social_layer',
78+
'lobbies.write',
7879
])
7980
.or(z.literal(-1))
8081
.default(-1),
@@ -165,27 +166,22 @@ export const GetRelationshipsResponseSchema = z.object({
165166
relationships: z.array(
166167
z.object({
167168
type: z.number(),
168-
user: z
169-
.union([
170-
z.object({
171-
id: z.string(),
172-
username: z.string(),
173-
global_name: z.union([z.string(), z.null()]).optional(),
174-
discriminator: z.string(),
175-
avatar: z.union([z.string(), z.null()]).optional(),
176-
flags: z.number(),
177-
bot: z.boolean(),
178-
avatar_decoration_data: z
179-
.union([
180-
z.object({asset: z.string(), skuId: z.string().optional(), expiresAt: z.number().optional()}),
181-
z.null(),
182-
])
183-
.optional(),
184-
premium_type: z.union([z.number(), z.null()]).optional(),
185-
}),
186-
z.null(),
187-
])
188-
.optional(),
169+
user: z.object({
170+
id: z.string(),
171+
username: z.string(),
172+
global_name: z.union([z.string(), z.null()]).optional(),
173+
discriminator: z.string(),
174+
avatar: z.union([z.string(), z.null()]).optional(),
175+
flags: z.number(),
176+
bot: z.boolean(),
177+
avatar_decoration_data: z
178+
.union([
179+
z.object({asset: z.string(), skuId: z.string().optional(), expiresAt: z.number().optional()}),
180+
z.null(),
181+
])
182+
.optional(),
183+
premium_type: z.union([z.number(), z.null()]).optional(),
184+
}),
189185
presence: z
190186
.object({
191187
status: z.string(),
@@ -246,6 +242,13 @@ export const GetRelationshipsResponseSchema = z.object({
246242
});
247243
export type GetRelationshipsResponse = zInfer<typeof GetRelationshipsResponseSchema>;
248244

245+
// INVITE_USER_EMBEDDED
246+
export const InviteUserEmbeddedRequestSchema = z.object({
247+
user_id: z.string(),
248+
content: z.string().min(0).max(1024).optional(),
249+
});
250+
export type InviteUserEmbeddedRequest = zInfer<typeof InviteUserEmbeddedRequestSchema>;
251+
249252
/**
250253
* RPC Commands which support schemas.
251254
*/
@@ -257,6 +260,7 @@ export enum Command {
257260
SHARE_INTERACTION = 'SHARE_INTERACTION',
258261
SHARE_LINK = 'SHARE_LINK',
259262
GET_RELATIONSHIPS = 'GET_RELATIONSHIPS',
263+
INVITE_USER_EMBEDDED = 'INVITE_USER_EMBEDDED',
260264
}
261265

262266
const emptyResponseSchema = z.object({}).optional().nullable();
@@ -294,4 +298,8 @@ export const Schemas = {
294298
request: emptyRequestSchema,
295299
response: GetRelationshipsResponseSchema,
296300
},
301+
[Command.INVITE_USER_EMBEDDED]: {
302+
request: InviteUserEmbeddedRequestSchema,
303+
response: emptyResponseSchema,
304+
},
297305
} as const;

src/mock.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,4 +181,5 @@ export const commandsMockDefault: IDiscordSDK['commands'] = {
181181
},
182182
],
183183
}),
184+
inviteUserEmbedded: () => Promise.resolve(null),
184185
};

src/schema/common.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export enum Commands {
3838
GET_ACTIVITY_INSTANCE_CONNECTED_PARTICIPANTS = 'GET_ACTIVITY_INSTANCE_CONNECTED_PARTICIPANTS',
3939
SHARE_LINK = 'SHARE_LINK',
4040
GET_RELATIONSHIPS = 'GET_RELATIONSHIPS',
41+
INVITE_USER_EMBEDDED = 'INVITE_USER_EMBEDDED',
4142
}
4243

4344
export const ReceiveFramePayload = zod

src/schema/responses.ts

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

0 commit comments

Comments
 (0)