/
v8.ts
103 lines (91 loc) · 3.56 KB
/
v8.ts
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
import {
APIApplicationCommandDMInteraction,
APIApplicationCommandGuildInteraction,
APIApplicationCommandInteraction,
APIButtonComponent,
APIButtonComponentWithCustomId,
APIButtonComponentWithURL,
APIDMInteraction,
APIGuildInteraction,
APIInteraction,
APIMessageComponentDMInteraction,
APIMessageComponentGuildInteraction,
APIMessageComponentInteraction,
ButtonStyle,
} from '../payloads/v8/mod.ts';
// Interactions
/**
* A type-guard check for DM interactions
* @param interaction The interaction to check against
* @returns A boolean that indicates if the interaction was received in a DM channel
*/
export function isDMInteraction(interaction: APIInteraction): interaction is APIDMInteraction {
return Reflect.has(interaction, 'user');
}
/**
* A type-guard check for guild interactions
* @param interaction The interaction to check against
* @returns A boolean that indicates if the interaction was received in a guild
*/
export function isGuildInteraction(interaction: APIInteraction): interaction is APIGuildInteraction {
return Reflect.has(interaction, 'guild_id');
}
// ApplicationCommandInteractions
/**
* A type-guard check for DM application command interactions
* @param interaction The application command interaction to check against
* @returns A boolean that indicates if the application command interaction was received in a DM channel
*/
export function isApplicationCommandDMInteraction(
interaction: APIApplicationCommandInteraction,
): interaction is APIApplicationCommandDMInteraction {
return isDMInteraction(interaction);
}
/**
* A type-guard check for guild application command interactions
* @param interaction The interaction to check against
* @returns A boolean that indicates if the application command interaction was received in a guild
*/
export function isApplicationCommandGuildInteraction(
interaction: APIApplicationCommandInteraction,
): interaction is APIApplicationCommandGuildInteraction {
return isGuildInteraction(interaction);
}
// MessageComponentInteractions
/**
* A type-guard check for DM message component interactions
* @param interaction The message component interaction to check against
* @returns A boolean that indicates if the message component interaction was received in a DM channel
*/
export function isMessageComponentDMInteraction(
interaction: APIMessageComponentInteraction,
): interaction is APIMessageComponentDMInteraction {
return isDMInteraction(interaction);
}
/**
* A type-guard check for guild message component interactions
* @param interaction The interaction to check against
* @returns A boolean that indicates if the message component interaction was received in a guild
*/
export function isMessageComponentGuildInteraction(
interaction: APIMessageComponentInteraction,
): interaction is APIMessageComponentGuildInteraction {
return isGuildInteraction(interaction);
}
// Buttons
/**
* A type-guard check for buttons that have a `url` attached to them.
* @param component The button to check against
* @returns A boolean that indicates if the button has a `url` attached to it
*/
export function isLinkButton(component: APIButtonComponent): component is APIButtonComponentWithURL {
return component.style === ButtonStyle.Link;
}
/**
* A type-guard check for buttons that have a `custom_id` attached to them.
* @param button The button to check against
* @returns A boolean that indicates if the button has a `custom_id` attached to it
*/
export function isInteractionButton(component: APIButtonComponent): component is APIButtonComponentWithCustomId {
return component.style !== ButtonStyle.Link;
}