import { email } from "https://esm.town/v/std/email?v=9";
import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON?v=41";
export async function EmailNotifIfDidntCode() {
type Data = DataItem[];
interface DataItem {
id: string;
type: string;
actor: any;
repo: any;
payload: any;
"public": boolean;
created_at: string;
org?: any;
}
const githubEvents = await fetchJSON(
"https://api.github.com/users/daviddkkim/events",
) as Data;
if (githubEvents.length < 1)
return;
const filteredEvents = githubEvents.filter((event) => {
return event.type === "PushEvent";
});
const latestPushEvent = filteredEvents[0];
const latestActivityDate = new Date(latestPushEvent.created_at);
const today = new Date();
if (latestActivityDate.getFullYear() != today.getFullYear()) {
await email({
text: "you gotta push some code my guy! Today is " + today.getFullYear() +
"-" + today.getMonth() + "-" + today.getDay(),
});
return;
}
if (latestActivityDate.getMonth() != today.getMonth()) {
await email({
text: "you gotta push some code my guy! Today is " + today.getFullYear() +
"-" + today.getMonth() + "-" + today.getDay(),
});
return;
}
if (latestActivityDate.getDay() != today.getDay()) {
await email({
text: "you gotta push some code my guy! Today is " + today.getFullYear() +
"-" + today.getMonth() + "-" + today.getDay(),
});
return;
}
await email({
text: "you coded today! " + today.getFullYear() + "-" + today.getMonth() +
"-" + today.getDay(),
});
return;
}