mirror of
https://github.com/tiramisulabs/seyfert.git
synced 2025-07-03 05:26:07 +00:00
feat: embeds
This commit is contained in:
parent
58b98719b4
commit
fbfeecf8c5
2
mod.ts
2
mod.ts
@ -33,6 +33,8 @@ export * from "./structures/guilds/BaseGuild.ts";
|
|||||||
export * from "./structures/guilds/Guild.ts";
|
export * from "./structures/guilds/Guild.ts";
|
||||||
export * from "./structures/guilds/InviteGuild.ts";
|
export * from "./structures/guilds/InviteGuild.ts";
|
||||||
|
|
||||||
|
export * from "./structures/builders/EmbedBuilder.ts";
|
||||||
|
|
||||||
export * from "./structures/interactions/Interaction.ts";
|
export * from "./structures/interactions/Interaction.ts";
|
||||||
|
|
||||||
export * from "./session/Session.ts";
|
export * from "./session/Session.ts";
|
||||||
|
@ -14,7 +14,7 @@ import { MessageFlags } from "../util/shared/flags.ts";
|
|||||||
import User from "./User.ts";
|
import User from "./User.ts";
|
||||||
import Member from "./Member.ts";
|
import Member from "./Member.ts";
|
||||||
import Attachment from "./Attachment.ts";
|
import Attachment from "./Attachment.ts";
|
||||||
import BaseComponent from "./components/Component.ts";
|
import ComponentFactory from "./components/ComponentFactory.ts";
|
||||||
import * as Routes from "../util/Routes.ts";
|
import * as Routes from "../util/Routes.ts";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -83,7 +83,7 @@ export class Message implements Model {
|
|||||||
this.member = new Member(session, { ...data.member, user: data.author }, data.guild_id);
|
this.member = new Member(session, { ...data.member, user: data.author }, data.guild_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.components = data.components?.map((component) => BaseComponent.from(session, component));
|
this.components = data.components?.map((component) => ComponentFactory.from(session, component));
|
||||||
}
|
}
|
||||||
|
|
||||||
readonly session: Session;
|
readonly session: Session;
|
||||||
|
113
structures/builders/EmbedBuilder.ts
Normal file
113
structures/builders/EmbedBuilder.ts
Normal file
@ -0,0 +1,113 @@
|
|||||||
|
import type {
|
||||||
|
DiscordEmbedField,
|
||||||
|
DiscordEmbed,
|
||||||
|
DiscordEmbedProvider
|
||||||
|
} from '../../vendor/external.ts';
|
||||||
|
|
||||||
|
export interface EmbedFooter {
|
||||||
|
text: string;
|
||||||
|
iconUrl?: string;
|
||||||
|
proxyIconUrl?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface EmbedAuthor {
|
||||||
|
name: string
|
||||||
|
text?: string;
|
||||||
|
url?: string;
|
||||||
|
iconUrl?: string;
|
||||||
|
proxyIconUrl?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface EmbedVideo {
|
||||||
|
height?: number;
|
||||||
|
proxyUrl?: string;
|
||||||
|
url?: string;
|
||||||
|
width?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class EmbedBuilder {
|
||||||
|
#data: DiscordEmbed
|
||||||
|
constructor(data: DiscordEmbed = {}) {
|
||||||
|
this.#data = data;
|
||||||
|
if (!this.#data.fields) this.#data.fields = []
|
||||||
|
}
|
||||||
|
|
||||||
|
setAuthor(author: EmbedAuthor) {
|
||||||
|
this.#data.author = {
|
||||||
|
name: author.name,
|
||||||
|
icon_url: author.iconUrl,
|
||||||
|
proxy_icon_url: author.proxyIconUrl,
|
||||||
|
url: author.url
|
||||||
|
};
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
setColor(color: number) {
|
||||||
|
this.#data.color = color;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
setDescription(description: string) {
|
||||||
|
this.#data.description = description;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
addField(field: DiscordEmbedField) {
|
||||||
|
this.#data.fields!.push(field);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
setFooter(footer: EmbedFooter) {
|
||||||
|
this.#data.footer = {
|
||||||
|
text: footer.text,
|
||||||
|
icon_url: footer.iconUrl,
|
||||||
|
proxy_icon_url: footer.proxyIconUrl,
|
||||||
|
};
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
setImage(image: string) {
|
||||||
|
this.#data.image = { url: image };
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
setProvider(provider: DiscordEmbedProvider) {
|
||||||
|
this.#data.provider = provider;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
setThumbnail(thumbnail: string) {
|
||||||
|
this.#data.thumbnail = { url: thumbnail };
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
setTimestamp(timestamp: string | Date) {
|
||||||
|
this.#data.timestamp = timestamp instanceof Date ? timestamp.toISOString() : timestamp;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
setTitle(title: string, url?: string) {
|
||||||
|
this.#data.title = title;
|
||||||
|
if (url) this.setUrl(url);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
setUrl(url: string) {
|
||||||
|
this.#data.url = url;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
setVideo(video: EmbedVideo) {
|
||||||
|
this.#data.video = {
|
||||||
|
height: video.height,
|
||||||
|
proxy_url: video.proxyUrl,
|
||||||
|
url: video.url,
|
||||||
|
width: video.width
|
||||||
|
};
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
toJSON(): DiscordEmbed {
|
||||||
|
return this.#data;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user