mirror of
https://github.com/System-End/slack-end.git
synced 2026-04-19 23:22:56 +00:00
enhancement(lint): Fix lint errors for src/modules/hacktime.ts
Co-authored-by: NeonGamerBot-QK <saahilattud@gmail.com> Signed-off-by: zeon-neon[bot] <136533918+zeon-neon[bot]@users.noreply.github.com>
This commit is contained in:
parent
786b76d43e
commit
8e8737a686
1 changed files with 113 additions and 104 deletions
|
|
@ -13,121 +13,130 @@ export function getStatusBar() {
|
|||
.then((d) => d.data.projects);
|
||||
}
|
||||
function isWithinLastTwoMinutes(timestamp) {
|
||||
if(timestamp instanceof Date) timestamp = timestamp.getTime();
|
||||
if (timestamp instanceof Date) timestamp = timestamp.getTime();
|
||||
const currentTime = Date.now(); // Get the current timestamp in milliseconds
|
||||
const twoMinutesInMilliseconds = 2 * 60 * 1000; // 2 minutes in milliseconds
|
||||
|
||||
return (currentTime - timestamp) <= twoMinutesInMilliseconds;
|
||||
return currentTime - timestamp <= twoMinutesInMilliseconds;
|
||||
}
|
||||
|
||||
export function watchForWhenIUseHacktime(app: ModifiedApp) {
|
||||
// inline function lol
|
||||
const its_late_at_night = new Date().getHours() >= 20 && new Date().getHours() <= 6
|
||||
function getMessage(type:string, ops?: any) {
|
||||
switch(type) {
|
||||
case "new":
|
||||
if(app.is_at_school) {
|
||||
return `Well Well Well <@${process.env.MY_USER_ID}>, your coding *${ops.d.project}* looks like (you better not get caught istg getting expelled is not IT!)...`
|
||||
} else if (its_late_at_night) {
|
||||
return `Well Well Well <@${process.env.MY_USER_ID}>, your coding *${ops.d.project}* looks like (its late at night gts dumbass)...`
|
||||
} else {
|
||||
return `Well Well Well <@${process.env.MY_USER_ID}>, your coding *${ops.d.project}* looks like...`
|
||||
}
|
||||
break;
|
||||
const its_late_at_night =
|
||||
new Date().getHours() >= 20 && new Date().getHours() <= 6;
|
||||
function getMessage(type: string, ops?: any) {
|
||||
switch (type) {
|
||||
case "new":
|
||||
if (app.is_at_school) {
|
||||
return `Well Well Well <@${process.env.MY_USER_ID}>, your coding *${ops.d.project}* looks like (you better not get caught istg getting expelled is not IT!)...`;
|
||||
} else if (its_late_at_night) {
|
||||
return `Well Well Well <@${process.env.MY_USER_ID}>, your coding *${ops.d.project}* looks like (its late at night gts dumbass)...`;
|
||||
} else {
|
||||
return `Well Well Well <@${process.env.MY_USER_ID}>, your coding *${ops.d.project}* looks like...`;
|
||||
}
|
||||
break;
|
||||
case "active":
|
||||
if(app.is_at_school) {
|
||||
return `Hey <@${process.env.MY_USER_ID}>, are you still coding? LOCK IN NEON smh. those grades aint going up themselves.`
|
||||
} else if (its_late_at_night) {
|
||||
return `Hey <@${process.env.MY_USER_ID}>, are you still coding? are you finally eepy neon?`
|
||||
} else {
|
||||
return `Hey <@${process.env.MY_USER_ID}>, are you still coding? if not its about to be cancled.`
|
||||
}
|
||||
break;
|
||||
case "over":
|
||||
if(app.is_at_school) {
|
||||
return `Looks like your done coding rn <@${process.env.MY_USER_ID}>, you coded for a total of ${ms(Date.now() - ops.currentSession.created_at)}\n> now focus on ur school work`
|
||||
} else if (its_late_at_night) {
|
||||
return `Looks like your done coding rn <@${process.env.MY_USER_ID}>, you coded for a total of ${ms(Date.now() - ops.currentSession.created_at)}\n> now good night neon`
|
||||
} else {
|
||||
return `Looks like your done coding rn <@${process.env.MY_USER_ID}>, you coded for a total of ${ms(Date.now() - ops.currentSession.created_at)}`
|
||||
}
|
||||
if (app.is_at_school) {
|
||||
return `Hey <@${process.env.MY_USER_ID}>, are you still coding? LOCK IN NEON smh. those grades aint going up themselves.`;
|
||||
} else if (its_late_at_night) {
|
||||
return `Hey <@${process.env.MY_USER_ID}>, are you still coding? are you finally eepy neon?`;
|
||||
} else {
|
||||
return `Hey <@${process.env.MY_USER_ID}>, are you still coding? if not its about to be cancled.`;
|
||||
}
|
||||
break;
|
||||
case "over":
|
||||
if (app.is_at_school) {
|
||||
return `Looks like your done coding rn <@${process.env.MY_USER_ID}>, you coded for a total of ${ms(Date.now() - ops.currentSession.created_at)}\n> now focus on ur school work`;
|
||||
} else if (its_late_at_night) {
|
||||
return `Looks like your done coding rn <@${process.env.MY_USER_ID}>, you coded for a total of ${ms(Date.now() - ops.currentSession.created_at)}\n> now good night neon`;
|
||||
} else {
|
||||
return `Looks like your done coding rn <@${process.env.MY_USER_ID}>, you coded for a total of ${ms(Date.now() - ops.currentSession.created_at)}`;
|
||||
}
|
||||
}
|
||||
}
|
||||
// ok since i use terminal im gonna make it ignore that, otherwise its a copy of my other code
|
||||
setInterval(async() => {
|
||||
const userHacktimeDat = await fetch(`https://waka.hackclub.com/api/compat/wakatime/v1/users/${process.env.MY_USER_ID}/heartbeats?date=${new Date().toISOString().split('T')[0]}`, {
|
||||
headers: {
|
||||
Authorization: `Basic ${process.env.ENC_HACKTIME_TOKEN}`,
|
||||
"Accept": "application/json",
|
||||
"Content-Type": "application/json"
|
||||
}
|
||||
}).then(r=>r.json()).then(r=>r.data)
|
||||
const currentSession = app.db.get(`hackedhearts`)
|
||||
if(userHacktimeDat.length > 0) {
|
||||
const d = userHacktimeDat.filter(e=>e.category === "coding" && e.project !== "Terminal").find(e => isWithinLastTwoMinutes(new Date(e.created_at).getTime()))
|
||||
console.log(d)
|
||||
if(d) {
|
||||
console.log(0)
|
||||
// console.log(`um heartbat???`, d)
|
||||
if(!currentSession) {
|
||||
app.client.chat.postMessage({
|
||||
channel: `C07R8DYAZMM`,
|
||||
text: getMessage("new", {d, currentSession})
|
||||
}).then(d=> {
|
||||
// heartStore.set(user.user, {
|
||||
// active: true,
|
||||
// m_ts: d.ts,
|
||||
// created_at: Date.now()
|
||||
// })
|
||||
app.db.set(`hackedhearts`, {
|
||||
active: true,
|
||||
m_ts: d.ts,
|
||||
created_at: Date.now()
|
||||
})
|
||||
})
|
||||
} else {
|
||||
app.db.set("hackedhearts", {
|
||||
...currentSession,
|
||||
active: true
|
||||
// ...currentSession,
|
||||
})
|
||||
}
|
||||
}
|
||||
else {
|
||||
console.debug(1)
|
||||
if(currentSession) {
|
||||
// check if still "active"
|
||||
if(currentSession.active) {
|
||||
// set to not be active
|
||||
// pretty much this is a warning: if there is no new heartbeat im nuking it.
|
||||
console.log("hmmm")
|
||||
app.db.set("hackedhearts", {
|
||||
...currentSession,
|
||||
active: false
|
||||
// ...currentSession,
|
||||
})
|
||||
app.client.chat.postMessage({
|
||||
channel: `C07R8DYAZMM`,
|
||||
text: getMessage("active", {d, currentSession}),
|
||||
thread_ts: currentSession.m_ts,
|
||||
// reply_broadcast: true
|
||||
})
|
||||
} else{
|
||||
console.log("over")
|
||||
// send time up message
|
||||
app.client.chat.postMessage({
|
||||
channel: `C07R8DYAZMM`,
|
||||
text: getMessage("over", {d, currentSession}),
|
||||
thread_ts: currentSession.m_ts,
|
||||
reply_broadcast: true
|
||||
})
|
||||
// delete it
|
||||
setInterval(async () => {
|
||||
const userHacktimeDat = await fetch(
|
||||
`https://waka.hackclub.com/api/compat/wakatime/v1/users/${process.env.MY_USER_ID}/heartbeats?date=${new Date().toISOString().split("T")[0]}`,
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Basic ${process.env.ENC_HACKTIME_TOKEN}`,
|
||||
Accept: "application/json",
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
},
|
||||
)
|
||||
.then((r) => r.json())
|
||||
.then((r) => r.data);
|
||||
const currentSession = app.db.get(`hackedhearts`);
|
||||
if (userHacktimeDat.length > 0) {
|
||||
const d = userHacktimeDat
|
||||
.filter((e) => e.category === "coding" && e.project !== "Terminal")
|
||||
.find((e) => isWithinLastTwoMinutes(new Date(e.created_at).getTime()));
|
||||
console.log(d);
|
||||
if (d) {
|
||||
console.log(0);
|
||||
// console.log(`um heartbat???`, d)
|
||||
if (!currentSession) {
|
||||
app.client.chat
|
||||
.postMessage({
|
||||
channel: `C07R8DYAZMM`,
|
||||
text: getMessage("new", { d, currentSession }),
|
||||
})
|
||||
.then((d) => {
|
||||
// heartStore.set(user.user, {
|
||||
// active: true,
|
||||
// m_ts: d.ts,
|
||||
// created_at: Date.now()
|
||||
// })
|
||||
app.db.set(`hackedhearts`, {
|
||||
active: true,
|
||||
m_ts: d.ts,
|
||||
created_at: Date.now(),
|
||||
});
|
||||
});
|
||||
} else {
|
||||
app.db.set("hackedhearts", {
|
||||
...currentSession,
|
||||
active: true,
|
||||
// ...currentSession,
|
||||
});
|
||||
}
|
||||
} else {
|
||||
console.debug(1);
|
||||
if (currentSession) {
|
||||
// check if still "active"
|
||||
if (currentSession.active) {
|
||||
// set to not be active
|
||||
// pretty much this is a warning: if there is no new heartbeat im nuking it.
|
||||
console.log("hmmm");
|
||||
app.db.set("hackedhearts", {
|
||||
...currentSession,
|
||||
active: false,
|
||||
// ...currentSession,
|
||||
});
|
||||
app.client.chat.postMessage({
|
||||
channel: `C07R8DYAZMM`,
|
||||
text: getMessage("active", { d, currentSession }),
|
||||
thread_ts: currentSession.m_ts,
|
||||
// reply_broadcast: true
|
||||
});
|
||||
} else {
|
||||
console.log("over");
|
||||
// send time up message
|
||||
app.client.chat.postMessage({
|
||||
channel: `C07R8DYAZMM`,
|
||||
text: getMessage("over", { d, currentSession }),
|
||||
thread_ts: currentSession.m_ts,
|
||||
reply_broadcast: true,
|
||||
});
|
||||
// delete it
|
||||
// heartStore.delete(user.user)
|
||||
app.db.delete(`hackedhearts`)
|
||||
}
|
||||
}
|
||||
app.db.delete(`hackedhearts`);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// console.log(userHacktimeDat)
|
||||
}, 1000 * 60)
|
||||
// console.log(userHacktimeDat)
|
||||
}, 1000 * 60);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue