Avatar

nate

9 public vals
Joined January 12, 2023
1
2
3
export let anotherTest = () => {
console.email("Notified!");
};
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { slackrespond } from "https://esm.town/v/nate/slackrespond";
import process from "node:process";
// A Slack slash command app to evaluate a val.town expression.
//
// Setup: Add a slash command using
// "https://api.val.town/express/@nate.slackapp" as the request URL.
//
// Usage: /yourcommandname {expression}
//
// Examples:
// - /evaltown 1+1
// - /evaltown @nate.email("Hi from Slack!")
export let slackapp = async (req, res) => {
if ("ssl_check" in req.body) return;
if (
!("api_app_id" in req.body) ||
req.body.api_app_id !== process.env.SLACK_API_APP_ID ||
!("text" in req.body) ||
!("response_url" in req.body)
) {
res.status(200);
res.set("Content-Type", "application/json");
res.send(
JSON.stringify({
text: "A parameter was invalid or missing.",
})
);
return;
}
// Slack requires a response within 3 seconds so we send back an empty
// response as an acknowledgment and process the request asynchronously.
res.status(200).send();
await slackrespond(req.body.response_url, req.body.text);
};
1
2
3
4
5
6
7
import { rateLimit } from "https://esm.town/v/nate/rateLimit";
export let email = async (...args: any[]) => {
return await rateLimit("email", 10, () => {
(console.email as any)(...args);
});
};
1
2
3
4
5
6
7
8
9
10
11
import process from "node:process";
import { gpt3 } from "https://esm.town/v/nate/gpt3";
export let kindness = async () => {
return await gpt3({
openAiKey: process.env.OPENAI_API_KEY,
prompt:
"Speaking as universal consciousness, say something short, true, uplifting, loving, and kind.",
model: "text-curie-001",
});
};
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import { current_vals } from "https://esm.town/v/nate/current_vals";
import { getUserId } from "https://esm.town/v/nate/getUserId";
export let getVals = async (author: string, offset: number = 0, limit: number = 10) => {
const authorId = await getUserId(author);
return current_vals({
select: "name",
public: "eq.true",
author: `eq.${authorId}`,
order: "runEndAt.desc.nullslast",
offset: offset,
limit: limit,
});
};
1
2
3
4
5
import { rest_v1 } from "https://esm.town/v/nate/rest_v1";
export let current_vals = async (params) => {
return rest_v1("current_vals", params);
};
1
2
3
4
import { testMessages } from "https://esm.town/v/nate/testMessages";
export let test = (msg) =>
testMessages.push({ time: Date.now(), msg });
1
2
3
export let ping = () => {
return "pong";
};
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { healthData } from "https://esm.town/v/nate/healthData";
import { isAuthenticated } from "https://esm.town/v/nate/isAuthenticated";
export let recordHealthData = (params) => {
if (isAuthenticated(params)) {
const date = params["date"];
// Expected input is a string with the number of heartbeats for each
// minute of the day, filled in with 0s. This converts it to a hash of
// the minute of the day to the number of heartbeats, excluding minutes
// with no data.
const heartRate = {};
params["heartRate"]
.split("\r\n")
.map((item: string) => +(item || "").trim())
.forEach((item: number, index: number) => {
if (item > 0) heartRate[index] = item;
});
const steps = parseInt(params["steps"]);
healthData.heartRate[date] = heartRate;
healthData.steps[date] = steps;
return true;
} else {
return false;
}
};
Next