@@ -19,6 +19,7 @@ import { containsAny } from "../utils/string";
1919import { phishingSet } from "../../index" ;
2020import { getSetting } from "../services/settings" ;
2121import { normalize } from "../utils/url" ;
22+ import { InstantDownloader } from "../utils/instantdl/downloader" ;
2223
2324const regex = emojiRegex ( ) ;
2425const commandPrefix = process . env . COMMAND_PREFIX || "!" ;
@@ -38,6 +39,19 @@ const mentionResponses = [
3839 "Did you just @ me for vibes, or do I owe you money? 💸" ,
3940] ;
4041
42+ async function isRateLimit ( msg : Message , lid : string ) {
43+ if ( msg . fromMe ) return false ;
44+
45+ const rate = await rateLimiter ( lid ) ;
46+ if ( rate ) return true ;
47+ if ( rate === null ) {
48+ await msg . reply ( "Please wait a minute or so." ) ;
49+ return true ;
50+ }
51+
52+ return false ;
53+ }
54+
4155export default async function ( msg : Message , type : string ) {
4256 // ignore message if it is older than 10 seconds
4357 if ( msg . timestamp < Date . now ( ) / 1000 - 10 && type === "create" ) return ;
@@ -86,6 +100,19 @@ export default async function (msg: Message, type: string) {
86100
87101 if ( msg . isForwarded ) return ;
88102
103+ Promise . resolve ( ) . then ( async ( ) => {
104+ if ( await isRateLimit ( msg , lid ) ) return ;
105+
106+ const extractUrls = msg . body . match ( / ( h t t p s ? : \/ \/ [ ^ \s ] + ) / g) ;
107+ if ( ! extractUrls ) return ;
108+
109+ const url = extractUrls [ Math . floor ( Math . random ( ) * extractUrls . length ) ] ;
110+ const message = msg ;
111+ message . body = url ;
112+ log . info ( "Instant Downloader" , `Found ${ url } ` ) ;
113+ await InstantDownloader ( message ) ;
114+ } ) ;
115+
89116 // process normalization
90117 msg . body = msg . body
91118 . normalize ( "NFKC" )
@@ -98,6 +125,8 @@ export default async function (msg: Message, type: string) {
98125 */
99126 if ( msg . hasQuotedMsg ) {
100127 Promise . resolve ( ) . then ( async ( ) => {
128+ if ( await isRateLimit ( msg , lid ) ) return ;
129+
101130 const quoted = await msg . getQuotedMessage ( ) ;
102131 await quiz ( msg , quoted ) ;
103132 } ) ;
@@ -185,14 +214,7 @@ export default async function (msg: Message, type: string) {
185214 /*
186215 * Rate limit commands to prevent abuse.
187216 */
188- if ( ! msg . fromMe ) {
189- const rate = await rateLimiter ( lid ) ;
190- if ( rate ) return ;
191- if ( rate === null ) {
192- await msg . reply ( "Please wait a minute or so." ) ;
193- return ;
194- }
195- }
217+ if ( await isRateLimit ( msg , lid ) ) return ;
196218
197219 /*
198220 * Role base restrictions.
0 commit comments