From 379099dc7af05446d5fc0dbac03f6df11f34afa8 Mon Sep 17 00:00:00 2001 From: matty Date: Tue, 1 Jul 2025 15:30:33 -0400 Subject: [PATCH] remove unused code, add try/catch block --- src/main.ts | 57 +++++++++++++---------------------------------------- 1 file changed, 14 insertions(+), 43 deletions(-) diff --git a/src/main.ts b/src/main.ts index f6c5593..56cab7a 100644 --- a/src/main.ts +++ b/src/main.ts @@ -11,28 +11,6 @@ import { createWebsocket } from "./websocket.js"; const prisma = new PrismaClient(); -// const getNotifications = async () => { -// try { -// const request = await fetch( -// `${process.env.PLEROMA_INSTANCE_URL}/api/v1/notifications?types[]=mention`, -// { -// method: "GET", -// headers: { -// Authorization: `Bearer ${process.env.INSTANCE_BEARER_TOKEN}`, -// }, -// } -// ); - -// const notifications: Notification[] = await request.json(); - -// return notifications; -// } catch (error: any) { -// throw new Error(error.message); -// } -// }; - -// const notifications = await getNotifications(); - const storeUserData = async (notification: Notification): Promise => { try { await prisma.user.upsert({ @@ -182,26 +160,19 @@ ws.on("upgrade", () => { }); ws.on("message", async (data) => { - const message: WSEvent = JSON.parse(data.toString("utf-8")); - if (message.event !== "notification") { - // only watch for notification events - return; - } - console.log("Websocket message received."); - const payload = JSON.parse(message.payload) as Notification; - const ollamaResponse = await generateOllamaRequest(payload); - if (ollamaResponse) { - await postReplyToStatus(payload, ollamaResponse); + try { + const message: WSEvent = JSON.parse(data.toString("utf-8")); + if (message.event !== "notification") { + // only watch for notification events + return; + } + console.log("Websocket message received."); + const payload = JSON.parse(message.payload) as Notification; + const ollamaResponse = await generateOllamaRequest(payload); + if (ollamaResponse) { + await postReplyToStatus(payload, ollamaResponse); + } + } catch (error: any) { + console.error(error.message); } }); - -// if (notifications) { -// await Promise.all( -// notifications.map(async (notification) => { -// const ollamaResponse = await generateOllamaRequest(notification); -// if (ollamaResponse) { -// postReplyToStatus(notification, ollamaResponse); -// } -// }) -// ); -// }