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
39
40
41
42
43
44
45
46
47
48
49
50
import { email } from "https://esm.town/v/std/email?v=9";
import { set } from "https://esm.town/v/std/set?v=11";
let { checkRedditState } = await import("https://esm.town/v/bnorick/checkRedditState");
import { reddit_matches } from "https://esm.town/v/bnorick/reddit_matches";
import { toggleSubreddits } from "https://esm.town/v/bnorick/toggleSubreddits";
export let check_reddit = async ({ check = null, toggle = null }) => {
if (check) {
check = Object.assign({
fetch_limit: 10,
force: false,
enable_toggle: Boolean(toggleSubreddits),
}, check);
// let before = @me.checkRedditState["x"].last;
let result = await reddit_matches({
username: check.username,
last_run_at_utc: check.last_run_at_utc,
filters: check.filters,
current_state: checkRedditState,
fetch_limit: check.fetch_limit,
enable_toggle: check.enable_toggle,
force: check.force,
});
// $me.redditAlertHistory.push({
// before: before,
// matches: result.matches,
// time: new Date().toLocaleString("en-US", {
// timeZone: "America/Los_Angeles",
// }),
// });
checkRedditState = result.state;
await set(
"checkRedditState",
checkRedditState,
);
if (result.email)
await email({
text: result.email.text,
subject: result.email.subject,
});
return result;
}
if (toggle) {
if (!checkRedditState) {
await set(
"checkRedditState",
checkRedditState,
);
return {};
}
👆 This is a val. Vals are TypeScript snippets of code, written in the browser and run on our servers. Create scheduled functions, email yourself, and persist small pieces of data — all from the browser.