From d250cbee5f37fd7a210d7c0f8fd92605b9a2ffd9 Mon Sep 17 00:00:00 2001 From: fsvreddit <97185438+fsvreddit@users.noreply.github.com> Date: Tue, 15 Oct 2024 13:00:55 +0100 Subject: [PATCH] Remove incorrect job invocation, improve console output --- devvit.yaml | 2 +- src/main.tsx | 14 ++++---------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/devvit.yaml b/devvit.yaml index 8eba509..b86d6a4 100644 --- a/devvit.yaml +++ b/devvit.yaml @@ -1,2 +1,2 @@ name: social-links-bot -version: 0.0.4 +version: 0.0.5 diff --git a/src/main.tsx b/src/main.tsx index a56d857..ab8acdb 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -2,7 +2,7 @@ import { Devvit, TriggerContext, User, UserSocialLink } from "@devvit/public-api"; import { isLinkId } from "@devvit/shared-types/tid.js"; -import { addDays, addHours } from "date-fns"; +import { addHours } from "date-fns"; import _ from "lodash"; enum AppSetting { @@ -54,7 +54,7 @@ async function getSocialLinksForUser (username: string, context: TriggerContext) Devvit.addSchedulerJob({ name: "cleanupJob", - onRun: async (event, context) => { + onRun: async (_, context) => { const commentsToDelete = (await context.redis.zRange(CLEANUP_KEY, 0, new Date().getTime(), { by: "score" })).map(x => x.member); if (commentsToDelete.length === 0) { return; @@ -106,7 +106,6 @@ Devvit.addTrigger({ } const accountNames = accountNamesVal.split(",").map(accountName => accountName.trim().toLowerCase()); - console.log(accountNames); if (!accountNames.includes(event.author.name.toLowerCase())) { console.log(`Wrong user: Got ${event.author.name}`); @@ -119,7 +118,6 @@ Devvit.addTrigger({ } const userList = _.uniq(JSON.parse(event.comment.body) as string[]); - console.log(userList); const userSocialLinks: UserSocialLinks[] = []; for (const user of userList) { const userSocials = await getSocialLinksForUser(user, context); @@ -137,13 +135,9 @@ Devvit.addTrigger({ text: JSON.stringify(userSocialLinks), }); - await addCleanup(event.comment.id, context); + console.log("Comment left."); - await context.scheduler.runJob({ - name: "deleteCommentAfterOneDay", - runAt: addDays(new Date(), 1), - data: { commentId: event.comment.id }, - }); + await addCleanup(event.comment.id, context); }, });