-
Notifications
You must be signed in to change notification settings - Fork 42
feat(experimental): added a job/introduction bot detection #461
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
1861c17
update: added more channels
Simplyalex99 01a025f
feat: added a job/introduction bot scanner
Simplyalex99 8c57191
update: added more job keywords
Simplyalex99 5cd67b2
update: removed job titles keywords and edge case
Simplyalex99 71f08ae
update: removed unneeded edge case
Simplyalex99 a2e6162
update: warning message
Simplyalex99 47d96c4
update: added edge case for langs with dollar sign
Simplyalex99 ee737d8
fix: messages being deleted with partial job keywords rather than full.
Simplyalex99 3ff72f5
fix: removed duplicate job keyword
Simplyalex99 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| import type { ChannelHandlers } from "../types/index.d.ts"; | ||
| import { EmbedType } from "discord.js"; | ||
|
|
||
| import { CHANNELS } from "../constants/channels.js"; | ||
| import { EMBED_COLOR } from "./commands.js"; | ||
|
|
||
| const jobKeywords = [ | ||
| "looking for work", | ||
| "seeking opportunities", | ||
| "available for hire", | ||
| "open to work", | ||
| "freelance available", | ||
| "seeking a role", | ||
| "looking for projects", | ||
| "hire me", | ||
| "job opportunities", | ||
| "job offer", | ||
| "job opportunity", | ||
| "contact me", | ||
| "actively seeking", | ||
| "available for freelance", | ||
| "remote position", | ||
| "dm me", | ||
| "reach out", | ||
| "ready to join", | ||
| "new opportunity", | ||
| "open position", | ||
| "seeking remote", | ||
| "available now", | ||
| "remote role", | ||
| "remote opportunity", | ||
| "full-time", | ||
| "job opportunities", | ||
| "opportunities available", | ||
| "new opportunity", | ||
| "open for", | ||
| "we’re hiring", | ||
| "we are hiring", | ||
| ]; | ||
|
|
||
| const currencyKeywords = ["₹", "€", "$"]; | ||
| const hasCodeBlockWithDollarSign = (content: string): boolean => { | ||
| const codeBlockRegex = /```[\s\S]*?\$[\s\S]*?```/g; | ||
| return codeBlockRegex.test(content); | ||
| }; | ||
|
|
||
| export const messageScanner: ChannelHandlers = { | ||
| handleMessage: async ({ msg }) => { | ||
| if (msg.author.bot) return; | ||
|
|
||
| const content = msg.content.toLowerCase(); | ||
| const ignoreDollar = hasCodeBlockWithDollarSign(content); | ||
| const hasCurrencyKeyword = | ||
| !ignoreDollar && | ||
| currencyKeywords.some((keyword) => content.includes(keyword)); | ||
|
|
||
| const keywordRegex = new RegExp(`\\b(${jobKeywords.join("|")})\\b`, "i"); | ||
| const containsJobKeyword = keywordRegex.test(content); | ||
| if (!containsJobKeyword && !hasCurrencyKeyword) return; | ||
|
|
||
| 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 🙌`; | ||
| const sentMsg = await msg.reply({ | ||
| embeds: [ | ||
| { | ||
| title: "Oops! Wrong Channel, Maybe?", | ||
| type: EmbedType.Rich, | ||
| description: warningMsg, | ||
| color: EMBED_COLOR, | ||
| }, | ||
| ], | ||
| }); | ||
| await msg.delete(); | ||
| setTimeout(() => { | ||
| sentMsg.delete().catch(console.error); | ||
| }, 300_000); | ||
| }, | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.