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

Function warnCommand

commands/warn.js:22–152  ·  view source on GitHub ↗
(sock, chatId, senderId, mentionedJids, message)

Source from the content-addressed store, hash-verified

20}
21
22async function warnCommand(sock, chatId, senderId, mentionedJids, message) {
23 try {
24 // Initialize files first
25 initializeWarningsFile();
26
27 // First check if it's a group
28 if (!chatId.endsWith('@g.us')) {
29 await sock.sendMessage(chatId, {
30 text: 'This command can only be used in groups!'
31 });
32 return;
33 }
34
35 // Check admin status first
36 try {
37 const { isSenderAdmin, isBotAdmin } = await isAdmin(sock, chatId, senderId);
38
39 if (!isBotAdmin) {
40 await sock.sendMessage(chatId, {
41 text: '❌ Error: Please make the bot an admin first to use this command.'
42 });
43 return;
44 }
45
46 if (!isSenderAdmin) {
47 await sock.sendMessage(chatId, {
48 text: '❌ Error: Only group admins can use the warn command.'
49 });
50 return;
51 }
52 } catch (adminError) {
53 console.error('Error checking admin status:', adminError);
54 await sock.sendMessage(chatId, {
55 text: '❌ Error: Please make sure the bot is an admin of this group.'
56 });
57 return;
58 }
59
60 let userToWarn;
61
62 // Check for mentioned users
63 if (mentionedJids && mentionedJids.length > 0) {
64 userToWarn = mentionedJids[0];
65 }
66 // Check for replied message
67 else if (message.message?.extendedTextMessage?.contextInfo?.participant) {
68 userToWarn = message.message.extendedTextMessage.contextInfo.participant;
69 }
70
71 if (!userToWarn) {
72 await sock.sendMessage(chatId, {
73 text: '❌ Error: Please mention the user or reply to their message to warn!'
74 });
75 return;
76 }
77
78 // Add delay to avoid rate limiting
79 await new Promise(resolve => setTimeout(resolve, 1000));

Callers 1

handleMessagesFunction · 0.85

Calls 2

initializeWarningsFileFunction · 0.85
isAdminFunction · 0.85

Tested by

no test coverage detected