Skip to content

Commit

Permalink
Merge pull request #16 from RabbitHouseCorp/restructuring(slashCommand)
Browse files Browse the repository at this point in the history
Restructuring(slash command)
  • Loading branch information
nayvcake authored May 2, 2022
2 parents 928672d + f14d714 commit 331cd72
Show file tree
Hide file tree
Showing 2 changed files with 204 additions and 67 deletions.
88 changes: 64 additions & 24 deletions lib/slashcommand/CommandBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class CommandBase {
*/
this.id = data.id ?? null;
}
if (data.id !== undefined) {
if (data.type !== undefined) {
/**
*
* @type {null|number}
Expand Down Expand Up @@ -43,13 +43,19 @@ class CommandBase {
*/
this.name = data.name ?? '';
}
if (data.name_localizations !== undefined) {
this.nameLocalizations = data.name_localizations;
}
if (data.description !== undefined) {
/**
*
* @type {string|string}
*/
this.description = data.description ?? '';
}
if (data.description_localizations !== undefined) {
this.descriptionLocalizations = data.description_localizations;
}
if (data.options !== undefined) {
/**
*
Expand Down Expand Up @@ -78,6 +84,7 @@ class CommandBase {

}


/**
*
* @param options
Expand Down Expand Up @@ -120,6 +127,32 @@ class CommandBase {
this.description = description;
return this;
}
/**
*
* @param description
* @returns {CommandOptions}
* @example
* ```js
* .setDescriptionLocalizations({
* "en-US": "Hello!",
* "{locale}": "{new description}"
* })
* ```
* @link https://discord.com/developers/docs/reference#locales
*/
setDescriptionLocalizations(translations) {
if (translations == undefined) {
throw Error('Method called setDescriptionLocalizations must have an input argument');
}
if (typeof description !== 'object') {
throw Error('Method called setDescriptionLocalizations is entering wrong call argument. Correct argument would be a object input.');
}
this.descriptionLocalizations = translations;
return this;
}



setMaxValue(value) {
this.maxValue = value;
return this;
Expand All @@ -137,34 +170,35 @@ class CommandBase {
this.name = name;
return this;
}
/**
*
* @param translations
* @returns {CommandOptions}
* @example
* ```js
* .setNameLocalizations({
* "en-US": "Hello!",
* "{locale}": "{new description}"
* })
* ```
* @link https://discord.com/developers/docs/reference#locales
*/
setNameLocalizations(translations) {
if (translations == undefined) {
throw Error('Method called setNameLocalizations must have an input argument');
}
if (typeof translations !== 'object') {
throw Error('Method called setNameLocalizations is entering wrong call argument. Correct argument would be a object input.');
}
this.nameLocalizations = translations;
return this;
}

setType(type) {
this.type = type;
return this;
}
























/**
*
* @returns {{default_permission: (*|boolean), name: string, options: (CommandOptions|*[]), description: string, id: (string|null), application_id: (*|string|null)}}
Expand All @@ -177,6 +211,12 @@ class CommandBase {
description: this.description,
default_permission: this.defaultPermission
};
if (this.nameLocalizations !== undefined) {
data.name_localizations = this.nameLocalizations;
}
if (this.descriptionLocalizations !== undefined) {
data.description_localizations = this.descriptionLocalizations;
}
if (this.maxValue !== undefined) {
data.max_value = this.maxValue;
}
Expand Down
Loading

0 comments on commit 331cd72

Please sign in to comment.