Skip to content

Commit 09392ff

Browse files
authored
feat(experimental): added job keywords detection [resubmitted after fix] (#471)
* add: new channels * feat: job scanner
1 parent 957c42e commit 09392ff

File tree

3 files changed

+102
-1
lines changed

3 files changed

+102
-1
lines changed

src/constants/channels.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@ import { guildId, isProd } from "../helpers/env.js";
44
const LOCAL_CHANNELS: Record<keyof typeof PRODUCTION_CHANNELS, string> = {
55
helpReact: "926931785219207301",
66
helpThreadsReact: "950790460857794620",
7+
helpReactNative: "1166062952084942940",
8+
helpStyling: "1166062952084942940",
79
helpJs: "950790460857794620",
10+
helpBackend: "1166062952084942940",
11+
generalReact: "1166062952084942940",
12+
jobsAdvice: "1166062952084942940",
13+
generalTech: "1166062952084942940",
814
random: "926931785219207301",
915
gaming: "926931785219207301",
1016
thanks: "926931785219207301",
@@ -25,7 +31,13 @@ const LOCAL_CHANNELS: Record<keyof typeof PRODUCTION_CHANNELS, string> = {
2531
const PRODUCTION_CHANNELS = {
2632
helpReact: "103696749012467712",
2733
helpThreadsReact: "902647189120118794",
34+
helpReactNative: "469170673533583361",
35+
helpStyling: "105765765117935616",
2836
helpJs: "565213527673929729",
37+
helpBackend: "145170347921113088",
38+
generalReact: "102860784329052160",
39+
jobsAdvice: "287623405946011648",
40+
generalTech: "547620660482932737",
2941
random: "103325358643752960",
3042
gaming: "509219336175747082",
3143
thanks: "798567961468076072",

src/features/job-scanner.ts

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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+
7+
const jobKeywords = [
8+
"looking for work",
9+
"seeking opportunities",
10+
"available for hire",
11+
"open to work",
12+
"freelance available",
13+
"seeking a role",
14+
"looking for projects",
15+
"hire me",
16+
"job opportunities",
17+
"job offer",
18+
"job opportunity",
19+
"contact me",
20+
"actively seeking",
21+
"available for freelance",
22+
"remote position",
23+
"dm me",
24+
"reach out",
25+
"ready to join",
26+
"new opportunity",
27+
"open position",
28+
"seeking remote",
29+
"available now",
30+
"remote role",
31+
"remote opportunity",
32+
"full-time",
33+
"job opportunities",
34+
"opportunities available",
35+
"new opportunity",
36+
"open for",
37+
"we’re hiring",
38+
"we are hiring",
39+
];
40+
41+
const currencyKeywords = ["₹", "€", "$"];
42+
const hasCodeBlockWithDollarSign = (content: string): boolean => {
43+
const codeBlockRegex = /```[\s\S]*?\$[\s\S]*?```/g;
44+
return codeBlockRegex.test(content);
45+
};
46+
47+
export const jobScanner: ChannelHandlers = {
48+
handleMessage: async ({ msg }) => {
49+
if (msg.author.bot) return;
50+
51+
const content = msg.content.toLowerCase();
52+
const ignoreDollar = hasCodeBlockWithDollarSign(content);
53+
const hasCurrencyKeyword =
54+
!ignoreDollar &&
55+
currencyKeywords.some((keyword) => content.includes(keyword));
56+
57+
const keywordRegex = new RegExp(`\\b(${jobKeywords.join("|")})\\b`, "i");
58+
const containsJobKeyword = keywordRegex.test(content);
59+
if (!containsJobKeyword && !hasCurrencyKeyword) return;
60+
61+
const warningMsg = `Oops <@${msg.author.id}>! This message looks more like a job/collaboration/advice post. Mind sharing that in <#${CHANNELS.jobsLog}> 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.`;
62+
const sentMsg = await msg.reply({
63+
embeds: [
64+
{
65+
title: "Oops! Wrong Channel, Maybe?",
66+
type: EmbedType.Rich,
67+
description: warningMsg,
68+
color: EMBED_COLOR,
69+
},
70+
],
71+
});
72+
await msg.delete().catch(console.error);
73+
setTimeout(() => {
74+
sentMsg.delete().catch(console.error);
75+
}, 300_000);
76+
},
77+
};

src/index.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import {
4141
import { recommendBookCommand } from "./features/book-list.js";
4242
import { mdnSearch } from "./features/mdn.js";
4343
import "./server.js";
44+
import { jobScanner } from "./features/job-scanner.js";
4445

4546
export const bot = new Client({
4647
intents: [
@@ -205,7 +206,18 @@ addHandler(
205206
],
206207
promotionThread,
207208
);
208-
209+
addHandler(
210+
[
211+
CHANNELS.helpReact,
212+
CHANNELS.helpJs,
213+
CHANNELS.helpReactNative,
214+
CHANNELS.helpStyling,
215+
CHANNELS.helpBackend,
216+
CHANNELS.generalReact,
217+
CHANNELS.generalTech,
218+
],
219+
jobScanner,
220+
);
209221
const threadChannels = [CHANNELS.helpJs, CHANNELS.helpThreadsReact];
210222
addHandler(threadChannels, autothread);
211223

0 commit comments

Comments
 (0)