Skip to content

Commit

Permalink
improve error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Starman3787 committed Jul 17, 2024
1 parent 925bc96 commit 5d7f0d9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/util/builder/buttonBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ class Button {
* @returns {Button}
*/
setLabel(label) {

if (!label) throw new TypeError("GLUON: Button label must be provided.");

this.label = label;

return this;
Expand All @@ -32,6 +35,8 @@ class Button {
setEmoji(emoji) {
this.emoji = resolveEmoji(emoji);

if (!this.emoji) throw new TypeError("GLUON: Button emoji must be provided.");

return this;
}

Expand Down
10 changes: 9 additions & 1 deletion src/util/discord/resolveEmoji.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,17 @@
* @returns {Object}
*/
function resolveEmoji(text) {

if (typeof text !== "string")
throw new TypeError("GLUON: The emoji must be a string.");

const emojis = text.match(/<:[^:\s]+:[0-9]+>|<a:[^:\s]+:[0-9]+>/g);

if (!emojis || emojis.length == 0) return null;
if (!emojis || emojis.length == 0) {
if (/\p{Extended_Pictographic}/u.test(text))
return { name: text, id: null };
return null;
}

const splitEmoji = emojis[0].replace(/<|>/g, "").split(":");

Expand Down

0 comments on commit 5d7f0d9

Please sign in to comment.