Skip to content

Commit 3c6dfb2

Browse files
committed
update: merged commits into one
feat: added a job/introduction bot scanner update: added more job keywords update: removed job titles keywords and edge case Removed job title keyword to prevent false positives, and to keep the bot solely for job posting related messages rather than intro and job postings. Removed unneeded edge case that could result in false negatives. update: removed unneeded edge case update: warning message Added a more helpful feedback in case of job advice related posts using similar keywords such as full time or job opportunity. update: added edge case for langs with dollar sign Added an edge case for code blocks using dollar sign and refactored if statement. fix: messages being deleted with partial job keywords rather than full. fix: removed duplicate job keyword feat(experimental): added a job/introduction bot detection (#461) * update: added more channels * feat: added a job/introduction bot scanner * update: added more job keywords * update: removed job titles keywords and edge case Removed job title keyword to prevent false positives, and to keep the bot solely for job posting related messages rather than intro and job postings. Removed unneeded edge case that could result in false negatives. * update: removed unneeded edge case * update: warning message Added a more helpful feedback in case of job advice related posts using similar keywords such as full time or job opportunity. * update: added edge case for langs with dollar sign Added an edge case for code blocks using dollar sign and refactored if statement. * fix: messages being deleted with partial job keywords rather than full. * fix: removed duplicate job keyword Revert "feat(experimental): added a job/introduction bot detection (#461)" This reverts commit f946770. fix: Shared references causing auto thread to be added to new channels (#464) * fix: Shared references causing auto thread to be added to new channels * fix: removed print statement add: cross post command (#465) * add: cross post command * update: description text IS:00 fix: prettier lint issues (#470) update: organized channels , and removed introduction refactor: renamed feature to job scanner
1 parent 0b521fd commit 3c6dfb2

File tree

4 files changed

+125
-2
lines changed

4 files changed

+125
-2
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/commands.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,24 @@ const commandsList: Command[] = [
7373
});
7474
},
7575
},
76+
{
77+
words: [`!crosspost`],
78+
help: `provides a no cross-post message`,
79+
category: "Communication",
80+
handleMessage: (msg) => {
81+
msg.channel.send({
82+
embeds: [
83+
{
84+
title: "Please Avoid Cross-Posting",
85+
type: EmbedType.Rich,
86+
description:
87+
"Just a friendly reminder: please avoid posting the same message in multiple channels. Choose the channel that best fits your question and allow some time for a response. If you don’t hear back after a while, feel free to bump your message.",
88+
color: EMBED_COLOR,
89+
},
90+
],
91+
});
92+
},
93+
},
7694
{
7795
words: [`!promotion`],
7896
help: `informs user's of self-promotion guidelines`,

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: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import {
1111
IntentsBitField,
1212
} from "discord.js";
1313

14+
import { jobScanner } from "./features/job-scanner.js";
15+
1416
import { logger, channelLog } from "./features/log.js";
1517
// import codeblock from './features/codeblock';
1618
import jobsMod, { resetJobCacheCommand } from "./features/jobs-moderation.js";
@@ -125,9 +127,10 @@ const addHandler = (
125127
channels.forEach((channelId) => {
126128
const existingHandlers = channelHandlersById[channelId];
127129
if (existingHandlers) {
128-
existingHandlers.push(...handlers);
130+
// Create a new array to avoid mutating the existing one
131+
channelHandlersById[channelId] = [...existingHandlers, ...handlers];
129132
} else {
130-
channelHandlersById[channelId] = handlers;
133+
channelHandlersById[channelId] = [...handlers];
131134
}
132135
});
133136
};
@@ -205,6 +208,19 @@ addHandler(
205208
promotionThread,
206209
);
207210

211+
addHandler(
212+
[
213+
CHANNELS.helpReact,
214+
CHANNELS.helpJs,
215+
CHANNELS.helpReactNative,
216+
CHANNELS.helpStyling,
217+
CHANNELS.helpBackend,
218+
CHANNELS.generalReact,
219+
CHANNELS.generalTech,
220+
],
221+
jobScanner,
222+
);
223+
208224
const threadChannels = [CHANNELS.helpJs, CHANNELS.helpThreadsReact];
209225
addHandler(threadChannels, autothread);
210226

0 commit comments

Comments
 (0)