-
-
Notifications
You must be signed in to change notification settings - Fork 114
/
v8.ts
48 lines (44 loc) · 1.71 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
import {
APIApplicationCommandDMInteraction,
APIApplicationCommandGuildInteraction,
APIApplicationCommandInteraction,
APIDMInteraction,
APIGuildInteraction,
APIInteraction,
} from '../payloads/v8/mod.ts';
/**
* A type-guard check for guild interactions.
* @param interaction The interaction to check against the
* @returns A boolean that indicates if the interaction was received from a guild
*/
export function isGuildInteraction(interaction: APIInteraction): interaction is APIGuildInteraction {
return Reflect.has(interaction, 'guild_id');
}
/**
* A type-guard check for DM interactions.
* @param interaction The interaction to check against
* @returns A boolean that indicates if the interaction was received from a direct message
*/
export function isDMInteraction(interaction: APIInteraction): interaction is APIDMInteraction {
return !isGuildInteraction(interaction);
}
/**
* A type-guard check for guild application command interactions.
* @param interaction The interaction to check against
* @returns A boolean that indicates if the command interaction was received from a guild
*/
export function isApplicationCommandGuildInteraction(
interaction: APIApplicationCommandInteraction,
): interaction is APIApplicationCommandGuildInteraction {
return isGuildInteraction(interaction);
}
/**
* A type-guard check for direct message application command interactions.
* @param interaction The interaction to check against
* @returns A boolean that indicates if the command interaction was received from a direct message
*/
export function isApplicationCommandDMInteraction(
interaction: APIApplicationCommandInteraction,
): interaction is APIApplicationCommandDMInteraction {
return !isGuildInteraction(interaction);
}