mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-15 02:53: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:'],
|
allowedProtocols: ['http:', 'https:'],
|
||||||
}).nullish;
|
}).nullish;
|
||||||
|
|
||||||
|
export const embedAuthorPredicate = s.object({
|
||||||
|
name: authorNamePredicate,
|
||||||
|
iconURL: imageURLPredicate,
|
||||||
|
url: urlPredicate,
|
||||||
|
});
|
||||||
|
|
||||||
export const RGBPredicate = s.number.int.ge(0).le(255);
|
export const RGBPredicate = s.number.int.ge(0).le(255);
|
||||||
export const colorPredicate = s.number.int
|
export const colorPredicate = s.number.int
|
||||||
.ge(0)
|
.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 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 timestampPredicate = s.union(s.number, s.date).nullable;
|
||||||
|
|
||||||
export const titlePredicate = fieldNamePredicate.nullable;
|
export const titlePredicate = fieldNamePredicate.nullable;
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import type { APIEmbedField } from 'discord-api-types/v10';
|
import type { APIEmbedField } from 'discord-api-types/v10';
|
||||||
import {
|
import {
|
||||||
authorNamePredicate,
|
|
||||||
colorPredicate,
|
colorPredicate,
|
||||||
descriptionPredicate,
|
descriptionPredicate,
|
||||||
|
embedAuthorPredicate,
|
||||||
embedFieldsArrayPredicate,
|
embedFieldsArrayPredicate,
|
||||||
footerTextPredicate,
|
embedFooterPredicate,
|
||||||
imageURLPredicate,
|
imageURLPredicate,
|
||||||
timestampPredicate,
|
timestampPredicate,
|
||||||
titlePredicate,
|
titlePredicate,
|
||||||
@@ -39,9 +39,7 @@ export class EmbedBuilder extends UnsafeEmbedBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Data assertions
|
// Data assertions
|
||||||
authorNamePredicate.parse(options.name);
|
embedAuthorPredicate.parse(options);
|
||||||
urlPredicate.parse(options.iconURL);
|
|
||||||
urlPredicate.parse(options.url);
|
|
||||||
|
|
||||||
return super.setAuthor(options);
|
return super.setAuthor(options);
|
||||||
}
|
}
|
||||||
@@ -62,8 +60,7 @@ export class EmbedBuilder extends UnsafeEmbedBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Data assertions
|
// Data assertions
|
||||||
footerTextPredicate.parse(options.text);
|
embedFooterPredicate.parse(options);
|
||||||
urlPredicate.parse(options.iconURL);
|
|
||||||
|
|
||||||
return super.setFooter(options);
|
return super.setFooter(options);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user