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

Commit 9774f7e

Browse files
committed
Add command options
1 parent 80fe6a8 commit 9774f7e

8 files changed

+232
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { ApplicationCommandOptionTypes } from '@src/interfaces';
2+
3+
import SlashCommandOption from '@common/SlashCommandOption';
4+
5+
/*
6+
|--------------------------------------------------------------------------
7+
| SlashCommandBuilder::Options -> SlashCommandBooleanOption
8+
|--------------------------------------------------------------------------
9+
|
10+
| ...
11+
|
12+
*/
13+
14+
export default class SlashCommandBooleanOption extends SlashCommandOption {
15+
public override readonly type = ApplicationCommandOptionTypes.Boolean;
16+
17+
constructor() {
18+
super(ApplicationCommandOptionTypes.Boolean);
19+
}
20+
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import { isArray, isEmpty, isNumber } from 'lodash';
2+
3+
import {
4+
ApplicationCommandOptionStructure,
5+
ApplicationCommandOptionTypes,
6+
ChannelTypes,
7+
} from '@src/interfaces';
8+
9+
import SlashCommandOption from '@common/SlashCommandOption';
10+
11+
/*
12+
|--------------------------------------------------------------------------
13+
| SlashCommandBuilder::Options -> SlashCommandChannelOption
14+
|--------------------------------------------------------------------------
15+
|
16+
| ...
17+
|
18+
*/
19+
20+
const allowTypes: Array<number> = [
21+
ChannelTypes.GUILD_TEXT,
22+
ChannelTypes.DM,
23+
ChannelTypes.GUILD_VOICE,
24+
ChannelTypes.GROUP_DM,
25+
ChannelTypes.GUILD_CATEGORY,
26+
ChannelTypes.GUILD_NEWS,
27+
ChannelTypes.GUILD_STORE,
28+
ChannelTypes.GUILD_NEWS_THREAD,
29+
ChannelTypes.GUILD_PUBLIC_THREAD,
30+
ChannelTypes.GUILD_PRIVATE_THREAD,
31+
ChannelTypes.GUILD_STAGE_VOICE,
32+
];
33+
34+
export default class SlashCommandChannelOption extends SlashCommandOption {
35+
public override readonly type = ApplicationCommandOptionTypes.Channel;
36+
public readonly channelTypes: Array<ChannelTypes> = [];
37+
38+
constructor() {
39+
super(ApplicationCommandOptionTypes.Channel);
40+
}
41+
42+
public addFilterBy(value: Array<ChannelTypes>| ChannelTypes): this {
43+
let deny: boolean = true;
44+
45+
if (isArray(value)) {
46+
deny = isEmpty(value);
47+
} else {
48+
deny = !isNumber(value);
49+
}
50+
51+
if (deny) {
52+
throw new Error('The `value` parameter is not an array/ChannelType or is empty');
53+
}
54+
55+
if (isArray(value)) {
56+
for (const item of value) {
57+
if (!this.channelTypes.includes(item)) {
58+
if (!this.checkType(item)) {
59+
break;
60+
}
61+
62+
this.channelTypes.push(item);
63+
}
64+
}
65+
} else if (!this.channelTypes.includes(value)) {
66+
if (!this.checkType(value)) {
67+
return this;
68+
}
69+
70+
this.channelTypes.push(value);
71+
}
72+
73+
return this;
74+
}
75+
76+
public override toJSON(): ApplicationCommandOptionStructure {
77+
return {
78+
...super.toJSON(),
79+
channel_types: this.channelTypes,
80+
};
81+
}
82+
83+
private checkType(type: ChannelTypes): boolean {
84+
let validate: boolean = allowTypes.includes(type);
85+
86+
if (!validate) {
87+
throw new Error('The `value` parameter is not a ChannelType');
88+
}
89+
90+
return validate;
91+
}
92+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { ApplicationCommandOptionTypes } from '@src/interfaces';
2+
3+
import SlashCommandOptionWithChoices from '@common/SlashCommandOptionWithChoices';
4+
5+
/*
6+
|--------------------------------------------------------------------------
7+
| SlashCommandBuilder::Options -> SlashCommandIntegerOption
8+
|--------------------------------------------------------------------------
9+
|
10+
| ...
11+
|
12+
*/
13+
14+
export default class SlashCommandIntegerOption extends SlashCommandOptionWithChoices<number> {
15+
public override readonly type = ApplicationCommandOptionTypes.Integer;
16+
17+
constructor() {
18+
super(ApplicationCommandOptionTypes.Integer);
19+
}
20+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { ApplicationCommandOptionTypes } from '@src/interfaces';
2+
3+
import SlashCommandOption from '@common/SlashCommandOption';
4+
5+
/*
6+
|--------------------------------------------------------------------------
7+
| SlashCommandBuilder::Options -> SlashCommandMentionableOption
8+
|--------------------------------------------------------------------------
9+
|
10+
| ...
11+
|
12+
*/
13+
14+
export default class SlashCommandMentionableOption extends SlashCommandOption {
15+
public override readonly type = ApplicationCommandOptionTypes.Mentionable;
16+
17+
constructor() {
18+
super(ApplicationCommandOptionTypes.Mentionable);
19+
}
20+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { ApplicationCommandOptionTypes } from '@src/interfaces';
2+
3+
import SlashCommandOptionWithChoices from '@common/SlashCommandOptionWithChoices';
4+
5+
/*
6+
|--------------------------------------------------------------------------
7+
| SlashCommandBuilder::Options -> SlashCommandNumberOption
8+
|--------------------------------------------------------------------------
9+
|
10+
| ...
11+
|
12+
*/
13+
14+
export default class SlashCommandNumberOption extends SlashCommandOptionWithChoices<number> {
15+
public override readonly type = ApplicationCommandOptionTypes.Number;
16+
17+
constructor() {
18+
super(ApplicationCommandOptionTypes.Number);
19+
}
20+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { ApplicationCommandOptionTypes } from '@src/interfaces';
2+
3+
import SlashCommandOption from '@common/SlashCommandOption';
4+
5+
/*
6+
|--------------------------------------------------------------------------
7+
| SlashCommandBuilder::Options -> SlashCommandRoleOption
8+
|--------------------------------------------------------------------------
9+
|
10+
| ...
11+
|
12+
*/
13+
14+
export default class SlashCommandRoleOption extends SlashCommandOption {
15+
public override readonly type = ApplicationCommandOptionTypes.Role;
16+
17+
constructor() {
18+
super(ApplicationCommandOptionTypes.Role);
19+
}
20+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { ApplicationCommandOptionTypes } from '@src/interfaces';
2+
3+
import SlashCommandOptionWithChoices from '@common/SlashCommandOptionWithChoices';
4+
5+
/*
6+
|--------------------------------------------------------------------------
7+
| SlashCommandBuilder::Options -> SlashCommandStringOption
8+
|--------------------------------------------------------------------------
9+
|
10+
| ...
11+
|
12+
*/
13+
14+
export default class SlashCommandStringOption extends SlashCommandOptionWithChoices<string> {
15+
public override readonly type = ApplicationCommandOptionTypes.String;
16+
17+
constructor() {
18+
super(ApplicationCommandOptionTypes.String);
19+
}
20+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { ApplicationCommandOptionTypes } from '@src/interfaces';
2+
3+
import SlashCommandOption from '@common/SlashCommandOption';
4+
5+
/*
6+
|--------------------------------------------------------------------------
7+
| SlashCommandBuilder::Options -> SlashCommandUserOption
8+
|--------------------------------------------------------------------------
9+
|
10+
| ...
11+
|
12+
*/
13+
14+
export default class SlashCommandUserOption extends SlashCommandOption {
15+
public override readonly type = ApplicationCommandOptionTypes.User;
16+
17+
constructor() {
18+
super(ApplicationCommandOptionTypes.User);
19+
}
20+
}

0 commit comments

Comments
 (0)