diff --git a/src/commands/eval.ts b/src/commands/eval.ts index 1b08576..1dc39f7 100644 --- a/src/commands/eval.ts +++ b/src/commands/eval.ts @@ -1,7 +1,7 @@ -import { CommandType, commandModule, Context } from "@sern/handler"; +import { commandModule, CommandType } from "@sern/handler"; import { Client, Collection, EmbedBuilder } from "discord.js"; -import { inspect } from "util"; import { fetch } from "undici"; +import { inspect } from "util"; import { ownerOnly } from "../plugins/ownerOnly.js"; import type { Data } from "./plugin.js"; @@ -11,43 +11,27 @@ export default commandModule({ plugins: [ownerOnly()], alias: ["ev"], execute: async (ctx, args) => { - const [type, code] = args; - const { channel, guild, client, user, member, message: msg } = ctx; + let code: string[] | string = args[1]; - function send(id: string, ping: boolean = false) { - const channel = client.channels.cache.get(id); - if (!channel) return; - const embed = new EmbedBuilder() - .setColor(0xcc5279) - .setTitle("v1 is out!") - .setThumbnail(client.user?.displayAvatarURL() ?? "") - .setImage( - "https://raw.githubusercontent.com/sern-handler/.github/main/banner.png" - ) - .setAuthor({ name: "sern", url: "https://sern-handler.js.org/" }) - .setDescription( - `__**Quick Look:**__\n\n${text()}\n\nThank you all for being patient! <@&981419402283085834> will continue being given out until next week` - ) - .setFooter({ text: "Supports DJS v14.2 and above" }) - .setTimestamp(); - const content = ping ? '@everyone' : null; - channel.isTextBased() && channel.send({ content, embeds: [embed] }); - return "Done sir"; + code = code.join(" ") as string; + if (code.includes("await")) { + const ar = code.split(";"); + const last = ar.pop(); + code = `(async () => {\n${ar.join(";\n")}\nreturn ${ + last?.trim() ?? " " + }\n\n})();`; } - - if (type !== "text") return; + const { channel, guild, client, user, member, message: msg } = ctx; if ( - (code.join(" ").includes("send") || code.join(" ").includes("reply")) && + ["TOKEN", "process.env", "token"].some((e) => code.includes(e)) && ctx.user.id !== "697795666373640213" ) - return; + return ctx.message.react("❌"); - if (code.join(" ").includes("process.env")) return; - if (code.join(" ").includes("token")) return; let result: unknown | string; try { - result = eval(code.join(" ")); + result = eval(code); } catch (error) { result = error; } @@ -63,7 +47,29 @@ export default commandModule({ if ((result as string).length > 2000) { channel!.send("Result is too long to send"); } + ctx.channel!.send({ content: result as string }); + + function send(id: string, ping = false) { + const channel = client.channels.cache.get(id); + if (!channel) return; + const embed = new EmbedBuilder() + .setColor(0xcc5279) + .setTitle("v1 is out!") + .setThumbnail(client.user?.displayAvatarURL() ?? "") + .setImage( + "https://raw.githubusercontent.com/sern-handler/.github/main/banner.png" + ) + .setAuthor({ name: "sern", url: "https://sern-handler.js.org/" }) + .setDescription( + `__**Quick Look:**__\n\n${text()}\n\nThank you all for being patient! <@&981419402283085834> will continue being given out until next week` + ) + .setFooter({ text: "Supports DJS v14.2 and above" }) + .setTimestamp(); + const content = ping ? "@everyone" : null; + channel.isTextBased() && channel.send({ content, embeds: [embed] }); + return "Done sir"; + } }, }); diff --git a/src/events/uncaughtException.ts b/src/events/uncaughtException.ts new file mode 100644 index 0000000..bc94065 --- /dev/null +++ b/src/events/uncaughtException.ts @@ -0,0 +1,9 @@ +import { eventModule, EventType } from "@sern/handler"; + +export default eventModule({ + emitter: "process", + type: EventType.External, + execute(r) { + console.log(r); + }, +}); diff --git a/src/events/unhandledRejection.ts b/src/events/unhandledRejection.ts new file mode 100644 index 0000000..bc94065 --- /dev/null +++ b/src/events/unhandledRejection.ts @@ -0,0 +1,9 @@ +import { eventModule, EventType } from "@sern/handler"; + +export default eventModule({ + emitter: "process", + type: EventType.External, + execute(r) { + console.log(r); + }, +}); diff --git a/src/index.ts b/src/index.ts index dec3679..593709c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,4 @@ -import { Client, GatewayIntentBits, Partials, ActivityType } from "discord.js"; +import { ActivityType, Client, GatewayIntentBits, Partials } from "discord.js"; import { Sern, SernEmitter } from "@sern/handler"; import "dotenv/config"; @@ -13,6 +13,7 @@ const client = new Client({ partials: [Partials.GuildMember, Partials.GuildMember, Partials.Message], }); +Sern.addExternal(process); Sern.init({ client, sernEmitter: new SernEmitter(), @@ -29,4 +30,4 @@ client.once("ready", (client) => { console.log(`[✅]: Logged in as ${client.user.username}`); }); -client.login(); +await client.login();