-
-
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.
refactor: allow djs builders to accept camel case json
- Loading branch information
1 parent
b936103
commit 57a9430
Showing
8 changed files
with
125 additions
and
36 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
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
'use strict'; | ||
|
||
const Builders = require('@discordjs/builders'); | ||
const Components = require('../util/Components'); | ||
|
||
class ActionRow extends Builders.ActionRow { | ||
constructor(data) { | ||
// TODO: Simply when getters PR is merged. | ||
const initData = Components.transformJSON(data); | ||
super({ ...initData, components: initData.components ?? [] }); | ||
} | ||
} | ||
|
||
module.exports = ActionRow; |
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
'use strict'; | ||
|
||
const Builders = require('@discordjs/builders'); | ||
const Components = require('../util/Components'); | ||
|
||
class ButtonComponent extends Builders.ButtonComponent { | ||
constructor(data) { | ||
super(Components.transformJSON(data)); | ||
} | ||
} | ||
|
||
module.exports = ButtonComponent; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
'use strict'; | ||
|
||
const Builders = require('@discordjs/builders'); | ||
const Components = require('../util/Components'); | ||
|
||
class SelectMenuComponent extends Builders.SelectMenuComponent { | ||
constructor(data) { | ||
super(Components.transformJSON(data)); | ||
} | ||
} | ||
|
||
module.exports = SelectMenuComponent; |
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
'use strict'; | ||
|
||
class Components extends null { | ||
/** | ||
* Transforms json data into api-compatible json data. | ||
* @param {MessageComponentData|APIMessageComponent} data The data to transform. | ||
* @returns {APIMessageComponentData} | ||
*/ | ||
static transformJSON(data) { | ||
return { | ||
type: data?.type, | ||
custom_id: data?.customId ?? data?.custom_id, | ||
disabled: data?.disabled, | ||
style: data?.style, | ||
label: data?.label, | ||
emoji: data?.emoji, | ||
url: data?.url, | ||
options: data?.options, | ||
placeholder: data?.placeholder, | ||
min_values: data?.minValues ?? data?.min_values, | ||
max_values: data?.maxValues ?? data?.max_values, | ||
components: data?.components?.map(c => Components.transformJSON(c)), | ||
}; | ||
} | ||
} | ||
|
||
module.exports = Components; |
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