-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add #from for easy builder conversions
- Loading branch information
1 parent
ee143e0
commit 48fdac6
Showing
6 changed files
with
85 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,24 @@ | ||
'use strict'; | ||
|
||
const { ButtonBuilder: BuildersButtonComponent } = require('@discordjs/builders'); | ||
const { ButtonBuilder: BuildersButtonComponent, isJSONEncodable } = require('@discordjs/builders'); | ||
const Transformers = require('../util/Transformers'); | ||
|
||
class ButtonBuilder extends BuildersButtonComponent { | ||
constructor(data) { | ||
super(Transformers.toSnakeCase(data)); | ||
} | ||
|
||
/** | ||
* Creates a new button builder from json data | ||
* @param {JSONEncodable<APIButtonComponent> | APIButtonComponent} other The other data | ||
* @returns {ButtonBuilder} | ||
*/ | ||
static from(other) { | ||
if (isJSONEncodable(other)) { | ||
return new this(other.toJSON()); | ||
} | ||
return new this(other); | ||
} | ||
} | ||
|
||
module.exports = ButtonBuilder; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,24 @@ | ||
'use strict'; | ||
|
||
const { EmbedBuilder: BuildersEmbed } = require('@discordjs/builders'); | ||
const { EmbedBuilder: BuildersEmbed, isJSONEncodable } = require('@discordjs/builders'); | ||
const Transformers = require('../util/Transformers'); | ||
|
||
class EmbedBuilder extends BuildersEmbed { | ||
constructor(data) { | ||
super(Transformers.toSnakeCase(data)); | ||
} | ||
|
||
/** | ||
* Creates a new embed builder from json data | ||
* @param {JSONEncodable<APIEmbed> | APIEmbed} other The other data | ||
* @returns {EmbedBuilder} | ||
*/ | ||
static from(other) { | ||
if (isJSONEncodable(other)) { | ||
return new this(other.toJSON()); | ||
} | ||
return new this(other); | ||
} | ||
} | ||
|
||
module.exports = EmbedBuilder; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,24 @@ | ||
'use strict'; | ||
|
||
const { SelectMenuBuilder: BuildersSelectMenuComponent } = require('@discordjs/builders'); | ||
const { SelectMenuBuilder: BuildersSelectMenuComponent, isJSONEncodable } = require('@discordjs/builders'); | ||
const Transformers = require('../util/Transformers'); | ||
|
||
class SelectMenuBuilder extends BuildersSelectMenuComponent { | ||
constructor(data) { | ||
super(Transformers.toSnakeCase(data)); | ||
} | ||
|
||
/** | ||
* Creates a new select menu builder from json data | ||
* @param {JSONEncodable<APISelectMenuComponent> | APISelectMenuComponent} other The other data | ||
* @returns {SelectMenuBuilder} | ||
*/ | ||
static from(other) { | ||
if (isJSONEncodable(other)) { | ||
return new this(other.toJSON()); | ||
} | ||
return new this(other); | ||
} | ||
} | ||
|
||
module.exports = SelectMenuBuilder; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,24 @@ | ||
'use strict'; | ||
|
||
const { TextInputBuilder: BuildersTextInputComponent } = require('@discordjs/builders'); | ||
const { TextInputBuilder: BuildersTextInputComponent, isJSONEncodable } = require('@discordjs/builders'); | ||
const Transformers = require('../util/Transformers'); | ||
|
||
class TextInputBuilder extends BuildersTextInputComponent { | ||
constructor(data) { | ||
super(Transformers.toSnakeCase(data)); | ||
} | ||
|
||
/** | ||
* Creates a new text input builder from json data | ||
* @param {JSONEncodable<APITextInputComponent> | APITextInputComponent} other The other data | ||
* @returns {TextInputBuilder} | ||
*/ | ||
static from(other) { | ||
if (isJSONEncodable(other)) { | ||
return new this(other.toJSON()); | ||
} | ||
return new this(other); | ||
} | ||
} | ||
|
||
module.exports = TextInputBuilder; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters