Skip to content
This repository was archived by the owner on Oct 13, 2022. It is now read-only.

Commit 445ea13

Browse files
committed
Add class with methods (options)
1 parent 9774f7e commit 445ea13

File tree

1 file changed

+104
-0
lines changed

1 file changed

+104
-0
lines changed

src/commons/SlashCommandMethods.ts

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
import { isFunction } from 'lodash';
2+
3+
import { ApplicationCommandOptionStructure } from '@src/interfaces';
4+
5+
import SlashCommandOption from '@common/SlashCommandOption';
6+
7+
import SlashCommandBooleanOption from '@option/SlashCommandBooleanOption';
8+
import SlashCommandChannelOption from '@option/SlashCommandChannelOption';
9+
import SlashCommandIntegerOption from '@option/SlashCommandIntegerOption';
10+
import SlashCommandMentionableOption from '@option/SlashCommandMentionableOption';
11+
import SlashCommandNumberOption from '@option/SlashCommandNumberOption';
12+
import SlashCommandRoleOption from '@option/SlashCommandRoleOption';
13+
import SlashCommandStringOption from '@option/SlashCommandStringOption';
14+
import SlashCommandUserOption from '@option/SlashCommandUserOption';
15+
16+
/*
17+
|--------------------------------------------------------------------------
18+
| SlashCommandBuilder::Commons -> SlashCommandMethods
19+
|--------------------------------------------------------------------------
20+
|
21+
| ...
22+
|
23+
*/
24+
25+
export default class SlashCommandMethods {
26+
public readonly options: Array<ApplicationCommandOptionStructure> = [];
27+
28+
public addBooleanOption(
29+
callback: (builder: SlashCommandBooleanOption) => SlashCommandBooleanOption
30+
): this {
31+
this.addNewOption(callback, SlashCommandBooleanOption);
32+
33+
return this;
34+
}
35+
36+
public addChannelOption(
37+
callback: (builder: SlashCommandChannelOption) => SlashCommandChannelOption
38+
): this {
39+
this.addNewOption(callback, SlashCommandChannelOption);
40+
41+
return this;
42+
}
43+
44+
public addIntegerOption(
45+
callback: (builder: SlashCommandIntegerOption) => SlashCommandIntegerOption
46+
): this {
47+
this.addNewOption(callback, SlashCommandIntegerOption);
48+
49+
return this;
50+
}
51+
52+
public addMentionableOption(
53+
callback: (builder: SlashCommandMentionableOption) => SlashCommandMentionableOption
54+
): this {
55+
this.addNewOption(callback, SlashCommandMentionableOption);
56+
57+
return this;
58+
}
59+
60+
public addNumberOption(
61+
callback: (builder: SlashCommandNumberOption) => SlashCommandNumberOption
62+
): this {
63+
this.addNewOption(callback, SlashCommandNumberOption);
64+
65+
return this;
66+
}
67+
68+
public addRoleOption(
69+
callback: (builder: SlashCommandRoleOption) => SlashCommandRoleOption
70+
): this {
71+
this.addNewOption(callback, SlashCommandRoleOption);
72+
73+
return this;
74+
}
75+
76+
public addStringOption(
77+
callback: (builder: SlashCommandStringOption) => SlashCommandStringOption
78+
): this {
79+
this.addNewOption(callback, SlashCommandStringOption);
80+
81+
return this;
82+
}
83+
84+
public addUserOption(
85+
callback: (builder: SlashCommandUserOption) => SlashCommandUserOption
86+
): this {
87+
this.addNewOption(callback, SlashCommandUserOption);
88+
89+
return this;
90+
}
91+
92+
private addNewOption<A extends SlashCommandOption>(
93+
callback: (builder: A) => A,
94+
Instance: new () => A,
95+
): this {
96+
if (!isFunction(callback)) {
97+
throw new Error('The `callback` parameter is not a function');
98+
}
99+
100+
this.options.push(callback(new Instance()).toJSON());
101+
102+
return this;
103+
}
104+
}

0 commit comments

Comments
 (0)