Skip to content

Commit c1963e4

Browse files
xhyromDidas-git
andauthored
feat: add support for user-installable apps (Didas-git#23)
* Initial helpers implementation Thanks Didas-git#17 for the webhook idea. * Remove reply options from the core * Small update to the helpers * Add helpers to template generator choices * Completely change type organization * Update modules to comply to changes * This should not be here * Use enum to get event name `GatewayEvent` is not a `const enum` anymore but it shouldn't affect performance since listeners are compiled using the literals either way * Initial builder implementation This is far from ready but im pushing this so i can continue on my laptop * Add support for Polls (Didas-git#21) * feat: types for user installable apps * feat: adopt transformers for user installable apps * feat: adopt jsx for user-installable apps * test: make ping command available in dms * refactor: assign not required in interaction context type enum * Initial helpers implementation Thanks Didas-git#17 for the webhook idea. * Completely change type organization * Update modules to comply to changes * This should not be here * Initial builder implementation This is far from ready but im pushing this so i can continue on my laptop * Add support for Polls (Didas-git#21) * feat: types for user installable apps * feat: adopt transformers for user installable apps * feat: adopt jsx for user-installable apps * test: make ping command available in dms * refactor: assign not required in interaction context type enum * rebase * revert(core): remove new line in pkg json * fix: add USE_EXTERNAL_APPS permission * refactor: remove deprecated fields --------- Co-authored-by: DidaS <didasoficial@gmail.com>
1 parent 2640439 commit c1963e4

File tree

10 files changed

+79
-12
lines changed

10 files changed

+79
-12
lines changed

packages/core/src/enums/interaction.ts

+6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ export const enum InteractionType {
66
MODAL_SUBMIT
77
}
88

9+
export const enum InteractionContextType {
10+
GUILD,
11+
BOT_DM,
12+
PRIVATE_CHANNEL
13+
}
14+
915
export const enum ApplicationCommandType {
1016
CHAT_INPUT = 1,
1117
USER,

packages/core/src/enums/permissions.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,6 @@ export const PermissionFlags = {
4747
CREATE_EVENTS: 17592186044416n,
4848
USE_EXTERNAL_SOUNDS: 35184372088832n,
4949
SEND_VOICE_MESSAGES: 70368744177664n,
50-
SEND_POLLS: 562949953421312n
50+
SEND_POLLS: 562949953421312n,
51+
USE_EXTERNAL_APPS: 1125899906842624n
5152
} as const;

packages/core/src/typings/application-command.ts

+14-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
import type { ApplicationCommandOptionType, ApplicationCommandPermissionType, ApplicationCommandType, ChannelType } from "#enums";
1+
import type {
2+
ApplicationCommandOptionType,
3+
ApplicationCommandPermissionType,
4+
ApplicationCommandType,
5+
ApplicationIntegrationType,
6+
ChannelType,
7+
InteractionContextType
8+
} from "#enums";
29
import type { ResolvedDataStructure } from "./others.js";
310
import type { Localizations as _Localizations } from "./localizations.js";
411

@@ -44,8 +51,9 @@ export declare namespace ApplicationCommand {
4451
description: string;
4552
options?: Array<Option.Structure>;
4653
default_member_permissions: string | null;
47-
dm_permission: boolean;
4854
nsfw?: boolean;
55+
integration_types?: Array<ApplicationIntegrationType>;
56+
contexts?: Array<InteractionContextType>;
4957
version: number;
5058
}
5159

@@ -59,6 +67,7 @@ export declare namespace ApplicationCommand {
5967
options?: Array<Option.Structure>;
6068
default_member_permissions: string | null;
6169
nsfw?: boolean;
70+
integration_types?: Array<ApplicationIntegrationType>;
6271
version: number;
6372
}
6473

@@ -115,7 +124,10 @@ export declare namespace ApplicationCommand {
115124
description?: string;
116125
options?: Array<ApplicationCommandOption.Structure>;
117126
default_member_permissions?: string | null;
127+
/** @deprecated Use {@link ApplicationCommandJSONParams.contexts} instead */
118128
dm_permission?: boolean | null;
129+
integration_types?: Array<ApplicationIntegrationType> | null;
130+
contexts?: Array<InteractionContextType> | null;
119131
type?: ApplicationCommandType;
120132
nsfw?: boolean;
121133
}

packages/core/src/typings/application.ts

+1
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,5 @@ export declare namespace Application {
9090
description: string;
9191
}
9292

93+
export type IntegrationTypeMap = Record<ApplicationIntegrationType, string>;
9394
}

packages/core/src/typings/interaction.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { ApplicationCommandOption } from "./application-command-options.js";
22
import type { LilybirdAttachment, ResolvedDataStructure } from "./others.js";
33
import type { ApplicationCommand } from "./application-command.js";
4+
import type { Application } from "./application.js";
45
import type { Channel } from "./channel.js";
56
import type { Message } from "./message.js";
67
import type { Guild } from "./guild.js";
@@ -13,7 +14,8 @@ import type {
1314
EntitlementType,
1415
InteractionType,
1516
ComponentType,
16-
Locale
17+
Locale,
18+
InteractionContextType
1719
} from "#enums";
1820

1921
export declare namespace Interaction {
@@ -26,16 +28,18 @@ export declare namespace Interaction {
2628
data?: DataStructure;
2729
token: string;
2830
version: number;
31+
app_permissions: string;
2932
locale: Locale;
3033
entitlements: Array<EntitlementStructure>;
34+
authorizing_integration_owners: Application.IntegrationTypeMap;
35+
context?: InteractionContextType;
3136
}
3237

3338
export interface GuildStructure extends Base {
3439
guild_id: string;
3540
channel: Partial<Channel.Structure>;
3641
channel_id: string;
3742
member: Guild.MemberStructure;
38-
app_permissions: string;
3943
guild_locale: Locale;
4044
}
4145

packages/core/src/typings/message.ts

+14
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export declare namespace Message {
5050
*/
5151
flags?: number;
5252
referenced_message?: Structure | null;
53+
interaction_metadata?: InteractionMetadataStructure;
5354
interaction?: InteractionStructure;
5455
thread?: Channel.Structure;
5556
/** This does not exist without the intent */
@@ -76,6 +77,19 @@ export declare namespace Message {
7677
member?: Partial<Guild.MemberStructure>;
7778
}
7879

80+
/**
81+
* @see {@link https://discord.com/developers/docs/resources/channel#message-interaction-metadata-object-message-interaction-metadata-structure}
82+
*/
83+
export interface InteractionMetadataStructure {
84+
id: string;
85+
type: InteractionType;
86+
user: User.Structure;
87+
authorizing_integration_owners: Application.IntegrationTypeMap;
88+
original_response_message_id?: string;
89+
interacted_message_id?: string;
90+
triggering_interaction_metadata?: InteractionMetadataStructure;
91+
}
92+
7993
/**
8094
* @see {@link https://discord.com/developers/docs/resources/channel#message-reference-object-message-reference-structure}
8195
*/

packages/jsx/src/command.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,18 @@ import { ApplicationCommandOptionType, ApplicationCommandType } from "lilybird";
55
import type {
66
ApplicationCommand as LilyApplicationCommand,
77
PermissionFlags,
8-
Locale
8+
Locale,
9+
ApplicationIntegrationType,
10+
InteractionContextType
911
} from "lilybird";
1012

1113
export function ApplicationCommand({
1214
name,
1315
description,
1416
defaultMemberPermissions,
1517
dmPermission,
18+
integrationTypes,
19+
contexts,
1620
name_localizations,
1721
description_localizations,
1822
nsfw,
@@ -22,6 +26,8 @@ export function ApplicationCommand({
2226
description: string,
2327
defaultMemberPermissions?: Array<typeof PermissionFlags[keyof typeof PermissionFlags]> | null,
2428
dmPermission?: boolean | null,
29+
integrationTypes?: Array<ApplicationIntegrationType> | null,
30+
contexts?: Array<InteractionContextType> | null,
2531
nsfw?: boolean,
2632
name_localizations?: Record<Locale, string> | null,
2733
description_localizations?: Record<Locale, string> | null,
@@ -34,6 +40,8 @@ export function ApplicationCommand({
3440
name,
3541
description,
3642
dm_permission: dmPermission,
43+
integration_types: integrationTypes,
44+
contexts,
3745
name_localizations,
3846
description_localizations,
3947
nsfw,

packages/test/src/commands/ping.tsx

+16-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
1-
import type { SlashCommand } from "@lilybird/handlers";
1+
import type { ApplicationCommand } from "@lilybird/handlers";
2+
import { ApplicationIntegrationType, InteractionContextType } from "lilybird";
23

34
export default {
45
post: "GLOBAL",
5-
data: { name: "ping", description: "pong" },
6+
data: {
7+
name: "ping",
8+
description: "pong",
9+
integration_types: [
10+
ApplicationIntegrationType.GUILD_INSTALL,
11+
ApplicationIntegrationType.USER_INSTALL
12+
],
13+
contexts: [
14+
InteractionContextType.BOT_DM,
15+
InteractionContextType.GUILD,
16+
InteractionContextType.PRIVATE_CHANNEL
17+
],
18+
},
619
run: async (interaction) => {
720
await interaction.deferReply();
821

@@ -17,4 +30,4 @@ export default {
1730
depth: 1
1831
}));
1932
}
20-
} satisfies SlashCommand;
33+
} satisfies ApplicationCommand;

packages/transformers/src/factories/interaction.ts

+9-3
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@ import type { ReplyOptions } from "../typings/shared.js";
1717
import type { PartialChannel } from "./channel.js";
1818

1919
import type {
20+
Application as LilyApplication,
2021
Interaction as LilyInteraction,
2122
Message as LilyMessage,
2223
ResolvedDataStructure,
2324
LilybirdAttachment,
2425
Locale,
2526
Client,
26-
ApplicationCommand
27+
ApplicationCommand,
28+
InteractionContextType
2729
} from "lilybird";
2830

2931
export function interactionFactory(client: Client, interaction: LilyInteraction.Structure): Interaction {
@@ -77,9 +79,12 @@ export class Interaction<T extends InteractionData = InteractionData, M extends
7779
public readonly type: InteractionType;
7880
public readonly token: string;
7981
public readonly version = 1;
82+
public readonly appPermissions: string;
8083
/** This is only undefined if type is PING */
8184
public readonly locale: Locale | undefined;
8285
public readonly entitlements: Array<LilyInteraction.EntitlementStructure>;
86+
public readonly authorizingIntegrationOwners: LilyApplication.IntegrationTypeMap;
87+
public readonly context: InteractionContextType | undefined;
8388
public readonly data: T;
8489
public readonly message: M = <M>undefined;
8590

@@ -93,8 +98,11 @@ export class Interaction<T extends InteractionData = InteractionData, M extends
9398
this.applicationId = interaction.application_id;
9499
this.type = interaction.type;
95100
this.token = interaction.token;
101+
this.appPermissions = interaction.app_permissions;
96102
this.locale = interaction.locale;
97103
this.entitlements = interaction.entitlements;
104+
this.authorizingIntegrationOwners = interaction.authorizing_integration_owners;
105+
this.context = interaction.context;
98106

99107
this.data = <never>data;
100108

@@ -389,7 +397,6 @@ export class GuildInteraction<T extends InteractionData, M extends undefined | M
389397
public readonly channel: PartialChannel;
390398
public readonly channelId: string;
391399
public readonly member: GuildMember;
392-
public readonly appPermissions: string;
393400
public readonly guildLocale: Locale;
394401

395402
public constructor(client: Client, interaction: LilyInteraction.GuildStructure, isDM: boolean, data?: T) {
@@ -399,7 +406,6 @@ export class GuildInteraction<T extends InteractionData, M extends undefined | M
399406
this.channel = channelFactory(client, interaction.channel);
400407
this.channelId = interaction.channel_id;
401408
this.member = new GuildMember(client, interaction.member);
402-
this.appPermissions = interaction.app_permissions;
403409
this.guildLocale = interaction.guild_locale;
404410
}
405411
}

packages/transformers/src/factories/message.ts

+2
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ export class Message {
5959
public readonly messageReference: LilyMessage.ReferenceStructure | undefined;
6060
public readonly flags: number;
6161
public readonly referencedMessage: Message | undefined;
62+
public readonly interactionMetadata: LilyMessage.InteractionMetadataStructure | undefined;
6263
public readonly interaction: LilyMessage.InteractionStructure | undefined;
6364
public readonly thread: Channel | undefined;
6465
public readonly components: Array<LilyMessage.Component.Structure> | undefined;
@@ -96,6 +97,7 @@ export class Message {
9697
this.applicationId = message.application_id;
9798
this.messageReference = message.message_reference;
9899
this.flags = message.flags ?? 0;
100+
this.interactionMetadata = message.interaction_metadata;
99101
this.interaction = message.interaction;
100102
this.components = message.components;
101103
this.stickerItems = message.sticker_items;

0 commit comments

Comments
 (0)