Skip to content

Commit

Permalink
fix: resolved more bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
kyranet committed Nov 9, 2023
1 parent d5026bc commit f9ed1a9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 39 deletions.
68 changes: 30 additions & 38 deletions src/commands/System/Admin/eval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/formatters.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit f9ed1a9

Please sign in to comment.