MCPcopy
hub / github.com/mruniquehacker/Knightbot-MD / settingsCommand

Function settingsCommand

commands/settings.js:14–90  ·  view source on GitHub ↗
(sock, chatId, message)

Source from the content-addressed store, hash-verified

12const isOwnerOrSudo = require('../lib/isOwner');
13
14async function settingsCommand(sock, chatId, message) {
15 try {
16 const senderId = message.key.participant || message.key.remoteJid;
17 const isOwner = await isOwnerOrSudo(senderId, sock, chatId);
18
19 if (!message.key.fromMe && !isOwner) {
20 await sock.sendMessage(chatId, { text: 'Only bot owner can use this command!' }, { quoted: message });
21 return;
22 }
23
24 const isGroup = chatId.endsWith('@g.us');
25 const dataDir = './data';
26
27 const mode = readJsonSafe(`${dataDir}/messageCount.json`, { isPublic: true });
28 const autoStatus = readJsonSafe(`${dataDir}/autoStatus.json`, { enabled: false });
29 const autoread = readJsonSafe(`${dataDir}/autoread.json`, { enabled: false });
30 const autotyping = readJsonSafe(`${dataDir}/autotyping.json`, { enabled: false });
31 const pmblocker = readJsonSafe(`${dataDir}/pmblocker.json`, { enabled: false });
32 const anticall = readJsonSafe(`${dataDir}/anticall.json`, { enabled: false });
33 const userGroupData = readJsonSafe(`${dataDir}/userGroupData.json`, {
34 antilink: {}, antibadword: {}, welcome: {}, goodbye: {}, chatbot: {}, antitag: {}
35 });
36 const autoReaction = Boolean(userGroupData.autoReaction);
37
38 // Per-group features
39 const groupId = isGroup ? chatId : null;
40 const antilinkOn = groupId ? Boolean(userGroupData.antilink && userGroupData.antilink[groupId]) : false;
41 const antibadwordOn = groupId ? Boolean(userGroupData.antibadword && userGroupData.antibadword[groupId]) : false;
42 const welcomeOn = groupId ? Boolean(userGroupData.welcome && userGroupData.welcome[groupId]) : false;
43 const goodbyeOn = groupId ? Boolean(userGroupData.goodbye && userGroupData.goodbye[groupId]) : false;
44 const chatbotOn = groupId ? Boolean(userGroupData.chatbot && userGroupData.chatbot[groupId]) : false;
45 const antitagCfg = groupId ? (userGroupData.antitag && userGroupData.antitag[groupId]) : null;
46
47 const lines = [];
48 lines.push('*BOT SETTINGS*');
49 lines.push('');
50 lines.push(`• Mode: ${mode.isPublic ? 'Public' : 'Private'}`);
51 lines.push(`• Auto Status: ${autoStatus.enabled ? 'ON' : 'OFF'}`);
52 lines.push(`• Autoread: ${autoread.enabled ? 'ON' : 'OFF'}`);
53 lines.push(`• Autotyping: ${autotyping.enabled ? 'ON' : 'OFF'}`);
54 lines.push(`• PM Blocker: ${pmblocker.enabled ? 'ON' : 'OFF'}`);
55 lines.push(`• Anticall: ${anticall.enabled ? 'ON' : 'OFF'}`);
56 lines.push(`• Auto Reaction: ${autoReaction ? 'ON' : 'OFF'}`);
57 if (groupId) {
58 lines.push('');
59 lines.push(`Group: ${groupId}`);
60 if (antilinkOn) {
61 const al = userGroupData.antilink[groupId];
62 lines.push(`• Antilink: ON (action: ${al.action || 'delete'})`);
63 } else {
64 lines.push('• Antilink: OFF');
65 }
66 if (antibadwordOn) {
67 const ab = userGroupData.antibadword[groupId];
68 lines.push(`• Antibadword: ON (action: ${ab.action || 'delete'})`);
69 } else {
70 lines.push('• Antibadword: OFF');
71 }

Callers 1

handleMessagesFunction · 0.85

Calls 2

isOwnerOrSudoFunction · 0.85
readJsonSafeFunction · 0.85

Tested by

no test coverage detected