diff --git a/src/index.ts b/src/index.ts index 2c90dbd..5614f7a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,6 @@ import "dotenv/config"; import "./modules/sentry"; -import * as Sentry from "@sentry/node" +import * as Sentry from "@sentry/node"; import init from "./modules/watch-git"; // import "./modules/smee" import app from "./modules/slackapp"; @@ -67,26 +67,29 @@ function handleError(e: any) { } catch (e) {} } function updateStatus(emoji: string, str: string, clearStats?: boolean) { - Sentry.startSpan({ - op: "prod", - name: "Update Status", - }, () => { - // Sentry.profiler.startProfiler(); - app.client.users.profile.set({ - //@ts-ignore - profile: clearStats - ? { - status_emoji: "", - status_text: "", - } - : { - status_emoji: emoji, - status_expiration: 0, - status_text: str.slice(0, 100), - }, - token: process.env.MY_SLACK_TOKEN, - }); - }); + Sentry.startSpan( + { + op: "prod", + name: "Update Status", + }, + () => { + // Sentry.profiler.startProfiler(); + app.client.users.profile.set({ + //@ts-ignore + profile: clearStats + ? { + status_emoji: "", + status_text: "", + } + : { + status_emoji: emoji, + status_expiration: 0, + status_text: str.slice(0, 100), + }, + token: process.env.MY_SLACK_TOKEN, + }); + }, + ); // Sentry.profiler.stopProfiler(); } cron.schedule("* * * * *", async () => { @@ -98,7 +101,7 @@ cron.schedule("* * * * *", async () => { updateStatus(":jellyfin:", jellyfinStr); } else if (spotifyStr) { cached_spotify_songs.push(spotifyStr); - app.db.set("spotify_songs", cached_spotify_songs) + app.db.set("spotify_songs", cached_spotify_songs); updateStatus(":new_spotify:", spotifyStr); } else { // clear status @@ -114,23 +117,26 @@ cron.schedule("* * * * *", async () => { // set away if in any focus mode }); async function sendRandomStuff() { - Sentry.startSpan({ - op: "prod", - name: "Send Random Stuff", - }, async () => { - // dont send bot after bot ... - const lastMessage = await app.client.conversations - .history({ - channel: "C07R8DYAZMM", - }) - .then((e) => e.messages[0]); - if (lastMessage.user === "U07LEF1PBTM") return; // ^^ - app.client.chat.postMessage({ - channel: "C07R8DYAZMM", - //@ts-ignore - text: await getResponse(db), - }); - }); + Sentry.startSpan( + { + op: "prod", + name: "Send Random Stuff", + }, + async () => { + // dont send bot after bot ... + const lastMessage = await app.client.conversations + .history({ + channel: "C07R8DYAZMM", + }) + .then((e) => e.messages[0]); + if (lastMessage.user === "U07LEF1PBTM") return; // ^^ + app.client.chat.postMessage({ + channel: "C07R8DYAZMM", + //@ts-ignore + text: await getResponse(db), + }); + }, + ); } //utils.startWatchingDirectory(app); cron.schedule("5 */12 * * *", sendRandomStuff); @@ -138,51 +144,57 @@ cron.schedule("25 */22 * * *", sendRandomStuff); cron.schedule("15 */3 * * *", sendRandomStuff); cron.schedule("45 2 */2 * *", sendRandomStuff); cron.schedule("35 20 * * *", async () => { - Sentry.profiler.startProfiler() -await howWasYourDay(app); -Sentry.profiler.stopProfiler() + Sentry.profiler.startProfiler(); + await howWasYourDay(app); + Sentry.profiler.stopProfiler(); }); cron.schedule("1 7 * * 1-5", async () => { - Sentry.startSpan({ - op: "prod", - name: "Morning Cron - school", - }, async () => { - const hw = await getTodaysEvents().then((e: any) => { - const start = []; - const end = []; - //@ts-ignore - e.forEach((e) => { - if (e.assign_type == "start") start.push(e.summary); - if (e.assign_type == "end") end.push(e.summary); - }); - if (start.length > 0 || end.length > 0) { - return `Assigned today:\n> ${start.join("\n> ")}\n*Due Today*\n> ${end.join("\n> ")}`; - } else { - return `No HW found :yay:`; - } - }); - app.client.chat.postMessage({ - channel: "C07R8DYAZMM", - //@ts-ignore - text: `Good Morning :D! Wake up <@${process.env.MY_USER_ID}> your ass needs to get ready for school now!.\n> ${hw}`, - }); -}) + Sentry.startSpan( + { + op: "prod", + name: "Morning Cron - school", + }, + async () => { + const hw = await getTodaysEvents().then((e: any) => { + const start = []; + const end = []; + //@ts-ignore + e.forEach((e) => { + if (e.assign_type == "start") start.push(e.summary); + if (e.assign_type == "end") end.push(e.summary); + }); + if (start.length > 0 || end.length > 0) { + return `Assigned today:\n> ${start.join("\n> ")}\n*Due Today*\n> ${end.join("\n> ")}`; + } else { + return `No HW found :yay:`; + } + }); + app.client.chat.postMessage({ + channel: "C07R8DYAZMM", + //@ts-ignore + text: `Good Morning :D! Wake up <@${process.env.MY_USER_ID}> your ass needs to get ready for school now!.\n> ${hw}`, + }); + }, + ); }); // special cron cron.schedule("1 9 * * 6-7", () => { - Sentry.startSpan({ - op: "prod", - name: "Morning Cron - weekend", - }, async () => { - const d = new Date(); - if (![6, 7].includes(d.getDay())) return; - const isSaturday = d.getDay() === 6; - app.client.chat.postMessage({ - channel: "C07R8DYAZMM", - //@ts-ignore - text: `Good Morning :D! dont wake up since i bet ur ass only went to sleep like 4 hours ago :P.${isSaturday ? "\n> You should be at robotics tho..." : ""}`, - }); - }); + Sentry.startSpan( + { + op: "prod", + name: "Morning Cron - weekend", + }, + async () => { + const d = new Date(); + if (![6, 7].includes(d.getDay())) return; + const isSaturday = d.getDay() === 6; + app.client.chat.postMessage({ + channel: "C07R8DYAZMM", + //@ts-ignore + text: `Good Morning :D! dont wake up since i bet ur ass only went to sleep like 4 hours ago :P.${isSaturday ? "\n> You should be at robotics tho..." : ""}`, + }); + }, + ); }); process.on("unhandledRejection", handleError); process.on("unhandledException", handleError);