guilded.ts
Version:
A powerful NPM module that allows you to easily interact with the Guilded API.
75 lines • 3.4 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.CalendarEventManager = void 0;
const collection_1 = require("@discordjs/collection");
const CalendarEvent_1 = require("../../structures/calendarEvent/CalendarEvent");
const BaseManager_1 = require("../BaseManager");
/**
* The manager of calendar events that belong to a calendar channel.
* @example new CalendarEventManager(channel);
*/
class CalendarEventManager extends BaseManager_1.BaseManager {
channel;
/** @param channel The calendar channel the events belong to. */
constructor(channel) {
super(channel.client, channel.client.options.maxCalendarEventCache);
this.channel = channel;
}
fetch(arg1, arg2) {
if (typeof arg1 === 'number' || arg1 instanceof CalendarEvent_1.CalendarEvent)
return this.fetchSingle(arg1, arg2);
return this.fetchMany(arg1);
}
/** @ignore */
async fetchSingle(calendarEvent, options) {
calendarEvent = calendarEvent instanceof CalendarEvent_1.CalendarEvent ? calendarEvent.id : calendarEvent;
const cached = this.cache.get(calendarEvent);
if (cached && !options?.force)
return cached;
const raw = await this.client.api.calendarEvents.fetch(this.channel.id, calendarEvent);
return new CalendarEvent_1.CalendarEvent(this.channel, raw, options?.cache);
}
/** @ignore */
async fetchMany(options) {
const raw = await this.client.api.calendarEvents.fetch(this.channel.id, options);
const calendarEvents = new collection_1.Collection();
for (const data of raw) {
const calendarEvent = new CalendarEvent_1.CalendarEvent(this.channel, data, options?.cache);
calendarEvents.set(data.id, calendarEvent);
}
return calendarEvents;
}
/**
* Create a calendar event in the channel.
* @param payload The payload of the calendar event.
* @returns The created calendar event.
* @example calanderEvents.create({ name: 'Event!' });
*/
async create(payload) {
const raw = await this.client.api.calendarEvents.create(this.channel.id, payload);
return new CalendarEvent_1.CalendarEvent(this.channel, raw);
}
/**
* Edit a calendar event in the channel.
* @param calendarEvent The calendar event to edit.
* @param payload The payload of the calendar event.
* @returns The edited calendar event.
* @example calanderEvents.edit(calendarEvent, { name: 'Event!' });
*/
async edit(calendarEvent, payload) {
calendarEvent = calendarEvent instanceof CalendarEvent_1.CalendarEvent ? calendarEvent.id : calendarEvent;
const raw = await this.client.api.calendarEvents.edit(this.channel.id, calendarEvent, payload);
return new CalendarEvent_1.CalendarEvent(this.channel, raw);
}
/**
* Delete a calendar event from the channel.
* @param calendarEvent The calendar event to delete.
* @example calanderEvents.delete(calendarEvent);
*/
delete(calendarEvent) {
calendarEvent = calendarEvent instanceof CalendarEvent_1.CalendarEvent ? calendarEvent.id : calendarEvent;
return this.client.api.calendarEvents.delete(this.channel.id, calendarEvent);
}
}
exports.CalendarEventManager = CalendarEventManager;
//# sourceMappingURL=CalendarEventManager.js.map