guilded.ts
Version:
A powerful NPM module that allows you to easily interact with the Guilded API.
163 lines • 5.68 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ServerType = exports.Server = void 0;
const guilded_api_typings_1 = require("guilded-api-typings");
Object.defineProperty(exports, "ServerType", { enumerable: true, get: function () { return guilded_api_typings_1.ServerType; } });
const Base_1 = require("../Base");
const ServerMemberManager_1 = require("../../managers/server/ServerMemberManager");
const ServerBanManager_1 = require("../../managers/server/ServerBanManager");
const ServerRoleManager_1 = require("../../managers/server/ServerRoleManager");
/**
* Represents a server on Guilded.
* @example new Server(client, rawServer);
*/
class Server extends Base_1.Base {
raw;
/** The ID of the user the server belongs to. */
ownerId;
/** The type of the server. */
type;
/** The name of the server. */
name;
/** The vanity URL of the server. */
url;
/** The description of the server. */
about;
/** The avatar of the server. */
avatar;
/** The banner of the server. */
banner;
/** The timezone of the server. */
timezone;
/** Whether the server is verified. */
isVerified;
/** The ID of the server's default channel. */
defaultChannelId;
/** The date the server was created. */
createdAt;
/** The manager of members that belong to the server. */
members;
/** The manager of bans that belong to the server. */
bans;
/** The manager of roles that belong to the server. */
roles;
/**
* @param client The client the server belongs to.
* @param raw The raw data of the server.
* @param cache Whether to cache the server.
*/
constructor(client, raw, cache = client.options.cacheServers ?? true) {
super(client, raw.id);
this.raw = raw;
this.ownerId = raw.ownerId;
this.type = raw.type;
this.name = raw.name;
this.url = raw.url;
this.about = raw.about;
this.avatar = raw.avatar;
this.banner = raw.banner;
this.timezone = raw.timezone;
this.isVerified = raw.isVerified;
this.defaultChannelId = raw.defaultChannelId;
this.createdAt = new Date(raw.createdAt);
this.members = new ServerMemberManager_1.ServerMemberManager(this);
this.bans = new ServerBanManager_1.ServerBanManager(this);
this.roles = new ServerRoleManager_1.ServerRoleManager(this);
if (cache)
client.servers.cache.set(this.id, this);
}
/** Whether the server is cached. */
get isCached() {
return this.client.servers.cache.has(this.id);
}
/** The server member the server belongs to. */
get owner() {
return this.members.cache.get(this.ownerId);
}
/** Whether the server is a team server. */
get isTeam() {
return this.type === guilded_api_typings_1.ServerType.Team;
}
/** Whether the server is a organization server. */
get isOrganization() {
return this.type === guilded_api_typings_1.ServerType.Organization;
}
/** Whether the server is a community server. */
get isCommunity() {
return this.type === guilded_api_typings_1.ServerType.Community;
}
/** Whether the server is a clan server. */
get isClan() {
return this.type === guilded_api_typings_1.ServerType.Clan;
}
/** Whether the server is a guild server. */
get isGuild() {
return this.type === guilded_api_typings_1.ServerType.Guild;
}
/** Whether the server is a friends server. */
get isFriends() {
return this.type === guilded_api_typings_1.ServerType.Friends;
}
/** Whether the server is a streaming server. */
get isStreaming() {
return this.type === guilded_api_typings_1.ServerType.Streaming;
}
/** Whether the server is a other type. */
get isOther() {
return this.type === guilded_api_typings_1.ServerType.Other;
}
/** The server's default channel. */
get defaultChannel() {
return this.defaultChannelId
? this.client.channels.cache.get(this.defaultChannelId)
: undefined;
}
/**
* Fetch the server.
* @param options The options to fetch the server with.
* @returns The fetched server.
* @example server.fetch();
*/
fetch(options) {
return this.client.servers.fetch(this, options);
}
/**
* Fetch the server member the server belongs to.
* @param options The options to fetch the server member with.
* @returns The fetched server member.
* @example server.fetchOwner();
*/
fetchOwner(options) {
return this.members.fetch(this.ownerId, options);
}
/**
* Fetch the server's default channel.
* @param options The options to fetch the channel with.
* @returns The fetched channel.
* @example server.fetchDefaultChannel();
*/
fetchDefaultChannel(options) {
return this.defaultChannelId
? this.client.channels.fetch(this.defaultChannelId, options)
: undefined;
}
/**
* Create a channel in the server.
* @param payload The payload of the channel.
* @returns The created channel.
* @example server.createChannel({ name: 'Chat', type: 'chat' });
*/
createChannel(payload) {
return this.client.channels.create({ serverId: this.id, ...payload });
}
/**
* Leave the server.
* @returns The server.
* @example server.leave();
*/
leave() {
return this.members.kick(this.client.user.id);
}
}
exports.Server = Server;
//# sourceMappingURL=Server.js.map