File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import { Message } from "../types/message" ;
2+ import { download } from "../components/utils/download" ;
3+ import { getClientIds } from "../components/services/account" ;
4+
5+ export const info = {
6+ command : "accounts" ,
7+ description : "List all accounts currently connected in." ,
8+ usage : "accounts" ,
9+ example : "accounts" ,
10+ role : "user" ,
11+ cooldown : 5000 ,
12+ } ;
13+
14+ export default async function ( msg : Message ) : Promise < void > {
15+ let accounts = "" ;
16+ const accountsIds = await getClientIds ( ) ;
17+ await Promise . all (
18+ Array . from ( accountsIds . entries ( ) ) . map ( ( [ clientId , isRoot ] ) => {
19+ accounts += `\`${ clientId } \` - ${ isRoot ? "Root" : "User" } \n` ;
20+ } ) ,
21+ ) ;
22+
23+ msg . reply ( `
24+ \`Accounts\`
25+
26+ ${ accounts }
27+ ` ) ;
28+ }
Original file line number Diff line number Diff line change @@ -2,18 +2,30 @@ import { Message } from "../types/message";
22import { removeAccount } from "../components/client" ;
33import log from "../components/utils/log" ;
44import { deleteAccount } from "../components/services/account" ;
5+ import redis from "../components/redis" ;
56
67export const info = {
78 command : "logout" ,
89 description : "Log out the client from WhatsApp." ,
9- usage : "logout" ,
10+ usage : "logout [clientId] " ,
1011 example : "logout" ,
11- role : "super- admin" ,
12+ role : "admin" ,
1213 cooldown : 5000 ,
1314} ;
1415
1516export default async function ( msg : Message ) : Promise < void > {
1617 try {
18+ const query = msg . body . replace ( / ^ l o g o u t \b \s * / i, "" ) . trim ( ) ;
19+ if ( query . length > 0 ) {
20+ const isRootAccount = await redis . get ( 'root_client_id' ) ;
21+ const rootClient = isRootAccount ? JSON . parse ( isRootAccount ) : null ;
22+ if ( rootClient . clientId === query ) {
23+ removeAccount ( query ) ;
24+ deleteAccount ( query ) ;
25+ log . info ( "Logout" , "Root client logged out successfully." ) ;
26+ return ;
27+ }
28+ }
1729 removeAccount ( msg . clientId ) ;
1830 deleteAccount ( msg . clientId ) ;
1931 log . info ( "Logout" , "Client logged out successfully." ) ;
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ import {
1717 PROJECT_THRESHOLD_MEMORY ,
1818} from "./config" ;
1919import { getClientIds , getRootAccount } from "./components/services/account" ;
20+ import redis from "./components/redis" ;
2021
2122const monitor = new MemoryMonitor ( {
2223 interval : 60000 ,
@@ -43,6 +44,11 @@ async function main() {
4344 const accountsIds = await getClientIds ( ) ;
4445 await Promise . all (
4546 Array . from ( accountsIds . entries ( ) ) . map ( async ( [ clientId , isRoot ] ) => {
47+ if ( isRoot )
48+ await redis . set (
49+ "root_client_id" ,
50+ JSON . stringify ( { clientId, lid : null , date : Date . now ( ) } ) ,
51+ ) ;
4652 await addAccount ( clientId , undefined , isRoot ) ;
4753 } ) ,
4854 ) ;
You can’t perform that action at this time.
0 commit comments