mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
feat(builders): improve embed errors and predicates (#7795)
* feat(builders): improve embed errors * fix: use imageURLPredicates Co-authored-by: Synbulat Biishev <arziksin@gmail.com> Co-authored-by: Synbulat Biishev <arziksin@gmail.com>
This commit is contained in:
@@ -31,6 +31,12 @@ export const urlPredicate = s.string.url({
|
||||
allowedProtocols: ['http:', 'https:'],
|
||||
}).nullish;
|
||||
|
||||
export const embedAuthorPredicate = s.object({
|
||||
name: authorNamePredicate,
|
||||
iconURL: imageURLPredicate,
|
||||
url: urlPredicate,
|
||||
});
|
||||
|
||||
export const RGBPredicate = s.number.int.ge(0).le(255);
|
||||
export const colorPredicate = s.number.int
|
||||
.ge(0)
|
||||
@@ -41,6 +47,11 @@ export const descriptionPredicate = s.string.lengthGe(1).lengthLe(4096).nullable
|
||||
|
||||
export const footerTextPredicate = s.string.lengthGe(1).lengthLe(2048).nullable;
|
||||
|
||||
export const embedFooterPredicate = s.object({
|
||||
text: footerTextPredicate,
|
||||
iconURL: imageURLPredicate,
|
||||
});
|
||||
|
||||
export const timestampPredicate = s.union(s.number, s.date).nullable;
|
||||
|
||||
export const titlePredicate = fieldNamePredicate.nullable;
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import type { APIEmbedField } from 'discord-api-types/v10';
|
||||
import {
|
||||
authorNamePredicate,
|
||||
colorPredicate,
|
||||
descriptionPredicate,
|
||||
embedAuthorPredicate,
|
||||
embedFieldsArrayPredicate,
|
||||
footerTextPredicate,
|
||||
embedFooterPredicate,
|
||||
imageURLPredicate,
|
||||
timestampPredicate,
|
||||
titlePredicate,
|
||||
@@ -39,9 +39,7 @@ export class EmbedBuilder extends UnsafeEmbedBuilder {
|
||||
}
|
||||
|
||||
// Data assertions
|
||||
authorNamePredicate.parse(options.name);
|
||||
urlPredicate.parse(options.iconURL);
|
||||
urlPredicate.parse(options.url);
|
||||
embedAuthorPredicate.parse(options);
|
||||
|
||||
return super.setAuthor(options);
|
||||
}
|
||||
@@ -62,8 +60,7 @@ export class EmbedBuilder extends UnsafeEmbedBuilder {
|
||||
}
|
||||
|
||||
// Data assertions
|
||||
footerTextPredicate.parse(options.text);
|
||||
urlPredicate.parse(options.iconURL);
|
||||
embedFooterPredicate.parse(options);
|
||||
|
||||
return super.setFooter(options);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user