feat(RichEmbed): backport spliceFields and normalizeField (#3762)

* backport: RichEmbed#checkField, Util#resolveString

* backport: RichEmbed#spliceFields

* fix: typo

* chore: use util.resolveString everywhere

* chore: rename EmbedFIeld to EmbedFieldData

* consistency with v12

* chore: rename checkField to normalizeField

* consistency with v12

* fix: EmbedField instead of EmbedFieldData

* fix(typings): EmbedFIeld#inline is guaranteed

* fix(docs): add JSDocs typedef for EmbedFieldData

* fix(typings): EmbedFIeldData#name/#value

* should be StringResolvable

* refactor(RichEmbed): do not duplicate field prop checking

* docs(RichEmbed): document default for inline

* fix(RichEmbed): pass correct parameters to normalizeField

* typings(RichEmbed): add missing spaces

Co-authored-by: SpaceEEC <spaceeec@yahoo.com>
This commit is contained in:
Souji
2020-02-28 18:16:19 +01:00
committed by GitHub
parent cf646b5394
commit 6eaf63fb7c
4 changed files with 89 additions and 17 deletions

15
typings/index.d.ts vendored
View File

@@ -234,6 +234,7 @@ declare module 'discord.js' {
public resolveChannel(channel: ChannelResolvable): Channel;
public resolveChannelID(channel: ChannelResolvable): Snowflake;
public resolveColor(color: ColorResolvable): number;
public resolveString(data: StringResolvable): string;
public resolveEmojiIdentifier(emoji: EmojiIdentifierResolvable): string;
public resolveFile(resource: BufferResolvable | Stream): Promise<Buffer>;
public resolveGuild(guild: GuildResolvable): Guild;
@@ -1111,6 +1112,12 @@ declare module 'discord.js' {
public push(request: object): void;
}
interface EmbedField {
name: string;
value: string;
inline: boolean;
}
export class RichEmbed {
constructor(data?: RichEmbedOptions | MessageEmbed);
private _apiTransform(): object;
@@ -1129,6 +1136,7 @@ declare module 'discord.js' {
public title?: string;
public url?: string;
public addBlankField(inline?: boolean): this;
public spliceFields(index: number, deleteCount: number, ...fields: EmbedFieldData[]): this;
public addField(name: StringResolvable, value: StringResolvable, inline?: boolean): this;
public attachFile(file: Attachment | FileOptions | string): this;
public attachFiles(file: Array<Attachment | FileOptions | string>): this;
@@ -1141,6 +1149,7 @@ declare module 'discord.js' {
public setTimestamp(timestamp?: Date | number): this;
public setTitle(title: StringResolvable): this;
public setURL(url: string): this;
public static normalizeField(name: StringResolvable, value: StringResolvable, inline?: boolean): EmbedField;
}
export class RichPresenceAssets {
@@ -2261,6 +2270,12 @@ declare module 'discord.js' {
interface RecursiveArray<T> extends Array<T | RecursiveArray<T>> { }
interface EmbedFieldData {
name: StringResolvable;
value: StringResolvable;
inline?: boolean;
}
type PermissionResolvable = BitFieldResolvable<PermissionString>
type PremiumTier = number;