Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
USERSATOSHI committed Aug 4, 2023
1 parent d0b127c commit 6249b09
Show file tree
Hide file tree
Showing 11 changed files with 1,088 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ export * from "./utils/api.js";
export * from "./utils/constants.js";

import Websocket from "./websocket/index.js";
import * as Builders from "./plugins/builders/index.js";

export { Client, request, QueueManager, EventManager, Group, createCacheManager, Websocket }
export { Client, request, QueueManager, EventManager, Group, createCacheManager, Websocket, Builders }
Empty file.
51 changes: 51 additions & 0 deletions src/plugins/builders/Attachment.ts
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;
}
}
87 changes: 87 additions & 0 deletions src/plugins/builders/Embed.ts
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;
}
}
}
Loading

0 comments on commit 6249b09

Please sign in to comment.