Skip to content

Commit

Permalink
Remove incorrect job invocation, improve console output
Browse files Browse the repository at this point in the history
  • Loading branch information
fsvreddit committed Oct 15, 2024
1 parent e8f4150 commit d250cbe
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
2 changes: 1 addition & 1 deletion devvit.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
name: social-links-bot
version: 0.0.4
version: 0.0.5
14 changes: 4 additions & 10 deletions src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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}`);
Expand All @@ -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);
Expand All @@ -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);
},
});

Expand Down

0 comments on commit d250cbe

Please sign in to comment.