Avatar

@demo

12 public vals
Joined January 11, 2023
1
export let kangaroo_jack = "https://en.wikipedia.org/wiki/Kangaroo_Jack";
1
2
3
4
5
6
7
8
9
10
11
12
export let respondToDiscordCommand = (payload) => {
// https://discord.com/developers/docs/interactions/receiving-and-responding#responding-to-an-interaction
return {
"type": 4,
"data": {
"tts": false,
"content": "Congrats on sending your command!",
"embeds": [],
"allowed_mentions": { "parse": [] },
},
};
};
1
2
3
4
5
6
7
8
9
10
11
12
13
import { Buffer } from "node:buffer";
export let naclValidateRequest = async (req: express.Request, publicKey) => {
const { default: nacl } = await import("npm:tweetnacl@1.0.3");
const signature = req.get("X-Signature-Ed25519");
const timestamp = req.get("X-Signature-Timestamp");
const body = JSON.stringify(req.body); // rawBody is expected to be a string, not raw bytes
const isVerified = nacl.sign.detached.verify(
Buffer.from(timestamp + body),
Buffer.from(signature, "hex"),
Buffer.from(publicKey, "hex"),
);
return isVerified;
};
1
2
3
4
5
6
7
8
9
10
11
import { Buffer } from "node:buffer";
export let naclValidate = async (publicKey, signature, timestamp, body) => {
const { default: nacl } = await import("npm:tweetnacl@1.0.3");
const isVerified = nacl.sign.detached.verify(
Buffer.from(timestamp + body),
Buffer.from(signature, "hex"),
Buffer.from(publicKey, "hex"),
);
return isVerified;
};
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { respondToDiscordCommand } from "https://esm.town/v/demo/respondToDiscordCommand";
import { naclValidateRequest } from "https://esm.town/v/demo/naclValidateRequest";
import process from "node:process";
export let discordInteractionHook = async (
req: express.Request,
res: express.Response,
) => {
// https://discord.com/developers/applications/<application_id>/information
const pub = process.env.personalBotPublicKey;
if (!(await naclValidateRequest(req, pub))) {
return res.status(401).end("invalid request signature");
}
// Handle ping request
// https://discord.com/developers/docs/interactions/receiving-and-responding#receiving-an-interaction
if (req.body["type"] == 1) {
res.json({ type: 1 });
return;
}
// Logic
console.log(req.body);
res.json(respondToDiscordCommand(req.body));
};
1
2
3
4
5
import { hnSearch } from "https://esm.town/v/stevekrouse/hnSearch?v=16";
export const hnGetLatest = hnSearch({
search_by_date: true,
});
1
export let timestamp = new Date(Number(new Date()));
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import { fetch } from "https://esm.town/v/std/fetch";
export let shortenUrl = async (url) => {
const data = {
url: url,
};
let resp = await fetch("https://api.util.fyi/shorten/", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(data),
});
return await resp.json();
};
1
2
3
import { zero } from "https://esm.town/v/rian/zero?v=5";
export let riansZero = zero;
1
2
3
4
5
6
7
8
9
10
11
import { six } from "https://esm.town/v/pedrovhb/six?v=1";
export let seven = ((n) => {
return [
...Array((six * six) / 2).keys(),
]
.slice(0)
.map((b) => n % b == 0)
.filter((b) => b)
.reduce((a, c) => a + c);
})(six ** 2);