From f9ed1a9645c6d9ec350347eaedb243e9d7815c8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aura=20Rom=C3=A1n?= Date: Thu, 9 Nov 2023 17:24:12 +0100 Subject: [PATCH] fix: resolved more bugs --- src/commands/System/Admin/eval.ts | 68 ++++++++++++++----------------- tests/lib/formatters.test.ts | 2 +- 2 files changed, 31 insertions(+), 39 deletions(-) diff --git a/src/commands/System/Admin/eval.ts b/src/commands/System/Admin/eval.ts index 4b324e28c3c..e61d06bfd41 100644 --- a/src/commands/System/Admin/eval.ts +++ b/src/commands/System/Admin/eval.ts @@ -53,50 +53,42 @@ export class UserCommand extends SkyraCommand { return send(message, `${header}${body}`); } - private get context() { + private async fetchContext() { if (!this.#cachedEvalContext) { - const modules = Object.fromEntries( - [ - // - ['buffer', 'node:buffer'], - ['crypto', 'node:crypto'], - ['events', 'node:events'], - ['fs', 'node:fs'], - ['http', 'node:http'], - ['os', 'node:os'], - ['path', 'node:path'], - ['process', 'node:process'], - ['stream', 'node:stream'], - ['timers', 'node:timers'], - ['url', 'node:url'], - ['util', 'node:util'], - ['v8', 'node:v8'], - ['vm', 'node:vm'], - ['worker_threads', 'node:worker_threads'] - ].map(([key, module]) => [key, require(module)]) - ); this.#cachedEvalContext = { ...globalThis, - ...modules, - stream: { consumers: require('node:stream/consumers'), web: require('node:stream/web'), ...modules.stream }, - timers: { promises: require('node:timers/promises'), ...modules.timers }, + buffer: await import('node:buffer'), + crypto: await import('node:crypto'), + events: await import('node:events'), + fs: await import('node:fs'), + http: await import('node:http'), + os: await import('node:os'), + path: await import('node:path'), + process: await import('node:process'), + url: await import('node:url'), + util: await import('node:util'), + v8: await import('node:v8'), + vm: await import('node:vm'), + worker_threads: await import('node:worker_threads'), + stream: { web: await import('node:stream/web'), ...(await import('node:stream')) }, + timers: { promises: await import('node:timers/promises'), ...(await import('node:timers')) }, discord: { - ...require('discord.js'), - builders: require('@discordjs/builders'), - collection: require('@discordjs/collection'), - types: require('discord-api-types/v10') + ...(await import('discord.js')), + builders: await import('@discordjs/builders'), + collection: await import('@discordjs/collection'), + types: await import('discord-api-types/v10') }, sapphire: { - asyncQueue: require('@sapphire/async-queue'), - fetch: require('@sapphire/fetch'), - pieces: require('@sapphire/pieces'), - framework: require('@sapphire/framework'), - snowflake: require('@sapphire/snowflake'), - stopwatch: require('@sapphire/stopwatch'), + asyncQueue: await import('@sapphire/async-queue'), + fetch: await import('@sapphire/fetch'), + pieces: await import('@sapphire/pieces'), + framework: await import('@sapphire/framework'), + snowflake: await import('@sapphire/snowflake'), + stopwatch: await import('@sapphire/stopwatch'), utilities: { - ...require('@sapphire/utilities'), - time: require('@sapphire/time-utilities'), - discord: require('@sapphire/discord.js-utilities') + ...(await import('@sapphire/utilities')), + time: await import('@sapphire/time-utilities'), + discord: await import('@sapphire/discord.js-utilities') } }, container: this.container, @@ -140,7 +132,7 @@ export class UserCommand extends SkyraCommand { return { success: false, time: '💥 Syntax Error', result: (error as SyntaxError).message }; } - const context = createContext({ ...this.context, msg: message, message, args, signal }); + const context = createContext({ ...(await this.fetchContext()), msg: message, message, args, signal }); const stopwatch = new Stopwatch(); let success: boolean; diff --git a/tests/lib/formatters.test.ts b/tests/lib/formatters.test.ts index 0c8d99d3dcc..08aa76208d9 100644 --- a/tests/lib/formatters.test.ts +++ b/tests/lib/formatters.test.ts @@ -3,7 +3,7 @@ import { client } from '#mocks/MockInstances'; import { formatMessage } from '#utils/formatters'; import { container } from '@sapphire/framework'; import { EmbedType, MessageFlags, type APIMessage } from 'discord-api-types/v10'; -import type { Message } from 'discord.js'; +import { Message } from 'discord.js'; describe('formatters', () => { describe('formatMessage', () => {