@@ -2,6 +2,7 @@ import { Message } from "whatsapp-web.js";
22import log from "npmlog" ;
33import { exec } from "child_process" ;
44import util from "util" ;
5+ import fs from "fs/promises" ;
56
67export const command = "run" ;
78export const role = "admin" ;
@@ -26,27 +27,29 @@ export default async function (msg: Message) {
2627 let command : string ;
2728 let tempFile : string ;
2829
30+ const tempDir = "./.temp" ;
31+ await fs . mkdir ( tempDir , { recursive : true } ) ;
32+
2933 if ( lang === "python" ) {
30- tempFile = `/tmp /run.py` ;
34+ tempFile = `${ tempDir } /run.py` ;
3135 command = `python3 "${ tempFile } "` ;
3236 } else if ( lang === "java" ) {
33- tempFile = `/tmp /run.java` ;
37+ tempFile = `${ tempDir } /run.java` ;
3438 command = `javac "${ tempFile } " && java -cp /tmp Code` ;
3539 } else if ( lang === "c" ) {
36- tempFile = `/tmp /run.c` ;
40+ tempFile = `${ tempDir } /run.c` ;
3741 command = `gcc "${ tempFile } " -o /tmp/code && /tmp/code` ;
3842 } else if ( lang === "js" ) {
39- tempFile = `/tmp /code.js` ;
43+ tempFile = `${ tempDir } /code.js` ;
4044 command = `node "${ tempFile } "` ;
4145 } else if ( lang === "php" ) {
42- tempFile = `/tmp /run.php` ;
46+ tempFile = `${ tempDir } /run.php` ;
4347 command = `php "${ tempFile } "` ;
4448 } else {
4549 await msg . reply ( "Unsupported language." ) ;
4650 return ;
4751 }
4852
49- const fs = await import ( "fs/promises" ) ;
5053 await fs . writeFile ( tempFile , code ) ;
5154
5255 const execPromise = util . promisify ( exec ) ;
0 commit comments