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

Function handler

plugins/notes.ts:35–120  ·  view source on GitHub ↗
(sock: any, message: any, args: any, context: BotContext)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 2

getUserNotesFunction · 0.85
saveUserNotesFunction · 0.85

Tested by

no test coverage detected