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

Function handler

plugins/notes.js:31–107  ·  view source on GitHub ↗
(sock, message, args, context)

Source from the content-addressed store, hash-verified

29 description: 'Store, view, and delete your personal notes',
30 usage: '.notes <add|all|del|delall> [text|ID]',
31 async handler(sock, message, args, context) {
32 const chatId = context.chatId || message.key.remoteJid;
33 const sender = message.key.participant || message.key.remoteJid;
34 try {
35 const action = args[0] ? args[0].toLowerCase() : null;
36 const content = args.slice(1).join(" ").trim();
37 const menuText = `
38╭───── *『 NOTES 』* ───◆
39┃ Store notes for later use
40┃ Storage: ${HAS_DB ? 'Database 🗄️' : 'Memory 📁'}
41
42┃ ● Add Note
43┃ .notes add your text here
44
45┃ ● Get All Notes
46┃ .notes all
47
48┃ ● Delete Note
49┃ .notes del noteID
50
51┃ ● Delete All Notes
52┃ .notes delall
53╰━━━━━━━━━━━━━━━━━──⊷`;
54 if (!action) {
55 return await sock.sendMessage(chatId, { text: menuText }, { quoted: message });
56 }
57 if (action === 'add') {
58 if (!content) {
59 return await sock.sendMessage(chatId, {
60 text: "*Please write a note to save.*\nExample: .notes add buy milk"
61 }, { quoted: message });
62 }
63 const userNotes = await getUserNotes(sender);
64 const newID = userNotes.length + 1;
65 userNotes.push({ id: newID, text: content, createdAt: Date.now() });
66 await saveUserNotes(sender, userNotes);
67 return await sock.sendMessage(chatId, {
68 text: `✅ Note saved.\nID: ${newID}\nStorage: ${HAS_DB ? 'Database' : 'Memory'}`
69 }, { quoted: message });
70 }
71 if (action === 'all') {
72 const userNotes = await getUserNotes(sender);
73 if (userNotes.length === 0) {
74 return await sock.sendMessage(chatId, { text: "*You have no notes saved.*" }, { quoted: message });
75 }
76 const list = userNotes.map((n) => `${n.id}. ${n.text}`).join("\n");
77 return await sock.sendMessage(chatId, {
78 text: `*📝 Your Notes:*\n\n${list}\n\n_Total: ${userNotes.length} notes_`
79 }, { quoted: message });
80 }
81 if (action === 'del') {
82 const id = parseInt(args[1], 10);
83 const userNotes = await getUserNotes(sender);
84 if (!id || !userNotes.find((n) => n.id === id)) {
85 return await sock.sendMessage(chatId, {
86 text: "Invalid note ID.\nExample: .notes del 1"
87 }, { quoted: message });
88 }

Callers

nothing calls this directly

Calls 2

getUserNotesFunction · 0.85
saveUserNotesFunction · 0.85

Tested by

no test coverage detected