@@ -16,8 +16,8 @@ import { TS_BLUE } from '../env';
16
16
import {
17
17
makeCodeBlock ,
18
18
findCode ,
19
- PLAYGROUND_REGEX ,
20
- truncate ,
19
+ matchPlaygroundLink ,
20
+ PlaygroundLinkMatch ,
21
21
} from '../util/codeBlocks' ;
22
22
import { LimitedSizeMap } from '../util/limitedSizeMap' ;
23
23
import {
@@ -66,10 +66,10 @@ export class PlaygroundModule extends Module {
66
66
async onPlaygroundLinkMessage ( msg : Message ) {
67
67
if ( msg . author . bot ) return ;
68
68
if ( msg . content [ 0 ] === '!' ) return ;
69
- const exec = PLAYGROUND_REGEX . exec ( msg . content ) ;
69
+ const exec = matchPlaygroundLink ( msg . content ) ;
70
70
if ( ! exec ) return ;
71
71
const embed = createPlaygroundEmbed ( msg . author , exec ) ;
72
- if ( exec [ 0 ] === msg . content && ! isHelpChannel ( msg . channel ) ) {
72
+ if ( exec . url === msg . content && ! isHelpChannel ( msg . channel ) ) {
73
73
// Message only contained the link
74
74
await sendWithMessageOwnership ( msg , { embeds : [ embed ] } ) ;
75
75
await msg . delete ( ) ;
@@ -90,12 +90,12 @@ export class PlaygroundModule extends Module {
90
90
const attachment = msg . attachments . find ( a => a . name === 'message.txt' ) ;
91
91
if ( msg . author . bot || ! attachment ) return ;
92
92
const content = await fetch ( attachment . url ) . then ( r => r . text ( ) ) ;
93
- const exec = PLAYGROUND_REGEX . exec ( content ) ;
93
+ const exec = matchPlaygroundLink ( content ) ;
94
94
// By default, if you write a message in the box and then paste a long
95
95
// playground link, it will only put the paste in message.txt and will
96
96
// put the rest of the message in msg.content
97
- if ( ! exec || exec [ 0 ] !== content ) return ;
98
- const shortenedUrl = await shortenPlaygroundLink ( exec [ 0 ] ) ;
97
+ if ( ! exec || exec . url !== content ) return ;
98
+ const shortenedUrl = await shortenPlaygroundLink ( exec . url ) ;
99
99
const embed = createPlaygroundEmbed ( msg . author , exec , shortenedUrl ) ;
100
100
await sendWithMessageOwnership ( msg , { embeds : [ embed ] } ) ;
101
101
if ( ! msg . content ) await msg . delete ( ) ;
@@ -104,7 +104,7 @@ export class PlaygroundModule extends Module {
104
104
@listener ( { event : 'messageUpdate' } )
105
105
async onLongFix ( _oldMsg : Message , msg : Message ) {
106
106
if ( msg . partial ) await msg . fetch ( ) ;
107
- const exec = PLAYGROUND_REGEX . exec ( msg . content ) ;
107
+ const exec = matchPlaygroundLink ( msg . content ) ;
108
108
if ( msg . author . bot || ! this . editedLongLink . has ( msg . id ) || exec ) return ;
109
109
const botMsg = this . editedLongLink . get ( msg . id ) ;
110
110
// Edit the message to only have the embed and not the "please edit your message" message
@@ -119,7 +119,7 @@ export class PlaygroundModule extends Module {
119
119
// Take care when messing with the truncation, it's extremely finnicky
120
120
function createPlaygroundEmbed (
121
121
author : User ,
122
- [ _url , query , code ] : RegExpExecArray ,
122
+ { url : _url , query, code } : PlaygroundLinkMatch ,
123
123
url : string = _url ,
124
124
) {
125
125
const embed = new MessageEmbed ( )
0 commit comments