guilded.ts
Version:
A powerful NPM module that allows you to easily interact with the Guilded API.
80 lines • 2.58 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.UserType = exports.ClientUser = exports.User = void 0;
const guilded_api_typings_1 = require("guilded-api-typings");
Object.defineProperty(exports, "UserType", { enumerable: true, get: function () { return guilded_api_typings_1.UserType; } });
const Base_1 = require("./Base");
/**
* Represents a user on Guilded.
* @example new User(client, rawUser);
*/
class User extends Base_1.Base {
raw;
/** The type of the user. */
type;
/** The name of the user. */
name;
/** The avatar of the user. */
avatar;
/** The banner of the user. */
banner;
/** The date the user was created. */
createdAt;
/**
* @param client The client the user belongs to.
* @param raw The raw data of the user.
* @param cache Whether to cache the user.
*/
constructor(client, raw, cache = client.options.cacheUsers ?? true) {
super(client, raw.id);
this.raw = raw;
this.type = raw.type;
this.name = raw.name;
this.avatar = raw.avatar;
this.banner = 'banner' in raw ? raw.banner : undefined;
this.createdAt = 'createdAt' in raw ? new Date(raw.createdAt) : undefined;
if (cache)
client.users.cache.set(this.id, this);
}
/** Whether the user is cached. */
get isCached() {
return this.client.users.cache.has(this.id);
}
/** The timestamp the user was created. */
get createdTimestamp() {
return this.createdAt?.getTime();
}
/** Whether the user is a bot. */
get isBot() {
return this.type === guilded_api_typings_1.UserType.Bot;
}
/** Whether the user is a human. */
get isUser() {
return !this.type || this.type === guilded_api_typings_1.UserType.User;
}
}
exports.User = User;
/**
* Represents a client user.
* @example new ClientUser(client, rawUser);
*/
class ClientUser extends User {
raw;
/** The bot ID of the client user. */
botId;
/** The ID of the user that created the client user. */
createdBy;
/**
* @param client The client the user belongs to.
* @param raw The raw data of the client user.
* @param cache Whether to cache the client user.
*/
constructor(client, raw, cache) {
super(client, { type: guilded_api_typings_1.UserType.Bot, ...raw }, cache);
this.raw = raw;
this.botId = raw.botId;
this.createdBy = raw.createdBy;
}
}
exports.ClientUser = ClientUser;
//# sourceMappingURL=User.js.map