guilded.ts
Version:
A powerful NPM module that allows you to easily interact with the Guilded API.
150 lines • 5.1 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CalendarEvent = void 0;
const CalendarEventRsvpManager_1 = require("../../managers/calendarEvent/CalendarEventRsvpManager");
const Base_1 = require("../Base");
/**
* Represents a calendar event on Guilded.
* @example new CalendarEvent(channel, rawEvent);
*/
class CalendarEvent extends Base_1.Base {
channel;
raw;
/** The ID of the server the calendar event belongs to. */
serverId;
/** The ID of the channel the calendar event belongs to. */
channelId;
/** The name of the calendar event. */
name;
/** The description of the calendar event. */
description;
/** The location of the calendar event. */
location;
/** The url of the calendar event. */
url;
/** The color of the calendar event. */
color;
/** The limit of RSVPs of the calendar event. */
rsvpLimit;
/** The date the calendar event starts. */
startsAt;
/** The duration of the calendar event. */
duration;
/** Whether the calendar event is private. */
isPrivate;
/** The mentions of the calendar event. */
mentions;
/** The date the calendar event was created. */
createdAt;
/** The ID of the user that created the calendar event. */
createdBy;
/** The cancellation of the calendar event. */
cancellation;
/** A manager of RSVPs that belong to the calendar event. */
rsvps;
/**
* @param channel The calendar channel the event belongs to.
* @param raw The raw data of the calendar event.
* @param cache Whether to cache the calendar event.
*/
constructor(channel, raw, cache = channel.client.options.cacheCalendarEvents ?? true) {
super(channel.client, raw.id);
this.channel = channel;
this.raw = raw;
this.rsvps = new CalendarEventRsvpManager_1.CalendarEventRsvpManager(this);
this.serverId = raw.serverId;
this.channelId = raw.channelId;
this.name = raw.name;
this.description = raw.description;
this.location = raw.location;
this.url = raw.url;
this.color = raw.color;
this.rsvpLimit = raw.rsvpLimit;
this.startsAt = new Date(raw.startsAt);
this.duration = raw.duration;
this.isPrivate = raw.isPrivate;
this.mentions = raw.mentions;
this.createdAt = new Date(raw.createdAt);
this.createdBy = raw.createdBy;
this.cancellation = raw.cancellation;
if (cache)
channel.events.cache.set(this.id, this);
}
/** Whether the calendar event is cached. */
get isCached() {
return this.channel.events.cache.has(this.id);
}
/** The server the calendar event belongs to. */
get server() {
return this.channel.server;
}
/** The time until the calendar event starts. */
get startsIn() {
const startsIn = this.startsAt.getTime() - Date.now();
return startsIn > 0 ? startsIn : 0;
}
/** The date the calendar event ends. */
get endsAt() {
return new Date(this.startsAt.getTime() + (this.duration ?? 0) * 1000);
}
/** The timestamp the calendar event was created. */
get createdTimestamp() {
return this.createdAt.getTime();
}
/** The server member that created the calendar event. */
get author() {
return this.server?.members.cache.get(this.createdBy);
}
/** The ID of the user that created the calendar event. */
get authorId() {
return this.createdBy;
}
/**
* Fetch the calendar event.
* @param options The options to fetch the calendar event with.
* @returns The fetched calendar event.
* @example event.fetch();
*/
fetch(options) {
return this.channel.events.fetch(this, options);
}
/**
* Fetch the server the calendar event belongs to.
* @param options The options to fetch the server with.
* @returns The fetched server.
* @example event.fetchServer();
*/
fetchServer(options) {
return this.channel.fetchServer(options);
}
/**
* Fetch the server member that created the calendar event.
* @param options The options to fetch the server member with.
* @returns The fetched server member.
* @example event.fetchAuthor();
*/
async fetchAuthor(options) {
const server = await this.fetchServer();
return server.members.fetch(this.createdBy, options);
}
/**
* Edit the calendar event.
* @param payload The payload of the calendar event.
* @returns The edited calendar event.
* @example event.edit({ name: 'New name' });
*/
edit(payload) {
return this.channel.events.edit(this, payload);
}
/**
* Delete the calendar event.
* @returns The deleted calendar event.
* @example event.delete();
*/
async delete() {
await this.channel.events.delete(this);
return this;
}
}
exports.CalendarEvent = CalendarEvent;
//# sourceMappingURL=CalendarEvent.js.map