Skip to content

Commit 9186ef8

Browse files
authored
chore: removed deletion, and added detailed logging. (#493)
1 parent 87e9edb commit 9186ef8

File tree

1 file changed

+10
-31
lines changed

1 file changed

+10
-31
lines changed

src/features/job-scanner.ts

Lines changed: 10 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
import type { ChannelHandlers } from "../types/index.js";
2-
import { EmbedType } from "discord.js";
3-
4-
import { CHANNELS } from "../constants/channels.js";
5-
import { EMBED_COLOR } from "./commands.js";
62
import { isStaff, isHelpful } from "../helpers/discord.js";
73
import { logger } from "./log.js";
84

@@ -52,38 +48,21 @@ export const jobScanner: ChannelHandlers = {
5248

5349
const content = msg.content.toLowerCase();
5450
const ignoreDollar = hasCodeBlockWithDollarSign(content);
55-
const hasCurrencyKeyword =
56-
!ignoreDollar &&
57-
currencyKeywords.some((keyword) => content.includes(keyword));
5851

52+
const currencyMatches = !ignoreDollar
53+
? currencyKeywords.filter((keyword) => content.includes(keyword))
54+
: [];
5955
const keywordRegex = new RegExp(`\\b(${jobKeywords.join("|")})\\b`, "i");
60-
const containsJobKeyword = keywordRegex.test(content);
61-
if (!containsJobKeyword && !hasCurrencyKeyword) return;
56+
const jobKeywordMatches = content.match(keywordRegex) || [];
57+
const uniqueJobKeywordMatches = new Set([...jobKeywordMatches]);
6258

63-
const warningMsg = `Oops <@${msg.author.id}>! This message looks more like a job/collaboration/advice post. Mind sharing that in <#${CHANNELS.jobBoard}> or <#${CHANNELS.lookingForGroup}> or <#${CHANNELS.jobsAdvice}> instead? If this was a mistake, please try again and ask your question. Appreciate you helping us keep channels on-topic.`;
64-
const sentMsg = await msg.reply({
65-
embeds: [
66-
{
67-
title: "Oops! Wrong Channel, Maybe?",
68-
type: EmbedType.Rich,
69-
description: warningMsg,
70-
color: EMBED_COLOR,
71-
},
72-
],
73-
});
59+
if (currencyMatches.length === 0 && jobKeywordMatches.length === 0) return;
7460
logger.log(
7561
"job keyword detected",
76-
`${msg.author.username} in <#${msg.channel.id}> \n${msg.content}`,
62+
`${msg.author.username} in <#${msg.channel.id}> \n*Content:* ${msg.content} \n*Matched Keywords:* ${[
63+
...currencyMatches,
64+
...uniqueJobKeywordMatches,
65+
].join(", ")}`,
7766
);
78-
await msg
79-
.delete()
80-
.catch((e) => logger.log("failed to delete job posting message", e));
81-
setTimeout(() => {
82-
sentMsg
83-
.delete()
84-
.catch((e) =>
85-
logger.log("failed to delete auto reply to a job posting message", e),
86-
);
87-
}, 30_000);
8867
},
8968
};

0 commit comments

Comments
 (0)