-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d0b127c
commit 6249b09
Showing
11 changed files
with
1,088 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { getFileData } from "../../utils/helpers.js"; | ||
|
||
export default class AttachmentBuilder { | ||
name!: string; | ||
data!: any; | ||
description?: string; | ||
spoiler: boolean = false; | ||
file!: Blob; | ||
constructor() { | ||
this.name = "file"; | ||
} | ||
async #getFileData() { | ||
this.file = await getFileData(this.data); | ||
} | ||
|
||
setName(name: string) { | ||
this.name = name; | ||
return this; | ||
} | ||
setDescription(description: string) { | ||
this.description = description; | ||
return this; | ||
} | ||
setSpoiler(spoiler: boolean) { | ||
this.spoiler = spoiler; | ||
return this; | ||
} | ||
setData(data: any) { | ||
this.data = data; | ||
this.#getFileData(); | ||
return this; | ||
} | ||
|
||
static from(data: any): AttachmentBuilder; | ||
static from( | ||
data: any, | ||
options?: { | ||
name: string; | ||
description?: string; | ||
spoiler?: boolean; | ||
}, | ||
): AttachmentBuilder { | ||
const builder = new AttachmentBuilder(); | ||
builder.setData(data); | ||
options?.name && builder.setName(options.name); | ||
options?.description && builder.setDescription(options.description); | ||
options?.spoiler && builder.setSpoiler(options.spoiler); | ||
|
||
return builder; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { parseColor } from "../../index.js"; | ||
import { | ||
EmbedAuthor, | ||
EmbedBuild, | ||
EmbedField, | ||
EmbedFooter, | ||
EmbedImage, | ||
EmbedThumbnail, | ||
} from "./interface.js"; | ||
import { ColorResolve } from "./type.js"; | ||
|
||
export default class EmbedBuilder { | ||
title?: string; | ||
description?: string; | ||
color?: number; | ||
fields: EmbedField[]; | ||
footer?: EmbedFooter; | ||
image?: EmbedImage; | ||
thumbnail?: EmbedThumbnail; | ||
timestamp?: Date; | ||
url?: string; | ||
author?: EmbedAuthor; | ||
constructor() { | ||
this.fields = []; | ||
} | ||
setTitle(title: string) { | ||
this.title = title; | ||
return this; | ||
} | ||
setDescription(description: string) { | ||
this.description = description; | ||
return this; | ||
} | ||
setColor(color: ColorResolve) { | ||
this.color = parseColor(color); | ||
return this; | ||
} | ||
addField(name: string, value: string, inline?: boolean) { | ||
this.fields.push({ name, value, inline }); | ||
return this; | ||
} | ||
addFields(...fields: EmbedField[]) { | ||
this.fields.push(...fields); | ||
return this; | ||
} | ||
setFooter(text: string, iconUrl?: string) { | ||
this.footer = { text, iconUrl }; | ||
return this; | ||
} | ||
setImage(url: string) { | ||
this.image = { url }; | ||
return this; | ||
} | ||
setThumbnail(url: string) { | ||
this.thumbnail = { url }; | ||
return this; | ||
} | ||
setTimestamp(timestamp: Date = new Date()) { | ||
this.timestamp = timestamp; | ||
return this; | ||
} | ||
setURL(url: string) { | ||
this.url = url; | ||
return this; | ||
} | ||
setAuthor(name: string, iconUrl?: string, url?: string) { | ||
this.author = { name, iconUrl, url }; | ||
return this; | ||
} | ||
|
||
static from(data: EmbedBuild | EmbedBuilder): EmbedBuilder { | ||
if (data instanceof EmbedBuilder) return data; | ||
else { | ||
const builder = new EmbedBuilder(); | ||
builder.title = data.title; | ||
builder.description = data.description; | ||
builder.color = data.color ? parseColor(data.color) : undefined; | ||
builder.fields = data.fields; | ||
builder.footer = data.footer; | ||
builder.image = data.image; | ||
builder.thumbnail = data.thumbnail; | ||
builder.timestamp = data.timestamp; | ||
builder.url = data.url; | ||
return builder; | ||
} | ||
} | ||
} |
Oops, something went wrong.