|
1 | 1 | 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"; |
6 | 2 | import { isStaff, isHelpful } from "../helpers/discord.js"; |
7 | 3 | import { logger } from "./log.js"; |
8 | 4 |
|
@@ -52,38 +48,21 @@ export const jobScanner: ChannelHandlers = { |
52 | 48 |
|
53 | 49 | const content = msg.content.toLowerCase(); |
54 | 50 | const ignoreDollar = hasCodeBlockWithDollarSign(content); |
55 | | - const hasCurrencyKeyword = |
56 | | - !ignoreDollar && |
57 | | - currencyKeywords.some((keyword) => content.includes(keyword)); |
58 | 51 |
|
| 52 | + const currencyMatches = !ignoreDollar |
| 53 | + ? currencyKeywords.filter((keyword) => content.includes(keyword)) |
| 54 | + : []; |
59 | 55 | 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]); |
62 | 58 |
|
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; |
74 | 60 | logger.log( |
75 | 61 | "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(", ")}`, |
77 | 66 | ); |
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); |
88 | 67 | }, |
89 | 68 | }; |
0 commit comments