UNPKG

@evolvejs/core

Version:

An advanced Discord API wrapper with TS and JS support

53 lines (52 loc) 2.7 kB
"use strict"; /* eslint-disable @typescript-eslint/no-non-null-assertion */ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const __1 = require("../../.."); const Guild_1 = require("../../../Structures/Guild/Guild"); class default_1 { constructor(client, payload, shard) { this.client = client; this.payload = payload; (() => __awaiter(this, void 0, void 0, function* () { return yield this.generate(payload, shard); }))(); this.client.readyAt = Date.now(); this.client.sessionID = payload.d.session_id; } generate(payload, shard) { return __awaiter(this, void 0, void 0, function* () { const { user, guilds } = payload.d; this.client.user = new __1.ClientUser(user.username, user.discriminator, user.verified, user.id, user.flags, user.email, user.bot, user.avatar); for (const guild of guilds) { const fetched = new Guild_1.Guild(yield this.client.rest.endpoint(__1.Endpoints.GUILD).get(guild.id), this.client); for (const [k, v] of fetched.members) { if (this.client.options.enableUsersCache) if (v.user) this.client.users.set(k, v.user); } for (const [k, v] of fetched.channels) { if (this.client.options.enableChannelCache) this.client.channels.set(k, v); } for (const [k, v] of fetched.emojis) { if (this.client.options.enableEmojiCache) this.client.emojis.set(k, v); } for (const [k, v] of fetched.roles) { this.client.roles.set(k, v); } if (this.client.options.enableGuildCache) this.client.guilds.set(fetched.id, fetched); } this.client.emit(__1.EVENTS.READY, shard); }); } } exports.default = default_1;