From 9cbafac379a27312d074ed9092645c1daad1879d Mon Sep 17 00:00:00 2001 From: arHSM Date: Sun, 13 Jul 2025 01:47:45 +0900 Subject: [PATCH 1/2] feat(modules/misc/urldecode): add urldecode command --- src/modules/misc/urldecode.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/modules/misc/urldecode.js diff --git a/src/modules/misc/urldecode.js b/src/modules/misc/urldecode.js new file mode 100644 index 0000000..039fd29 --- /dev/null +++ b/src/modules/misc/urldecode.js @@ -0,0 +1,29 @@ +const Command = require("#lib/command.js"); + +const urldecode = new Command("urldecode"); +urldecode.category = "misc"; +urldecode.helpText = "Get url information"; +urldecode.usage = ""; +urldecode.callback = async function (msg, _, [urlString]) { + const url = new URL(urlString); + + const info = [ + ["scheme", url.protocol], + ["username", url.username], + ["password", url.password], + ["host", url.host], + ["path", url.pathname], + ["hash", url.hash], + ]; + + return `\`\`\`py +${info.filter(kv => kv[1].length > 0).map(([k, v]) => `${k} = ${v}`).join("\n")} + +${JSON.stringify( + url.searchParams, + (_, v) => v instanceof URLSearchParams ? Object.fromEntries(v.entries()) : v, + "\t" +)} +\`\`\``; +}; +hf.registerCommand(urldecode); From 64456645124ccff10f1661181aafb68804e61aa7 Mon Sep 17 00:00:00 2001 From: Cynthia Foxwell Date: Sat, 12 Jul 2025 10:50:26 -0600 Subject: [PATCH 2/2] urldecode: cleanup, error handling --- src/modules/misc/urldecode.js | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/src/modules/misc/urldecode.js b/src/modules/misc/urldecode.js index 039fd29..cb19372 100644 --- a/src/modules/misc/urldecode.js +++ b/src/modules/misc/urldecode.js @@ -1,29 +1,37 @@ const Command = require("#lib/command.js"); +const {Icons} = require("#util/constants.js"); const urldecode = new Command("urldecode"); urldecode.category = "misc"; -urldecode.helpText = "Get url information"; +urldecode.helpText = "Get information on a URL"; urldecode.usage = ""; -urldecode.callback = async function (msg, _, [urlString]) { +urldecode.callback = async function (msg, line, [urlString]) { + try { const url = new URL(urlString); const info = [ - ["scheme", url.protocol], - ["username", url.username], - ["password", url.password], - ["host", url.host], - ["path", url.pathname], - ["hash", url.hash], + ["scheme", url.protocol], + ["username", url.username], + ["password", url.password], + ["host", url.host], + ["path", url.pathname], + ["hash", url.hash], ]; return `\`\`\`py -${info.filter(kv => kv[1].length > 0).map(([k, v]) => `${k} = ${v}`).join("\n")} +${info + .filter((kv) => kv[1].length > 0) + .map(([k, v]) => `${k} = ${v}`) + .join("\n")} ${JSON.stringify( - url.searchParams, - (_, v) => v instanceof URLSearchParams ? Object.fromEntries(v.entries()) : v, - "\t" + url.searchParams, + (_, v) => (v instanceof URLSearchParams ? Object.fromEntries(v.entries()) : v), + "\t" )} \`\`\``; + } catch (err) { + return `${Icons.silk.error} Failed to decode URL:\n\`\`\`\n${err}\`\`\``; + } }; hf.registerCommand(urldecode);