UNPKG

guilded.ts

Version:

A powerful NPM module that allows you to easily interact with the Guilded API.

90 lines 4.53 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.rsvpDeleted = exports.rsvpsUpdated = exports.rsvpUpdated = exports.deleted = exports.updated = exports.created = void 0; const collection_1 = require("@discordjs/collection"); const CalendarEvent_1 = require("../../structures/calendarEvent/CalendarEvent"); const CalendarEventRsvp_1 = require("../../structures/calendarEvent/CalendarEventRsvp"); /** * Handle the CalendarEventCreated event. * @param client The client the Websocket belongs to. * @param data The data of the event. */ async function created(client, data) { const channel = (await client.channels.fetch(data.calendarEvent.channelId)); const calendarEvent = new CalendarEvent_1.CalendarEvent(channel, data.calendarEvent); client.emit('calendarEventCreate', calendarEvent); } exports.created = created; /** * Handle the CalendarEventUpdated event. * @param client The client the Websocket belongs to. * @param data The data of the event. */ async function updated(client, data) { const channel = (await client.channels.fetch(data.calendarEvent.channelId)); const oldCalendarEvent = channel.events.cache.get(data.calendarEvent.id); const newCalendarEvent = new CalendarEvent_1.CalendarEvent(channel, data.calendarEvent); client.emit('calendarEventEdit', newCalendarEvent, oldCalendarEvent); } exports.updated = updated; /** * Handle the CalendarEventDeleted event. * @param client The client the Websocket belongs to. * @param data The data of the event. */ async function deleted(client, data) { const channel = (await client.channels.fetch(data.calendarEvent.channelId)); const calendarEvent = new CalendarEvent_1.CalendarEvent(channel, data.calendarEvent); if (client.options.disposeCachedCalendarEvents ?? true) channel.events.cache.delete(calendarEvent.id); client.emit('calendarEventDelete', calendarEvent); } exports.deleted = deleted; /** * Handle the CalendarEventRsvpUpdated event. * @param client The client the Websocket belongs to. * @param data The data of the event. */ async function rsvpUpdated(client, data) { const channel = (await client.channels.fetch(data.calendarEventRsvp.channelId)); const calendarEvent = await channel.events.fetch(data.calendarEventRsvp.calendarEventId); const oldCalendarEventRsvp = calendarEvent.rsvps.cache.get(data.calendarEventRsvp.userId); const newCalendarEventRsvp = new CalendarEventRsvp_1.CalendarEventRsvp(calendarEvent, data.calendarEventRsvp); client.emit('calendarEventRsvpEdit', newCalendarEventRsvp, oldCalendarEventRsvp); } exports.rsvpUpdated = rsvpUpdated; /** * Handle the CalendarEventRsvpManyUpdated event. * @param client The client the Websocket belongs to. * @param data The data of the event. */ async function rsvpsUpdated(client, data) { const oldCalendarEventRsvps = new collection_1.Collection(); const newCalendarEventRsvps = new collection_1.Collection(); for (const rawCalendarEventRsvp of data.calendarEventRsvps) { const channel = (await client.channels.fetch(rawCalendarEventRsvp.channelId)); const calendarEvent = await channel.events.fetch(rawCalendarEventRsvp.calendarEventId); const oldCalendarEventRsvp = calendarEvent.rsvps.cache.get(rawCalendarEventRsvp.userId); const newCalendarEventRsvp = new CalendarEventRsvp_1.CalendarEventRsvp(calendarEvent, rawCalendarEventRsvp); if (oldCalendarEventRsvp) oldCalendarEventRsvps.set(oldCalendarEventRsvp.id, oldCalendarEventRsvp); newCalendarEventRsvps.set(newCalendarEventRsvp.id, newCalendarEventRsvp); } client.emit('calendarEventRsvpsEdit', newCalendarEventRsvps, oldCalendarEventRsvps); } exports.rsvpsUpdated = rsvpsUpdated; /** * Handle the CalendarEventRsvpDeleted event. * @param client The client the Websocket belongs to. * @param data The data of the event. */ async function rsvpDeleted(client, data) { const channel = (await client.channels.fetch(data.calendarEventRsvp.channelId)); const calendarEvent = await channel.events.fetch(data.calendarEventRsvp.calendarEventId); const calendarEventRsvp = new CalendarEventRsvp_1.CalendarEventRsvp(calendarEvent, data.calendarEventRsvp); if (client.options.disposeCachedCalendarEventRsvps ?? true) calendarEvent.rsvps.cache.delete(calendarEventRsvp.id); client.emit('calendarEventRsvpDelete', calendarEventRsvp); } exports.rsvpDeleted = rsvpDeleted; //# sourceMappingURL=calendarEvent.js.map