1
1
import type { Message } from 'discord.js' ;
2
2
import { MessageType } from 'discord.js' ;
3
3
4
+ const urlMappings = [
5
+ {
6
+ 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,
7
+ replacement : 'https://vxtwitter.com/$2/status/$3' ,
8
+ } ,
9
+ ] ;
10
+
4
11
export const handleGuildMessageCreation = async ( message : Message ) => {
5
12
if ( message . author . bot ) {
6
13
return ;
@@ -10,17 +17,20 @@ export const handleGuildMessageCreation = async (message: Message) => {
10
17
return ;
11
18
}
12
19
13
- const urls = message . content . match ( / h t t p s ? : \/ \/ \S + / g) ;
14
- if ( urls === null ) {
15
- return ;
16
- }
20
+ let modifiedContent = message . content ;
21
+ let hasModification = false ;
17
22
18
- const newContent = message . content . replaceAll (
19
- / h t t p s ? : \/ \/ ( m o b i l e \. ) ? t w i t t e r \. c o m / g,
20
- 'https://vxtwitter.com'
21
- ) ;
23
+ for ( const { pattern, replacement } of urlMappings ) {
24
+ if ( pattern . test ( modifiedContent ) ) {
25
+ modifiedContent = modifiedContent . replace ( pattern , replacement ) ;
26
+ hasModification = true ;
27
+ }
28
+ }
22
29
23
- const newMessage = [ `<@${ message . author . id } >` , newContent ] . join ( '\n' ) ;
30
+ if ( ! hasModification ) {
31
+ return ;
32
+ }
33
+ const newMessage = [ `<@${ message . author . id } >` , modifiedContent ] . join ( '\n' ) ;
24
34
25
35
await message . channel . send ( newMessage ) ;
26
36
await message . delete ( ) ;
0 commit comments