a
This commit is contained in:
77
hosts/default/apps/files/crontab-executable.ts
Normal file
77
hosts/default/apps/files/crontab-executable.ts
Normal file
@@ -0,0 +1,77 @@
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
import { exec } from "child_process";
|
||||
|
||||
const stateFilePath = path.join(
|
||||
process.env.HOME || "~",
|
||||
".regretevator-challenge-state"
|
||||
);
|
||||
|
||||
const regretevatorStateFile = path.join(
|
||||
process.env.HOME || "~",
|
||||
".regretevator_state"
|
||||
);
|
||||
|
||||
if (fs.existsSync(regretevatorStateFile)) process.exit(0);
|
||||
|
||||
function sendReminderNotification() {
|
||||
exec(
|
||||
`notify-send -a "tuxstrap" -u low "OCbwoy3's Dotfiles" "It's time for Regretevator!"`
|
||||
);
|
||||
}
|
||||
|
||||
function sendReminderNotificationPlayed(floors: number) {
|
||||
exec(
|
||||
`notify-send -a "tuxstrap" -u low "OCbwoy3's Dotfiles" "Man... Only ${floors} floors, really? You can do better than that."`
|
||||
);
|
||||
}
|
||||
|
||||
function sendSpamNotifications() {
|
||||
for (let i = 0; i < 2; i++) {
|
||||
exec(
|
||||
`notify-send -a "tuxstrap" -u low "OCbwoy3's Dotfiles" "HURRY UP!!!!!"`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function writeState(floorsSurvived: number) {
|
||||
const state = {
|
||||
date: new Date().toISOString().split("T")[0],
|
||||
floors: floorsSurvived,
|
||||
};
|
||||
fs.writeFileSync(stateFilePath, JSON.stringify(state, null, 2));
|
||||
}
|
||||
|
||||
function checkChallengeState() {
|
||||
if (fs.existsSync(stateFilePath)) {
|
||||
const state = JSON.parse(fs.readFileSync(stateFilePath, "utf-8"));
|
||||
const today = new Date().toISOString().split("T")[0];
|
||||
const stateDate = state.date;
|
||||
const floorsSurvived = state.floors;
|
||||
|
||||
const now = new Date();
|
||||
const hoursLeft = 24 - now.getHours();
|
||||
|
||||
if (stateDate === today) {
|
||||
if (floorsSurvived < 25) {
|
||||
if (floorsSurvived === 0) {
|
||||
sendReminderNotification();
|
||||
} else {
|
||||
sendReminderNotificationPlayed(floorsSurvived);
|
||||
}
|
||||
if (hoursLeft <= 4) {
|
||||
sendSpamNotifications();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
sendReminderNotification();
|
||||
writeState(0); // Write state with 0 floors if the user hasn't played today
|
||||
}
|
||||
} else {
|
||||
sendReminderNotification();
|
||||
writeState(0); // Write state with 0 floors if no state file exists
|
||||
}
|
||||
}
|
||||
|
||||
// Run the check
|
||||
checkChallengeState();
|
||||
Reference in New Issue
Block a user