MCPcopy Create free account
hub / github.com/Xchristech2/Zenitsu-Bot / clearSessionCommand

Function clearSessionCommand

commands/clearsession.js:18–99  ·  view source on GitHub ↗
(sock, chatId, msg)

Source from the content-addressed store, hash-verified

16};
17
18async function clearSessionCommand(sock, chatId, msg) {
19 try {
20 const senderId = msg.key.participant || msg.key.remoteJid;
21 const isOwner = await isOwnerOrSudo(senderId, sock, chatId);
22
23 if (!msg.key.fromMe && !isOwner) {
24 await sock.sendMessage(chatId, {
25 text: '❌ This command can only be used by the owner!',
26 ...channelInfo
27 });
28 return;
29 }
30
31 // Define session directory
32 const sessionDir = path.join(__dirname, '../session');
33
34 if (!fs.existsSync(sessionDir)) {
35 await sock.sendMessage(chatId, {
36 text: '❌ Session directory not found!',
37 ...channelInfo
38 });
39 return;
40 }
41
42 let filesCleared = 0;
43 let errors = 0;
44 let errorDetails = [];
45
46 // Send initial status
47 await sock.sendMessage(chatId, {
48 text: `🔍 Optimizing session files for better performance...`,
49 ...channelInfo
50 });
51
52 const files = fs.readdirSync(sessionDir);
53
54 // Count files by type for optimization
55 let appStateSyncCount = 0;
56 let preKeyCount = 0;
57
58 for (const file of files) {
59 if (file.startsWith('app-state-sync-')) appStateSyncCount++;
60 if (file.startsWith('pre-key-')) preKeyCount++;
61 }
62
63 // Delete files
64 for (const file of files) {
65 if (file === 'creds.json') {
66 // Skip creds.json file
67 continue;
68 }
69 try {
70 const filePath = path.join(sessionDir, file);
71 fs.unlinkSync(filePath);
72 filesCleared++;
73 } catch (error) {
74 errors++;
75 errorDetails.push(`Failed to delete ${file}: ${error.message}`);

Callers

nothing calls this directly

Calls 1

isOwnerOrSudoFunction · 0.85

Tested by

no test coverage detected