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

Commit 0a7298a

Browse files
Vyvy-viAllanRegush
andauthored
feat(words): optimised word filter (#379)
* feat: optimised word filter(alex) * feat: added <> to the regex * suggestion: added function for the regex * fix: altered regex Co-authored-by: Allan Regush <[email protected]>
1 parent a6e2395 commit 0a7298a

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/words.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,11 @@ export const words = async (message: Message) => {
1717
return;
1818
}
1919

20-
const match = alex.markdown(message.content, ALEX as alex.Config).messages;
21-
20+
// Regex to remove puntuation from text
21+
const match = alex.markdown(
22+
stripSpecialCharacters(message.content),
23+
ALEX as alex.Config
24+
).messages;
2225
if (match.length) {
2326
const embed = defaultEmbed(config.COLORS.alerts)
2427
.setTitle(`You used the word "${match[0].actual}"`)
@@ -36,3 +39,11 @@ export const words = async (message: Message) => {
3639

3740
return;
3841
};
42+
43+
// Utility function for removing special characters
44+
function stripSpecialCharacters(str: string) {
45+
// match special symbols and replace with ' '
46+
str = str.replace(/[.,/#!$%&*;:{}=\-_'"~()]/g, ' ');
47+
// match double whitespace with single space for cleaner string
48+
return str.replace(/\s{2,}/g, ' ');
49+
}

0 commit comments

Comments
 (0)