File tree 2 files changed +28
-24
lines changed 2 files changed +28
-24
lines changed Original file line number Diff line number Diff line change @@ -3,13 +3,7 @@ import { MessageType } from 'discord.js';
3
3
4
4
import { config } from '../config' ;
5
5
import { coolLinksManagement } from '../cool-links-management' ;
6
-
7
- const urlMappings = [
8
- {
9
- pattern : / h t t p s ? : \/ \/ ( m o b i l e \. ) ? t w i t t e r \. c o m \/ ( \S + ) \/ s t a t u s \/ ( \d + ) / g,
10
- replacement : 'https://vxtwitter.com/$2/status/$3' ,
11
- } ,
12
- ] ;
6
+ import { patternReplacement } from '../pattern-replacement' ;
13
7
14
8
export const handleGuildMessageCreation = async ( message : Message ) => {
15
9
if ( message . author . bot ) {
@@ -25,21 +19,5 @@ export const handleGuildMessageCreation = async (message: Message) => {
25
19
return ;
26
20
}
27
21
28
- let modifiedContent = message . content ;
29
- let hasModification = false ;
30
-
31
- for ( const { pattern, replacement } of urlMappings ) {
32
- if ( pattern . test ( modifiedContent ) ) {
33
- modifiedContent = modifiedContent . replace ( pattern , replacement ) ;
34
- hasModification = true ;
35
- }
36
- }
37
-
38
- if ( ! hasModification ) {
39
- return ;
40
- }
41
- const newMessage = [ `<@${ message . author . id } >` , modifiedContent ] . join ( '\n' ) ;
42
-
43
- await message . channel . send ( newMessage ) ;
44
- await message . delete ( ) ;
22
+ await patternReplacement ( message ) ;
45
23
} ;
Original file line number Diff line number Diff line change
1
+ import type { Message } from 'discord.js' ;
2
+
3
+ const urlMappings = [
4
+ {
5
+ pattern : / h t t p s ? : \/ \/ ( m o b i l e \. ) ? t w i t t e r \. c o m \/ ( \S + ) \/ s t a t u s \/ ( \d + ) / g,
6
+ replacement : 'https://vxtwitter.com/$2/status/$3' ,
7
+ } ,
8
+ ] ;
9
+
10
+ export const patternReplacement = async ( message : Message ) => {
11
+ let modifiedContent = message . content ;
12
+
13
+ for ( const { pattern, replacement } of urlMappings ) {
14
+ if ( pattern . test ( modifiedContent ) ) {
15
+ modifiedContent = modifiedContent . replace ( pattern , replacement ) ;
16
+ }
17
+ }
18
+
19
+ const hasModification = message . content !== modifiedContent ;
20
+ if ( ! hasModification ) return ;
21
+
22
+ const newMessage = [ `<@${ message . author . id } >` , modifiedContent ] . join ( '\n' ) ;
23
+
24
+ await message . channel . send ( newMessage ) ;
25
+ await message . delete ( ) ;
26
+ } ;
You can’t perform that action at this time.
0 commit comments