-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
78 lines (71 loc) Β· 2.06 KB
/
index.ts
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import fetch from "node-fetch";
import * as dotenv from "dotenv";
import { randomFourExercises } from "./plan";
dotenv.config();
export const API_URL = "https://platform.vestaboard.com";
const days = {
0: "sunday",
1: "monday",
2: "tuesday",
3: "wednesday",
4: "thursday",
5: "friday",
6: "saturday",
} as { [key: number]: Days };
type Days =
| "sunday"
| "monday"
| "tuesday"
| "wednesday"
| "thursday"
| "friday"
| "saturday";
type Intensity = "easy" | "medium" | "hard";
// hardcode to easy for now
const intensity = "easy" as Intensity
const main = async () => {
const day = new Date().getDay();
const dayName = days[day];
// const intensity = day % 3 === 1 ? "hard" : day % 3 === 2 ? "medium" : "easy";
const exercises = randomFourExercises(intensity);
const color =
intensity === "hard" ? "{63}" : intensity === "medium" ? "{65}" : "{66}";
const text = `${color}Happy ${dayName}!${color}\nToday's WOD is:\n${exercises}`;
console.log(text);
await sendMessage(text);
await sendMastodonMessage(text);
};
const sendMessage = async (text: string) => {
if (process.env.VB_SUB_KEY && process.env.VB_SUB_SECRET) {
await fetch(`${API_URL}/subscriptions/${process.env.VB_SUB_ID}/message`, {
method: "POST",
headers: {
"X-Vestaboard-Api-Key": process.env.VB_SUB_KEY,
"X-Vestaboard-Api-Secret": process.env.VB_SUB_SECRET,
},
body: JSON.stringify({
text,
}),
});
}
};
const sendMastodonMessage = async (text: string) => {
const status = text
.replace("{66}", "π© ")
.replace("{66}", " π©")
.replace("{65}", "π¨ ")
.replace("{65}", " π¨")
.replace("{63}", "π₯ ")
.replace("{63}", " π₯");
if (process.env.MASTODON_ACCESS_TOKEN) {
await fetch(`https://mastodon.social/api/v1/statuses`, {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.MASTODON_ACCESS_TOKEN}`,
"Idempotency-Key": `${Date.now()}`,
},
body: `status=${encodeURIComponent(status + `\n#workoutoftheday`)}`,
});
}
};
main();