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

Function handler

plugins/addreply.ts:12–87  ·  view source on GitHub ↗
(sock: any, message: any, args: any[], context: BotContext)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 2

initConfigFunction · 0.70
saveConfigFunction · 0.70

Tested by

no test coverage detected