File tree 3 files changed +13
-3
lines changed
3 files changed +13
-3
lines changed Original file line number Diff line number Diff line change 1
1
import { describe , expect , it } from 'vitest' ;
2
2
3
- import { isASocialNetworkUrl , removeEmoji } from '../helpers/regex.helper' ;
3
+ import { isASocialNetworkUrl , removeEmoji , removeMarkdown } from '../helpers/regex.helper' ;
4
4
5
5
describe ( 'Helpers: Regex' , ( ) => {
6
6
describe ( 'Rule: isASocialNetworkUrl should regex correctly an url' , ( ) => {
@@ -22,4 +22,11 @@ describe('Helpers: Regex', () => {
22
22
expect ( result ) . toBe ( ' Hello, World!' ) ;
23
23
} ) ;
24
24
} ) ;
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
+ } ) ;
25
32
} ) ;
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ const socialNetworksUrlRegex = new RegExp(
2
2
'^(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.-/?=&#_]+$' ,
3
3
) ;
4
4
const punctuationRegex = / [ . , ! ? ] / g;
5
+ const markdownRegex = / ( \* \* | _ _ | \* | _ | ` | ~ ) ( .* ?) \1/ g;
5
6
const emojiRegex = / < a ? : .+ ?: \d { 10 , 30 } > | \p{ Extended_Pictographic} / gu;
6
7
7
8
export const isASocialNetworkUrl = ( url : string ) : boolean => {
@@ -10,3 +11,4 @@ export const isASocialNetworkUrl = (url: string): boolean => {
10
11
11
12
export const removePunctuation = ( text : string ) => text . replaceAll ( punctuationRegex , '' ) ;
12
13
export const removeEmoji = ( text : string ) => text . replaceAll ( emojiRegex , '' ) ;
14
+ export const removeMarkdown = ( text : string ) => text . replaceAll ( markdownRegex , '$2' ) ;
Original file line number Diff line number Diff line change @@ -7,12 +7,13 @@ import {
7
7
} from 'discord.js' ;
8
8
9
9
import { cache } from '../../core/cache' ;
10
- import { removeEmoji , removePunctuation } from '../../helpers/regex.helper' ;
10
+ import { removeEmoji , removeMarkdown , removePunctuation } from '../../helpers/regex.helper' ;
11
11
12
12
const ONE_MINUTE = 1 * 60 * 1000 ;
13
13
14
14
const quoiDetectorRegex = / \b q u o i \s * $ / i;
15
- const endWithQuoi = ( text : string ) => quoiDetectorRegex . test ( removeEmoji ( removePunctuation ( text ) ) ) ;
15
+ const endWithQuoi = ( text : string ) =>
16
+ quoiDetectorRegex . test ( removeEmoji ( removePunctuation ( removeMarkdown ( text ) ) ) ) ;
16
17
17
18
const reactWith = async ( message : Message , reactions : string [ ] ) => {
18
19
for ( const reaction of reactions ) {
You can’t perform that action at this time.
0 commit comments