mirror of
https://github.com/tiramisulabs/seyfert.git
synced 2025-07-01 20:46:08 +00:00
feat: attachments
This commit is contained in:
parent
b896c3c188
commit
f247669902
36
structures/Attachment.ts
Normal file
36
structures/Attachment.ts
Normal file
@ -0,0 +1,36 @@
|
||||
import type { Model } from "./Base.ts";
|
||||
import type { Snowflake } from "../util/Snowflake.ts";
|
||||
import type { Session } from "../session/Session.ts";
|
||||
import type { DiscordAttachment } from "../vendor/external.ts";
|
||||
|
||||
/**
|
||||
* Represents an attachment
|
||||
* @link https://discord.com/developers/docs/resources/channel#attachment-object
|
||||
* */
|
||||
export class Attachment implements Model {
|
||||
constructor(session: Session, data: DiscordAttachment) {
|
||||
this.session = session;
|
||||
this.id = data.id;
|
||||
|
||||
this.contentType = data.content_type ? data.content_type : undefined;
|
||||
this.attachment = data.url;
|
||||
this.proxyUrl = data.proxy_url;
|
||||
this.name = data.filename;
|
||||
this.size = data.size;
|
||||
this.height = data.height ? data.height : undefined;
|
||||
this.width = data.width ? data.width : undefined;
|
||||
this.ephemeral = !!data.ephemeral
|
||||
}
|
||||
|
||||
readonly session: Session;
|
||||
readonly id: Snowflake;
|
||||
|
||||
contentType?: string;
|
||||
attachment: string;
|
||||
proxyUrl: string;
|
||||
name: string;
|
||||
size: number;
|
||||
height?: number;
|
||||
width?: number;
|
||||
ephemeral: boolean;
|
||||
}
|
@ -3,6 +3,7 @@ import type { Snowflake } from "../util/Snowflake.ts";
|
||||
import type { Session } from "../session/mod.ts";
|
||||
import type { AllowedMentionsTypes, DiscordMessage } from "../vendor/external.ts";
|
||||
import { User } from "./User.ts";
|
||||
import { Attachment } from "./Attachment.ts";
|
||||
import { MessageFlags, Routes } from "../util/mod.ts";
|
||||
|
||||
/**
|
||||
@ -49,6 +50,8 @@ export class Message implements Model {
|
||||
this.pinned = !!data.pinned;
|
||||
this.tts = !!data.tts;
|
||||
this.content = data.content!;
|
||||
|
||||
this.attachments = data.attachments.map((attachment) => new Attachment(session, attachment));
|
||||
}
|
||||
|
||||
readonly session: Session;
|
||||
@ -62,6 +65,8 @@ export class Message implements Model {
|
||||
tts: boolean;
|
||||
content: string;
|
||||
|
||||
attachments: Attachment[];
|
||||
|
||||
get url() {
|
||||
return `https://discord.com/channels/${this.guildId ?? "@me"}/${this.channelId}/${this.id}`;
|
||||
}
|
||||
|
@ -61,4 +61,8 @@ export class User implements Model {
|
||||
|
||||
return `${url}.${options.format ?? (url.includes("/a_") ? "gif" : "jpg")}?size=${options.size}`;
|
||||
}
|
||||
|
||||
toString() {
|
||||
return `<@${this.id}>`;
|
||||
}
|
||||
}
|
||||
|
@ -3,21 +3,21 @@
|
||||
*/
|
||||
export enum MessageFlags {
|
||||
/** this message has been published to subscribed channels (via Channel Following) */
|
||||
CROSSPOSTED = 1 << 0,
|
||||
CrossPosted = 1 << 0,
|
||||
/** this message originated from a message in another channel (via Channel Following) */
|
||||
IS_CROSSPOST = 1 << 1,
|
||||
IsCrosspost = 1 << 1,
|
||||
/** do not include any embeds when serializing this message */
|
||||
SUPPRESS_EMBEDS = 1 << 2,
|
||||
SupressEmbeds = 1 << 2,
|
||||
/** the source message for this crosspost has been deleted (via Channel Following) */
|
||||
SOURCE_MESSAGE_DELETED = 1 << 3,
|
||||
SourceMessageDeleted = 1 << 3,
|
||||
/** this message came from the urgent message system */
|
||||
URGENT = 1 << 4,
|
||||
Urgent = 1 << 4,
|
||||
/** this message has an associated thread, with the same id as the message */
|
||||
HAS_THREAD = 1 << 5,
|
||||
HasThread = 1 << 5,
|
||||
/** this message is only visible to the user who invoked the Interaction */
|
||||
EPHEMERAL = 1 << 6,
|
||||
Ephemeral = 1 << 6,
|
||||
/** this message is an Interaction Response and the bot is "thinking" */
|
||||
LOADING = 1 << 7,
|
||||
Loading = 1 << 7,
|
||||
/** this message failed to mention some roles and add their members to the thread */
|
||||
FAILED_TO_MENTION_SOME_ROLES_IN_THREAD = 1 << 8,
|
||||
FailedToMentionSomeRolesInThread = 1 << 8,
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user