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:
Ryan Munro
2022-04-19 23:58:47 +10:00
committed by GitHub
parent 440ac243ca
commit ec8d87f932
2 changed files with 15 additions and 7 deletions

View File

@@ -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;

View File

@@ -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);
}