harmony/src/structures/embed.ts

148 lines
2.8 KiB
TypeScript
Raw Normal View History

import {
EmbedAuthor,
EmbedField,
EmbedFooter,
EmbedImage,
EmbedPayload,
EmbedProvider,
EmbedThumbnail,
EmbedTypes,
EmbedVideo
2020-10-31 12:33:34 +00:00
} from '../types/channel.ts'
export class Embed {
title?: string
type?: EmbedTypes
description?: string
url?: string
timestamp?: string
color?: number
footer?: EmbedFooter
image?: EmbedImage
thumbnail?: EmbedThumbnail
video?: EmbedVideo
provider?: EmbedProvider
author?: EmbedAuthor
fields?: EmbedField[]
2020-12-02 12:29:52 +00:00
constructor(data?: EmbedPayload) {
this.title = data?.title
this.type = data?.type
this.description = data?.description
this.url = data?.url
this.timestamp = data?.timestamp
this.color = data?.color
this.footer = data?.footer
this.image = data?.image
this.thumbnail = data?.thumbnail
this.video = data?.video
this.provider = data?.provider
this.author = data?.author
this.fields = data?.fields
}
// khk4912
2020-12-02 12:29:52 +00:00
toJSON(): EmbedPayload {
return {
title: this.title,
type: this.type,
description: this.description,
url: this.url,
timestamp: this.timestamp,
color: this.color,
footer: this.footer,
image: this.image,
thumbnail: this.thumbnail,
video: this.video,
provider: this.provider,
author: this.author,
fields: this.fields
}
}
2020-12-02 12:29:52 +00:00
setTitle(title: string): Embed {
this.title = title
return this
}
2020-12-02 12:29:52 +00:00
setDescription(description: string): Embed {
this.description = description
return this
}
2020-12-02 12:29:52 +00:00
setType(type: EmbedTypes): Embed {
this.type = type
return this
}
2020-12-02 12:29:52 +00:00
setURL(url: string): Embed {
this.url = url
return this
}
2020-12-02 12:29:52 +00:00
setTimestamp(timestamp: string): Embed {
this.timestamp = timestamp
return this
}
2020-12-02 12:29:52 +00:00
setColor(hex: number): Embed {
this.color = hex
return this
}
2020-12-02 12:29:52 +00:00
setFooter(footer: EmbedFooter): Embed {
this.footer = footer
return this
}
2020-12-02 12:29:52 +00:00
setImage(image: EmbedImage): Embed {
this.image = image
return this
}
2020-12-02 12:29:52 +00:00
setThumbnail(thumbnail: EmbedThumbnail): Embed {
this.thumbnail = thumbnail
return this
}
2020-12-02 12:29:52 +00:00
setVideo(video: EmbedVideo): Embed {
this.video = video
return this
}
2020-12-02 12:29:52 +00:00
setProvider(provider: EmbedProvider): Embed {
this.provider = provider
return this
}
2020-12-02 12:29:52 +00:00
setAuthor(author: EmbedAuthor): Embed {
this.author = author
return this
}
2020-12-02 12:29:52 +00:00
setFields(fields: EmbedField[]): Embed {
this.fields = fields
return this
}
2020-12-02 12:29:52 +00:00
addField(name: string, value: string, inline?: boolean): Embed {
if (this.fields === undefined) {
this.fields = [
{
name: name,
value: value,
inline: inline
}
]
} else {
this.fields.push({
name: name,
value: value,
inline: inline
})
}
return this
}
}