-
-
Notifications
You must be signed in to change notification settings - Fork 28
/
options.ts
94 lines (82 loc) · 3.84 KB
/
options.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
import {
ApplicationCommandOptionType,
type APIApplicationCommandOptionChoice,
type ChannelType,
} from 'discord-api-types/v10';
import type {
AutocompleteCallback,
MenuCommandContext,
OnAutocompleteErrorCallback,
ReturnOptionsTypes,
__TypesWrapper,
} from '..';
import type { MessageCommandInteraction, UserCommandInteraction } from '../../structures';
import type { CommandContext } from './chatcontext';
import type { MiddlewareContext } from './shared';
export type SeyfertBasicOption<T extends keyof __TypesWrapper, D = {}> = __TypesWrapper[T] & D;
export type SeyfertStringOption = SeyfertBasicOption<'String'> & {
autocomplete?: AutocompleteCallback;
onAutocompleteError?: OnAutocompleteErrorCallback;
choices?:
| readonly { readonly name: string; readonly value: string }[]
| APIApplicationCommandOptionChoice<ReturnOptionsTypes[ApplicationCommandOptionType.String]>[];
min_length?: number;
max_length?: number;
};
export type SeyfertIntegerOption = SeyfertBasicOption<'Integer'> & {
autocomplete?: AutocompleteCallback;
onAutocompleteError?: OnAutocompleteErrorCallback;
choices?: APIApplicationCommandOptionChoice<ReturnOptionsTypes[ApplicationCommandOptionType.Integer]>[];
min_value?: number;
max_value?: number;
};
export type SeyfertBooleanOption = SeyfertBasicOption<'Boolean'>;
export type SeyfertUserOption = SeyfertBasicOption<'User'>;
export type SeyfertChannelOption = SeyfertBasicOption<'Channel'> & {
channel_types?: ChannelType[];
};
export type SeyfertRoleOption = SeyfertBasicOption<'Role'>;
export type SeyfertMentionableOption = SeyfertBasicOption<'Mentionable'>;
export type SeyfertNumberOption = SeyfertBasicOption<'Number'> & {
autocomplete?: AutocompleteCallback;
onAutocompleteError?: OnAutocompleteErrorCallback;
choices?: APIApplicationCommandOptionChoice<ReturnOptionsTypes[ApplicationCommandOptionType.Number]>[];
min_value?: number;
max_value?: number;
};
export type SeyfertAttachmentOption = SeyfertBasicOption<'Attachment'>;
export function createStringOption<T extends SeyfertStringOption = SeyfertStringOption>(data: T) {
return { ...data, type: ApplicationCommandOptionType.String } as const;
}
export function createIntegerOption<T extends SeyfertIntegerOption = SeyfertIntegerOption>(data: T) {
return { ...data, type: ApplicationCommandOptionType.Integer } as const;
}
export function createBooleanOption<T extends SeyfertBooleanOption = SeyfertBooleanOption>(data: T) {
return { ...data, type: ApplicationCommandOptionType.Boolean } as const;
}
export function createUserOption<T extends SeyfertUserOption = SeyfertUserOption>(data: T) {
return { ...data, type: ApplicationCommandOptionType.User } as const;
}
export function createChannelOption<T extends SeyfertChannelOption = SeyfertChannelOption>(data: T) {
return { ...data, type: ApplicationCommandOptionType.Channel } as const;
}
export function createRoleOption<T extends SeyfertRoleOption = SeyfertRoleOption>(data: T) {
return { ...data, type: ApplicationCommandOptionType.Role } as const;
}
export function createMentionableOption<T extends SeyfertMentionableOption = SeyfertMentionableOption>(data: T) {
return { ...data, type: ApplicationCommandOptionType.Mentionable } as const;
}
export function createNumberOption<T extends SeyfertNumberOption = SeyfertNumberOption>(data: T) {
return { ...data, type: ApplicationCommandOptionType.Number } as const;
}
export function createAttachmentOption<T extends SeyfertAttachmentOption = SeyfertAttachmentOption>(data: T) {
return { ...data, type: ApplicationCommandOptionType.Attachment } as const;
}
export function createMiddleware<
T = any,
C extends CommandContext | MenuCommandContext<MessageCommandInteraction<boolean> | UserCommandInteraction<boolean>> =
| CommandContext
| MenuCommandContext<MessageCommandInteraction<boolean> | UserCommandInteraction<boolean>>,
>(data: MiddlewareContext<T, C>) {
return data;
}