mirror of
https://github.com/tiramisulabs/seyfert.git
synced 2025-07-03 05:26:07 +00:00
64 lines
1.8 KiB
TypeScript
64 lines
1.8 KiB
TypeScript
import type { Model } from "../Base.ts";
|
|
import type { Session } from "../../session/Session.ts";
|
|
import type { DiscordGuild } from "../../vendor/external.ts";
|
|
import type { ImageFormat, ImageSize } from "../../util/shared/images.ts";
|
|
import { formatImageURL } from "../../util/shared/images.ts";
|
|
import { iconBigintToHash, iconHashToBigInt } from "../../util/hash.ts";
|
|
import { GuildFeatures } from "../../vendor/external.ts";
|
|
import { Snowflake } from "../../util/Snowflake.ts";
|
|
import * as Routes from "../../util/Routes.ts";
|
|
|
|
/**
|
|
* Class for {@link Guild} and {@link AnonymousGuild}
|
|
*/
|
|
export abstract class BaseGuild implements Model {
|
|
constructor(session: Session, data: DiscordGuild) {
|
|
this.session = session;
|
|
this.id = data.id;
|
|
|
|
this.name = data.name;
|
|
this.iconHash = data.icon ? iconHashToBigInt(data.icon) : undefined;
|
|
|
|
this.features = data.features;
|
|
}
|
|
|
|
readonly session: Session;
|
|
readonly id: Snowflake;
|
|
|
|
name: string;
|
|
iconHash?: bigint;
|
|
features: GuildFeatures[];
|
|
|
|
get createdTimestamp() {
|
|
return Snowflake.snowflakeToTimestamp(this.id);
|
|
}
|
|
|
|
get createdAt() {
|
|
return new Date(this.createdTimestamp);
|
|
}
|
|
|
|
get partnered() {
|
|
return this.features.includes(GuildFeatures.Partnered);
|
|
}
|
|
|
|
get verified() {
|
|
return this.features.includes(GuildFeatures.Verified);
|
|
}
|
|
|
|
iconURL(options: { size?: ImageSize; format?: ImageFormat } = { size: 128 }) {
|
|
if (this.iconHash) {
|
|
return formatImageURL(
|
|
Routes.GUILD_BANNER(this.id, iconBigintToHash(this.iconHash)),
|
|
options.size,
|
|
options.format,
|
|
);
|
|
}
|
|
}
|
|
|
|
toString() {
|
|
return this.name;
|
|
}
|
|
}
|
|
|
|
export default BaseGuild;
|