MCPcopy Create free account
hub / github.com/GlobalTechInfo/MEGA-MD / handler

Function handler

plugins/addreply.js:9–73  ·  view source on GitHub ↗
(sock, message, args, context)

Source from the content-addressed store, hash-verified

7 usage: '.addreply <trigger> | <response>\nFor exact match: .addreply exact:<trigger> | <response>\nUse {name} in response to mention sender name',
8 ownerOnly: true,
9 async handler(sock, message, args, context) {
10 const chatId = context.chatId || message.key.remoteJid;
11 const senderId = context.senderId || message.key.remoteJid;
12 const channelInfo = context.channelInfo || {};
13 const fullText = args.join(' ');
14 const pipeIndex = fullText.indexOf('|');
15 if (!fullText || pipeIndex === -1) {
16 return await sock.sendMessage(chatId, {
17 text: `*➕ ADD AUTO-REPLY*\n\n` +
18 `*Usage:*\n` +
19 `\`.addreply <trigger> | <response>\`\n\n` +
20 `*Examples:*\n` +
21 `• \`.addreply hello | Hi there! 👋\`\n` +
22 `• \`.addreply exact:good morning | Good morning! ☀️\`\n` +
23 `• \`.addreply hi | Hello {name}! How are you?\`\n\n` +
24 `*Tips:*\n` +
25 `• Use \`exact:\` prefix for full message match\n` +
26 `• Without \`exact:\` it matches if message *contains* trigger\n` +
27 `• Use \`{name}\` in response to mention the sender's name`,
28 ...channelInfo
29 }, { quoted: message });
30 }
31 let trigger = fullText.substring(0, pipeIndex).trim();
32 const response = fullText.substring(pipeIndex + 1).trim();
33 if (!trigger || !response) {
34 return await sock.sendMessage(chatId, {
35 text: '❌ Both trigger and response are required.\n\nExample: `.addreply hello | Hi there!`',
36 ...channelInfo
37 }, { quoted: message });
38 }
39 let exactMatch = false;
40 if (trigger.toLowerCase().startsWith('exact:')) {
41 exactMatch = true;
42 trigger = trigger.substring(6).trim();
43 }
44 if (!trigger) {
45 return await sock.sendMessage(chatId, {
46 text: '❌ Trigger cannot be empty after `exact:` prefix.',
47 ...channelInfo
48 }, { quoted: message });
49 }
50 const config = await initConfig();
51 const exists = config.replies.find(r => r.trigger === trigger.toLowerCase());
52 if (exists) {
53 return await sock.sendMessage(chatId, {
54 text: `⚠️ A reply for *"${trigger}"* already exists!\n\nUse \`.delreply ${trigger}\` to remove it first.`,
55 ...channelInfo
56 }, { quoted: message });
57 }
58 config.replies.push({
59 trigger: trigger.toLowerCase(),
60 response,
61 exactMatch,
62 addedBy: senderId,
63 createdAt: Date.now()
64 });
65 await saveConfig(config);
66 await sock.sendMessage(chatId, {

Callers

nothing calls this directly

Calls 2

initConfigFunction · 0.90
saveConfigFunction · 0.90

Tested by

no test coverage detected