mirror of
https://github.com/tiramisulabs/seyfert.git
synced 2025-07-03 05:26:07 +00:00
56 lines
2.1 KiB
TypeScript
56 lines
2.1 KiB
TypeScript
import type { Model } from "./Base.ts";
|
|
import type { Session } from "../session/Session.ts";
|
|
import type { DiscordGuild, GuildNsfwLevel, VerificationLevels } from "../vendor/external.ts";
|
|
import type { ImageFormat, ImageSize } from "../util/shared/images.ts";
|
|
import { iconBigintToHash, iconHashToBigInt } from "../util/hash.ts";
|
|
import { formatImageUrl } from "../util/shared/images.ts";
|
|
import BaseGuild from "./BaseGuild.ts";
|
|
import * as Routes from "../util/Routes.ts";
|
|
|
|
export class AnonymousGuild extends BaseGuild implements Model {
|
|
constructor(session: Session, data: Partial<DiscordGuild>); // TODO: Improve this type (name and id are required)
|
|
constructor(session: Session, data: DiscordGuild) {
|
|
super(session, data);
|
|
|
|
this.splashHash = data.splash ? iconHashToBigInt(data.splash) : undefined;
|
|
this.bannerHash = data.banner ? iconHashToBigInt(data.banner) : undefined;
|
|
|
|
this.verificationLevel = data.verification_level;
|
|
this.vanityUrlCode = data.vanity_url_code ? data.vanity_url_code : undefined;
|
|
this.nsfwLevel = data.nsfw_level;
|
|
this.description = data.description ? data.description : undefined;
|
|
this.premiumSubscriptionCount = data.premium_subscription_count;
|
|
}
|
|
|
|
splashHash?: bigint;
|
|
bannerHash?: bigint;
|
|
|
|
verificationLevel: VerificationLevels;
|
|
vanityUrlCode?: string;
|
|
nsfwLevel: GuildNsfwLevel;
|
|
description?: string;
|
|
premiumSubscriptionCount?: number;
|
|
|
|
splashUrl(options: { size?: ImageSize; format?: ImageFormat } = { size: 128 }) {
|
|
if (this.splashHash) {
|
|
return formatImageUrl(
|
|
Routes.GUILD_SPLASH(this.id, iconBigintToHash(this.splashHash)),
|
|
options.size,
|
|
options.format,
|
|
);
|
|
}
|
|
}
|
|
|
|
bannerUrl(options: { size?: ImageSize; format?: ImageFormat } = { size: 128 }) {
|
|
if (this.bannerHash) {
|
|
return formatImageUrl(
|
|
Routes.GUILD_BANNER(this.id, iconBigintToHash(this.bannerHash)),
|
|
options.size,
|
|
options.format,
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
export default AnonymousGuild;
|