@lilybird/transformers
Version:
Event transformers and more for lilybird
127 lines (126 loc) • 4.34 kB
JavaScript
import { GuildMember } from "./guild-member.js";
import { channelFactory } from "./channel.js";
export function guildFactory(client, guild) {
if ("joined_at" in guild)
return new NewGuild(client, guild);
if ("unavailable" in guild)
return guild;
return new Guild(client, guild);
}
export class Guild {
id;
name;
icon;
iconHash;
splash;
discoverySplash;
owner;
ownerId;
permissions;
afkChannelId;
afkTimeout;
widgetEnabled;
widgetChannelId;
verificationLevel;
defaultMessageNotifications;
explicitContentFilter;
roles;
emojis;
features;
mfaLevel;
applicationId;
systemChannelId;
systemChannelFlags;
rulesChannelId;
maxPresences;
maxMembers;
vanityUrlCode;
description;
banner;
premiumTier;
premiumSubscriptionCount;
preferredLocale;
publicUpdatesChannelId;
maxVideoChannelUsers;
maxStageVideoChannelUsers;
approximateMemberCount;
approximatePresenceCount;
welcomeScreen;
nsfwLevel;
stickers;
premiumProgressBarEnabled;
safetyAlertsChannelId;
client;
constructor(client, guild) {
this.client = client;
this.id = guild.id;
this.name = guild.name;
this.icon = guild.icon;
this.iconHash = guild.icon_hash;
this.splash = guild.splash;
this.discoverySplash = guild.discovery_splash;
this.owner = guild.owner;
this.ownerId = guild.owner_id;
this.permissions = guild.permissions;
this.afkChannelId = guild.afk_channel_id;
this.afkTimeout = guild.afk_timeout;
this.widgetEnabled = guild.widget_enabled;
this.widgetChannelId = guild.widget_channel_id;
this.verificationLevel = guild.verification_level;
this.defaultMessageNotifications = guild.default_message_notifications;
this.explicitContentFilter = guild.explicit_content_filter;
this.roles = guild.roles;
this.emojis = guild.emojis;
this.features = guild.features;
this.mfaLevel = guild.mfa_level;
this.applicationId = guild.application_id;
this.systemChannelId = guild.system_channel_id;
this.systemChannelFlags = guild.system_channel_flags;
this.rulesChannelId = guild.rules_channel_id;
this.maxPresences = guild.max_presences;
this.maxMembers = guild.max_members;
this.vanityUrlCode = guild.vanity_url_code;
this.description = guild.description;
this.banner = guild.banner;
this.premiumTier = guild.premium_tier;
this.premiumSubscriptionCount = guild.premium_subscription_count ?? 0;
this.preferredLocale = guild.preferred_locale;
this.publicUpdatesChannelId = guild.public_updates_channel_id;
this.maxVideoChannelUsers = guild.max_video_channel_users;
this.maxStageVideoChannelUsers = guild.max_stage_video_channel_users;
this.approximateMemberCount = guild.approximate_member_count;
this.approximatePresenceCount = guild.approximate_presence_count;
this.welcomeScreen = guild.welcome_screen;
this.nsfwLevel = guild.nsfw_level;
this.stickers = guild.stickers ?? [];
this.premiumProgressBarEnabled = guild.premium_progress_bar_enabled;
this.safetyAlertsChannelId = guild.safety_alerts_channel_id;
}
}
export class NewGuild extends Guild {
joinedAt;
large;
unavailable;
memberCount;
voiceStates;
members;
channels;
threads;
presences;
stageInstances;
guildScheduledEvents;
constructor(client, guild) {
super(client, guild);
this.joinedAt = guild.joined_at;
this.large = guild.large;
this.unavailable = guild.unavailable ?? false;
this.memberCount = guild.member_count;
this.voiceStates = guild.voice_states;
this.members = guild.members.map((member) => new GuildMember(client, member));
this.channels = guild.channels.map((channel) => channelFactory(client, channel));
this.threads = guild.threads.map((channel) => channelFactory(client, channel));
this.presences = guild.presences;
this.stageInstances = guild.stage_instances;
this.guildScheduledEvents = guild.guild_scheduled_events;
}
}