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

Commit 08fb815

Browse files
committed
Add option base
1 parent 844a399 commit 08fb815

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

src/commons/SlashCommandOption.ts

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import { isUndefined } from 'lodash';
2+
3+
import {
4+
ApplicationCommandOptionTypes,
5+
ApplicationCommandOptionStructure,
6+
} from '@src/interfaces';
7+
8+
/*
9+
|--------------------------------------------------------------------------
10+
| SlashCommandBuilder::Commons -> SlashCommandOption
11+
|--------------------------------------------------------------------------
12+
|
13+
| ...
14+
|
15+
*/
16+
17+
export default class SlashCommandOption {
18+
public readonly type: ApplicationCommandOptionTypes;
19+
public readonly name: string = '';
20+
public readonly description: string = '';
21+
public readonly required: boolean = false;
22+
23+
constructor(type: ApplicationCommandOptionTypes) {
24+
this.type = type;
25+
}
26+
27+
public setName(value: string): this {
28+
Reflect.set(this, 'name', value);
29+
30+
return this;
31+
}
32+
33+
public setDescription(value: string): this {
34+
Reflect.set(this, 'description', value);
35+
36+
return this;
37+
}
38+
39+
public setRequired(value: boolean): this {
40+
Reflect.set(this, 'required', value);
41+
42+
return this;
43+
}
44+
45+
public toJSON(): ApplicationCommandOptionStructure {
46+
if (isUndefined(this.type)) {
47+
throw new Error('The `type` parameter should not be empty');
48+
}
49+
50+
const response: ApplicationCommandOptionStructure = {
51+
type: this.type,
52+
name: this.name,
53+
description: this.description,
54+
required: this.required,
55+
};
56+
57+
return response;
58+
}
59+
}

0 commit comments

Comments
 (0)