@@ -2,6 +2,7 @@ import { command, Module, listener } from 'cookiecord';
22import { Message , TextChannel } from 'discord.js' ;
33import { twoslasher } from '@typescript/twoslash' ;
44import { findCodeFromChannel } from '../util/findCodeblockFromChannel' ;
5+ import { sendWithMessageOwnership } from '../util/send' ;
56
67const CODEBLOCK = '```' ;
78
@@ -15,18 +16,19 @@ export class TwoslashModule extends Module {
1516 const match = / ^ [ _ $ a - z A - Z ] [ _ $ 0 - 9 a - z A - Z ] * / . exec ( content ) ;
1617
1718 if ( ! match ) {
18- msg . channel . send (
19+ return sendWithMessageOwnership (
20+ msg ,
1921 'You need to give me a valid symbol name to look for!' ,
2022 ) ;
21- return ;
2223 }
2324
2425 const symbol = match [ 0 ] ;
2526
2627 const code = await findCodeFromChannel ( msg . channel as TextChannel ) ;
2728
2829 if ( ! code )
29- return msg . channel . send (
30+ return sendWithMessageOwnership (
31+ msg ,
3032 `:warning: could not find any TypeScript codeblocks in the past 10 messages` ,
3133 ) ;
3234
@@ -38,11 +40,13 @@ export class TwoslashModule extends Module {
3840 i => i . targetString === symbol . trim ( ) ,
3941 ) ;
4042 if ( ! value )
41- return msg . channel . send (
43+ return sendWithMessageOwnership (
44+ msg ,
4245 `:warning: no symbol named \`${ symbol } \` in the most recent codeblock` ,
4346 ) ;
4447
45- return msg . channel . send (
48+ await sendWithMessageOwnership (
49+ msg ,
4650 `${ CODEBLOCK } typescript\n${ value . text } ${ CODEBLOCK } ` ,
4751 ) ;
4852 }
@@ -55,7 +59,8 @@ export class TwoslashModule extends Module {
5559 const code = await findCodeFromChannel ( msg . channel as TextChannel ) ;
5660
5761 if ( ! code )
58- return msg . channel . send (
62+ return sendWithMessageOwnership (
63+ msg ,
5964 `:warning: could not find any TypeScript codeblocks in the past 10 messages` ,
6065 ) ;
6166
@@ -131,6 +136,9 @@ export class TwoslashModule extends Module {
131136 } ) ;
132137
133138 const output = resultLines . join ( '\n' ) ;
134- return msg . channel . send ( `${ CODEBLOCK } ts\n${ output } ${ CODEBLOCK } \n` ) ;
139+ return sendWithMessageOwnership (
140+ msg ,
141+ `${ CODEBLOCK } ts\n${ output } ${ CODEBLOCK } \n` ,
142+ ) ;
135143 }
136144}
0 commit comments