diff --git a/deps.ts b/deps.ts index 4f8bdb0..f09c650 100644 --- a/deps.ts +++ b/deps.ts @@ -7,4 +7,4 @@ export { export * from "https://deno.land/x/discordeno@13.0.0-rc45/mod.ts"; export * from "https://deno.land/x/discordeno@13.0.0-rc45/plugins/mod.ts"; export { config as dotEnvConfig } from "https://deno.land/x/dotenv@v3.1.0/mod.ts"; -export * from "https://esm.sh/typedoc-json-parser@3.0.0"; +export * from "https://esm.sh/typedoc-json-parser@5.0.0"; diff --git a/src/commands/class.ts b/src/commands/class.ts index 6fd5ab7..1e2044b 100644 --- a/src/commands/class.ts +++ b/src/commands/class.ts @@ -90,6 +90,12 @@ createCommand({ "Source", "Link", cls.source?.url || "https://josh.evie.dev", + ).addButton( + "Website", + "Link", + `https://joshdocs.netlify.app/docs/${ + cls.project.name.split("/")[1] + }/classes#${cls.name}`, ), }, }, diff --git a/src/commands/eval.ts b/src/commands/eval.ts new file mode 100644 index 0000000..4417936 --- /dev/null +++ b/src/commands/eval.ts @@ -0,0 +1,80 @@ +import { BOT_COLOR } from "../../config.ts"; +import { + ApplicationCommandOptionTypes, + ApplicationCommandTypes, + InteractionResponseTypes, +} from "../../deps.ts"; +import * as docsUtils from "../utils/docs.ts"; +import { Embeds } from "../utils/embed.ts"; +import { createCommand } from "./mod.ts"; + +const docs = docsUtils; + +createCommand({ + name: "eval", + description: "Evaluate code", + type: ApplicationCommandTypes.ChatInput, + scope: "Global", + options: [ + { + name: "code", + description: "Code", + type: ApplicationCommandOptionTypes.String, + required: true, + }, + ], + execute: async (bot, interaction) => { + if (interaction.user.id !== 709674034798788617n) { + return bot.helpers.sendInteractionResponse( + interaction.id, + interaction.token, + { + type: InteractionResponseTypes.ChannelMessageWithSource, + data: { + flags: 1 << 6, + content: "Sorry, you are not allowed to use this command", + }, + }, + ); + } + const inputCode = interaction.data?.options?.find( + (x) => x.name === "code", + )?.value as string; + try { + docs; // to be used + let result = eval(inputCode); + if (result instanceof Promise) { + result = await result; + } + const embed = new Embeds(bot) + .setTitle("Eval") + .setColor(BOT_COLOR) + .addField("Output", `\`\`\`ts\n${Deno.inspect(result)}\`\`\``); + return bot.helpers.sendInteractionResponse( + interaction.id, + interaction.token, + { + type: InteractionResponseTypes.ChannelMessageWithSource, + data: { + embeds: embed, + }, + }, + ); + } catch (error) { + const embed = new Embeds(bot) + .setTitle("Eval") + .setColor(BOT_COLOR) + .addField("Output", `\`\`\`ts\n${error}\`\`\``); + return bot.helpers.sendInteractionResponse( + interaction.id, + interaction.token, + { + type: InteractionResponseTypes.ChannelMessageWithSource, + data: { + embeds: embed, + }, + }, + ); + } + }, +}); diff --git a/src/commands/method.ts b/src/commands/method.ts index 55b262b..d14d13a 100644 --- a/src/commands/method.ts +++ b/src/commands/method.ts @@ -91,6 +91,12 @@ createCommand({ "Source", "Link", method.source?.url || "https://josh.evie.dev", + ).addButton( + "Website", + "Link", + `https://joshdocs.netlify.app/docs/${ + method.project.name.split("/")[1] + }/methods#${method.parent.name}-${method.name}`, ), }, }, diff --git a/src/utils/docs.ts b/src/utils/docs.ts index e663a20..e6e5743 100644 --- a/src/utils/docs.ts +++ b/src/utils/docs.ts @@ -40,11 +40,7 @@ export const resolveReferenceType = (type: ReferenceTypeParser) => { }; export const resolveType = (type: TypeParser) => { - if (type instanceof ReferenceTypeParser) { - return resolveReferenceType(type); - } - - return type.toString(); + return `[${type.toString()}](https://joshdocs.netlify.app/)`; }; let filesCache: { date?: Date; files: File[] }; diff --git a/src/utils/notFound.ts b/src/utils/notFound.ts index d2da4ac..29d74f9 100644 --- a/src/utils/notFound.ts +++ b/src/utils/notFound.ts @@ -54,6 +54,7 @@ export const notFound = async ( { type: InteractionResponseTypes.ChannelMessageWithSource, data: { + flags: 1 << 6, embeds: new Embeds(bot) .setTitle(name + " not found") .setColor(BOT_COLOR)