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
import changeUserStatus from "https://esm.town/v/arrudaricardo/github_change_user_status";
import emojiMap from "https://esm.town/v/arrudaricardo/github_status_emoji_map";
const GITHUB_TOKEN = Deno.env.get("GITHUB_TOKEN");
if (!GITHUB_TOKEN) throw new Error("Add GITHUB_TOKEN environemnt variable.");
const MAX_MESSAGE_LENGTH = 80;
type AdviceResponse = {
slip: {
id: number;
advice: string;
};
};
let message: null | string = null;
while (!message) {
const adviceResponse = await fetch("https://api.adviceslip.com/advice");
const adviceJson: AdviceResponse = await adviceResponse.json();
const newMessage = adviceJson.slip.advice + "@ x.arruda.dev/v";
if (newMessage.length <= MAX_MESSAGE_LENGTH) {
message = newMessage;
}
}
const emojiTexts = Object.values(emojiMap);
const randomEmoji = emojiTexts[Math.floor(Math.random() * emojiTexts.length)];
const response = await changeUserStatus(
{ message: message, emoji: randomEmoji },
GITHUB_TOKEN,
);
if (!response.changeUserStatus.status) throw new Error("Could not set status!");
console.info("Status updated.\n", response);
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
June 6, 2024