Skip to content

Commit

Permalink
mastodon integration 🐘
Browse files Browse the repository at this point in the history
  • Loading branch information
John Ottenlips authored and John Ottenlips committed Sep 17, 2023
1 parent 5d81cc5 commit ae571c8
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# πŸ’ͺ WODaboard πŸ‹οΈ

"Workout Of the Day" on Vestaboard
"Workout Of the Day" on Vestaboard

This Github Action workflow also posts the Vestbaord message to the [[email protected]](https://mastodon.social/@workoutoftheday).

```
touch .env
Expand All @@ -17,10 +19,14 @@ or your GitHub action secrets for running with a GitHub workflow as a cron job.
VB_SUB_ID=yoursubscriptionid
VB_SUB_KEY=yoursubscriptionapikey
VB_SUB_SECRET=yoursubscriptionapisecret
# (optional to post to Mastodon)
MASTODON_ACCESS_TOKEN=
```

```
# send a WOD to your Vestaboard
bun install
bun run index.ts
```

Expand Down
Binary file modified bun.lockb
Binary file not shown.
35 changes: 32 additions & 3 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,25 @@ const days = {
5: "friday",
6: "saturday",
} as { [key: number]: IDays };
type IDays = "sunday" | "monday" | "tuesday" | "wednesday" | "thursday" | "friday" | "saturday";
type IDays =
| "sunday"
| "monday"
| "tuesday"
| "wednesday"
| "thursday"
| "friday"
| "saturday";

const main = () => {
const main = async () => {
const day = new Date().getDay();
const dayName = days[day];
const intensity = day % 3 === 0 ? "hard" : day % 2 === 0 ? "medium" : "easy";
const exercises = randomFourExercises(intensity);
const color = day % 3 === 0 ? "{63}" : day % 2 === 0 ? "{65}" : "{66}";
const text = `${color}Happy ${dayName}!${color}\nToday's WOD is:\n${exercises}`;
console.log(text);
sendMessage(text);
await sendMessage(text);
await sendMastodonMessage(text);
};

const sendMessage = async (text: string) => {
Expand All @@ -41,4 +49,25 @@ const sendMessage = async (text: string) => {
}
};

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)}`,
});
}
};

main();

0 comments on commit ae571c8

Please sign in to comment.