Skip to content

Commit 969ff78

Browse files
Scttprpotb
authored andcommitted
fix: utf8 char breaks quoifeur (#93)
1 parent ac121fe commit 969ff78

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/helpers/regex.helper.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ const socialNetworksUrlRegex = new RegExp(
44
const punctuationRegex = /[.,!?]/g;
55
const markdownRegex = /(\*\*|__|\*|_|`|~)(.*?)\1/g;
66
const emojiRegex = /<a?:.+?:\d{10,30}>|\p{Extended_Pictographic}/gu;
7+
const nonASCIIRegex = /[\u{007F}-\u{FFFF}]/gu;
78

89
export const isASocialNetworkUrl = (url: string): boolean => {
910
return socialNetworksUrlRegex.test(url);
1011
};
1112

1213
export const removePunctuation = (text: string) => text.replaceAll(punctuationRegex, '');
1314
export const removeEmoji = (text: string) => text.replaceAll(emojiRegex, '');
15+
export const removeNonASCII = (text: string) => text.replaceAll(nonASCIIRegex, '');
1416
export const removeMarkdown = (text: string) => text.replaceAll(markdownRegex, '$2');

src/modules/quoiFeur/quoiFeur.helpers.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,18 @@ import {
77
} from 'discord.js';
88

99
import { cache } from '../../core/cache';
10-
import { removeEmoji, removeMarkdown, removePunctuation } from '../../helpers/regex.helper';
10+
import {
11+
removeEmoji,
12+
removeMarkdown,
13+
removeNonASCII,
14+
removePunctuation,
15+
} from '../../helpers/regex.helper';
1116

1217
const ONE_MINUTE = 1 * 60 * 1000;
1318

1419
const quoiDetectorRegex = /\bquoi\s*$/i;
1520
const endWithQuoi = (text: string) =>
16-
quoiDetectorRegex.test(removeEmoji(removePunctuation(removeMarkdown(text))));
21+
quoiDetectorRegex.test(removeNonASCII(removeEmoji(removePunctuation(removeMarkdown(text)))));
1722

1823
const reactWith = async (message: Message, reactions: string[]) => {
1924
for (const reaction of reactions) {

0 commit comments

Comments
 (0)