File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -31,19 +31,21 @@ export default async function (msg: Message) {
3131 if ( ! result . url )
3232 return await msg . reply ( "No video found at the provided URL." ) ;
3333
34- const response = await axios . get ( result . hd , { responseType : "arraybuffer" } ) ;
34+ const response = await axios . get ( result . hd || result . sd , {
35+ responseType : "arraybuffer" ,
36+ } ) ;
3537
3638 const tempDir = "./.temp" ;
37- await fs . mkdirSync ( tempDir , { recursive : true } ) ;
39+ fs . mkdirSync ( tempDir , { recursive : true } ) ;
3840
3941 const tempPath = `${ tempDir } /fbdl_${ Date . now ( ) } .mp4` ;
40- await fs . writeFileSync ( tempPath , response . data ) ;
42+ fs . writeFileSync ( tempPath , response . data ) ;
4143
4244 const audioBuffer = fs . readFileSync ( tempPath ) ;
4345 const media = new MessageMedia (
4446 "audio/mpeg" ,
4547 audioBuffer . toString ( "base64" ) ,
46- `${ result . title } .mp4`
48+ `${ result . title } .mp4` ,
4749 ) ;
4850
4951 await msg . reply ( media , msg . from ) ;
Original file line number Diff line number Diff line change @@ -79,7 +79,7 @@ export default async function (msg: Message) {
7979 * Rate limit commands to prevent abuse.
8080 */
8181 if ( ! msg . fromMe ) {
82- const rate = await rateLimiter ( msg . from ) ;
82+ const rate = await rateLimiter ( msg ) ;
8383 if ( rate ) return ;
8484 if ( rate === null ) {
8585 msg . reply ( "Please wait a minute or so." ) ;
Original file line number Diff line number Diff line change 1+ import { Message } from "whatsapp-web.js" ;
12import redis from "../redis" ;
23import log from "./log" ;
4+ import { prisma } from "../prisma" ;
35
46const LIMIT = 5 ;
57const BASE_WINDOW_MS = 30 * 1000 ;
@@ -10,8 +12,9 @@ function getKey(number: string) {
1012}
1113
1214export default async function rateLimiter (
13- number : string ,
15+ msg : Message ,
1416) : Promise < boolean | null > {
17+ const number = msg . from ;
1518 const now = Date . now ( ) ;
1619 const key = getKey ( number ) ;
1720
@@ -47,7 +50,19 @@ export default async function rateLimiter(
4750 `User ${ number } blocked until ${ new Date ( entry . penaltyUntil ) . toLocaleTimeString ( ) } ` ,
4851 ) ;
4952
50- await redis . set ( key , JSON . stringify ( entry ) ) ;
53+ await Promise . all ( [
54+ redis . set ( key , JSON . stringify ( entry ) ) ,
55+ prisma . user . update ( {
56+ where : {
57+ lid : msg . author ? msg . author . split ( "@" ) [ 0 ] : msg . from . split ( "@" ) [ 0 ] ,
58+ } ,
59+ data : {
60+ quizAnswered : {
61+ decrement : 10 ,
62+ } ,
63+ } ,
64+ } ) ,
65+ ] ) ;
5166 if ( entry . penaltyCount === 1 ) return null ;
5267 return true ;
5368 }
You can’t perform that action at this time.
0 commit comments