Skip to content
This repository has been archived by the owner on Oct 10, 2024. It is now read-only.

Commit

Permalink
fix: remove URLs from content before checking for banned words (#816)
Browse files Browse the repository at this point in the history
* fix: remove URLs from content before checking for banned words

* fix: updated url pattern

* fix: urlregex fix
  • Loading branch information
Bashamega authored Jul 28, 2024
1 parent 9fc6b25 commit 21f59e3
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/alexjs/checkBannedWords.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { ExtendedClient } from '../interfaces/ExtendedClient.js';
import { errorHandler } from '../utils/errorHandler.js';
import { BannedWordsOptions } from '../config/BannedWordsOptions.js';
import { getBannedWordConfig } from '../utils/getBannedWordConfig.js';
import { urlPattern } from '../config/UrlRegex.js';

export const checkBannedWords = async (
bot: ExtendedClient,
Expand All @@ -12,11 +13,13 @@ export const checkBannedWords = async (
): Promise<EmbedBuilder[]> => {
const embeds: EmbedBuilder[] = [];
try {
const text: string = content.replace(urlPattern, '');
const config = await getBannedWordConfig(bot, serverId);
const checkWords = config?.bannedWordConfig
? config.bannedWordConfig
: BannedWordsOptions;
content.split(' ').forEach((word) => {

text.split(' ').forEach((word) => {
if (checkWords.includes(word.toLowerCase())) {
const embed = new EmbedBuilder();
embed.setTitle(`You used the word "${word}"`);
Expand Down
2 changes: 2 additions & 0 deletions src/config/UrlRegex.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const urlPattern =
/[Hh][Tt][Tt][Pp][Ss]?:\/\/([\w-]+(\.[\w-]+)+)(\/[\w-./?%&=]*)?/g;
3 changes: 1 addition & 2 deletions src/links/checkLinks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ import { EmbedBuilder, Message, type PartialMessage } from 'discord.js';

import type { ExtendedClient } from '../interfaces/ExtendedClient.js';
import { errorHandler } from '../utils/errorHandler.js';
import { urlPattern } from '../config/UrlRegex.js';

const allowedLinks = ['github.com', 'eddiejaoude.io', 'gitlab.com'];
const urlPattern =
/[Hh][Tt][Tt][Pp][Ss]?:\/\/([\w-]+(\.[\w-]+)+)(\/[\w-./?%&=]*)?/g;

export const checkLinks = async (
bot: ExtendedClient,
Expand Down

0 comments on commit 21f59e3

Please sign in to comment.