Skip to content

Commit a73f239

Browse files
dilaouidpotb
andcommitted
fix(quoi-feur): check if the trigger word is formatted in md (#68)
Co-authored-by: Peïo Thibault <[email protected]>
1 parent 23e7c98 commit a73f239

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

src/__tests__/regex.spec.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { describe, expect, it } from 'vitest';
22

3-
import { isASocialNetworkUrl, removeEmoji } from '../helpers/regex.helper';
3+
import { isASocialNetworkUrl, removeEmoji, removeMarkdown } from '../helpers/regex.helper';
44

55
describe('Helpers: Regex', () => {
66
describe('Rule: isASocialNetworkUrl should regex correctly an url', () => {
@@ -22,4 +22,11 @@ describe('Helpers: Regex', () => {
2222
expect(result).toBe(' Hello, World!');
2323
});
2424
});
25+
describe('Rule: removeMarkdown should remove all markdown from a string', () => {
26+
it('removeMarkdown() should remove all markdown from a string', () => {
27+
const text = 'Hello, **World!** This is _me_ I **give** you `reactions` and ~more~ **quoi**';
28+
const result = removeMarkdown(text);
29+
expect(result).toBe('Hello, World! This is me I give you reactions and more quoi');
30+
});
31+
});
2532
});

src/helpers/regex.helper.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const socialNetworksUrlRegex = new RegExp(
22
'^(https?://)?(www.)?(facebook.com|fb.me|twitter.com|vxtwitter.com|instagram.com|linkedin.com|youtube.com|youtu.be|pinterest.com|snapchat.com|tiktok.com)/[a-zA-Z0-9.-/?=&#_]+$',
33
);
44
const punctuationRegex = /[.,!?]/g;
5+
const markdownRegex = /(\*\*|__|\*|_|`|~)(.*?)\1/g;
56
const emojiRegex = /<a?:.+?:\d{10,30}>|\p{Extended_Pictographic}/gu;
67

78
export const isASocialNetworkUrl = (url: string): boolean => {
@@ -10,3 +11,4 @@ export const isASocialNetworkUrl = (url: string): boolean => {
1011

1112
export const removePunctuation = (text: string) => text.replaceAll(punctuationRegex, '');
1213
export const removeEmoji = (text: string) => text.replaceAll(emojiRegex, '');
14+
export const removeMarkdown = (text: string) => text.replaceAll(markdownRegex, '$2');

src/modules/quoiFeur/quoiFeur.helpers.ts

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

99
import { cache } from '../../core/cache';
10-
import { removeEmoji, removePunctuation } from '../../helpers/regex.helper';
10+
import { removeEmoji, removeMarkdown, removePunctuation } from '../../helpers/regex.helper';
1111

1212
const ONE_MINUTE = 1 * 60 * 1000;
1313

1414
const quoiDetectorRegex = /\bquoi\s*$/i;
15-
const endWithQuoi = (text: string) => quoiDetectorRegex.test(removeEmoji(removePunctuation(text)));
15+
const endWithQuoi = (text: string) =>
16+
quoiDetectorRegex.test(removeEmoji(removePunctuation(removeMarkdown(text))));
1617

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

0 commit comments

Comments
 (0)