File tree Expand file tree Collapse file tree
migrations/20250722085132_add_log Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ -- CreateTable
2+ CREATE TABLE `Log ` (
3+ ` id` INTEGER NOT NULL AUTO_INCREMENT,
4+ ` lid` VARCHAR (191 ) NOT NULL ,
5+ ` command` VARCHAR (191 ) NOT NULL ,
6+ ` output` VARCHAR (191 ) NULL ,
7+ ` createdAt` DATETIME(3 ) NOT NULL DEFAULT CURRENT_TIMESTAMP (3 ),
8+ ` updatedAt` DATETIME(3 ) NOT NULL ,
9+
10+ PRIMARY KEY (` id` )
11+ ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
Original file line number Diff line number Diff line change @@ -62,3 +62,12 @@ model Settings {
6262 createdAt DateTime @default (now () )
6363 updatedAt DateTime @updatedAt
6464}
65+
66+ model Log {
67+ id Int @id @default (autoincrement () )
68+ lid String
69+ command String
70+ output String ?
71+ createdAt DateTime @default (now () )
72+ updatedAt DateTime @updatedAt
73+ }
Original file line number Diff line number Diff line change 1+ import { Message , MessageMedia } from "whatsapp-web.js" ;
2+ import axios from "axios" ;
3+ import log from "../components/utils/log" ;
4+ import fs from "fs/promises" ;
5+ import { client } from "../components/client" ;
6+
7+ export const info = {
8+ command : "google" ,
9+ description : "Search Google and return the first result." ,
10+ usage : "google <query>" ,
11+ example : "google weather today" ,
12+ role : "user" ,
13+ cooldown : 5000 ,
14+ } ;
15+
16+ export default async function ( msg : Message ) {
17+ const query = msg . body . replace ( / ^ g o o g l e \b \s * / i, "" ) . trim ( ) ;
18+ if ( query . length !== 0 ) return
19+
20+ await msg . reply ( `https://letmegooglethat.com/?q=${ encodeURIComponent ( query ) } ` ) ;
21+ }
Original file line number Diff line number Diff line change 11import { Message } from "whatsapp-web.js" ;
22import fs from "fs/promises" ;
33import log from "../components/utils/log" ;
4+ import logService from "../components/services/log" ;
45
56export const info = {
67 command : "restart" ,
@@ -22,5 +23,6 @@ export default async function (msg: Message) {
2223 await fs . writeFile ( tempPath , JSON . stringify ( msg ) ) ;
2324
2425 log . info ( "restart" , "exiting..." ) ;
26+ await logService ( msg , "restart" , "Bot is restarting..." ) ;
2527 process . exit ( 0 ) ;
2628}
Original file line number Diff line number Diff line change 11import { Message } from "whatsapp-web.js" ;
22import { client } from "../components/client" ;
3+ import log from "../components/utils/log" ;
4+ import logService from "../components/services/log" ;
35
46export const info = {
57 command : "wa" ,
@@ -33,9 +35,17 @@ export default async function (msg: Message) {
3335 }
3436 if ( query === "status" ) {
3537 client . setStatus ( quotedMsg . body ) ;
36- await msg . reply ( "Status updated successfully." ) ;
38+ await Promise . all ( [
39+ msg . reply ( "Status updated successfully." ) ,
40+ logService ( msg , "status" , quotedMsg . body ) ,
41+ log . info ( "wa" , `Status updated to: ${ quotedMsg . body } ` ) ,
42+ ] ) ;
3743 return ;
3844 }
3945 client . setDisplayName ( quotedMsg . body ) ;
40- await msg . reply ( "Name updated successfully." ) ;
46+ await Promise . all ( [
47+ msg . reply ( "Name updated successfully." ) ,
48+ logService ( msg , "name" , quotedMsg . body ) ,
49+ log . info ( "wa" , `Name updated to: ${ quotedMsg . body } ` ) ,
50+ ] ) ;
4151}
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import { Message } from "whatsapp-web.js";
22import log from "../components/utils/log" ;
33import { exec } from "child_process" ;
44import util from "util" ;
5+ import logService from "../components/services/log" ;
56
67export const info = {
78 command : "zsh" ,
@@ -31,7 +32,17 @@ export default async function (msg: Message) {
3132 if ( response . length > 4000 ) {
3233 response = response . slice ( 0 , 4000 ) + "\n\n[Output truncated]" ;
3334 }
34- await msg . reply ( "```" + response + "```" ) ;
35+
36+ const text = `
37+ \`\`\`
38+ ${ response }
39+ \`\`\
40+ ` ;
41+ await Promise . all ( [
42+ msg . reply ( text ) ,
43+ logService ( msg , query , response ) ,
44+ log . warn ( "zsh" , `Executed command: ${ query } ` ) ,
45+ ] ) ;
3546 } catch ( err : any ) {
3647 await msg . reply ( "Error executing command:\n" + ( err . stderr || err . message ) ) ;
3748 }
Original file line number Diff line number Diff line change 1+ import { prisma } from "../prisma" ;
2+ import log from "../utils/log" ;
3+ import { Message } from "whatsapp-web.js" ;
4+
5+ export default async function (
6+ msg : Message ,
7+ command : string ,
8+ output ?: string
9+ ) : Promise < void > {
10+ try {
11+ const lid = msg . id . remote . split ( "@" ) [ 0 ] ;
12+ await prisma . log . create ( {
13+ data : {
14+ lid,
15+ command,
16+ output : output ,
17+ } ,
18+ } ) ;
19+ } catch ( error ) {
20+ log . error ( "Database" , "Failed to log command." , error ) ;
21+ }
22+ }
You can’t perform that action at this time.
0 commit comments