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

Function handler

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

Source from the content-addressed store, hash-verified

44 description: "Analyze someone's character traits",
45 usage: '.character @user',
46 async handler(sock, message, args, context) {
47 const chatId = context.chatId || message.key.remoteJid;
48 const ctx = message.message?.extendedTextMessage?.contextInfo;
49 let userJid = ctx?.mentionedJid?.[0] ||
50 ctx?.participant ||
51 message.key.participant;
52 if (!userJid) {
53 return sock.sendMessage(chatId, {
54 text: '❌ Please mention someone or reply to their message to analyze their character!',
55 ...channelInfo
56 }, { quoted: message });
57 }
58 if (userJid.includes('@lid') && sock.store?.contacts) {
59 const resolved = Object.keys(sock.store.contacts).find(k => sock.store.contacts[k]?.lid === userJid);
60 if (resolved)
61 userJid = resolved;
62 }
63 try {
64 let profilePic;
65 try {
66 profilePic = await sock.profilePictureUrl(userJid, 'image');
67 }
68 catch {
69 profilePic = 'https://i.imgur.com/2wzGhpF.jpeg';
70 }
71 let displayName;
72 if (userJid.includes('@lid')) {
73 // lid JID - can't resolve to real number unless in contacts
74 const fromContacts = sock.store?.contacts?.[userJid];
75 displayName = fromContacts?.name || fromContacts?.notify || 'Unknown User';
76 }
77 else {
78 displayName = await sock.getName(userJid) || `+${ userJid.replace('@s.whatsapp.net', '')}`;
79 }
80 // Pick random traits
81 const numTraits = Math.floor(Math.random() * 3) + 3;
82 const selected = [];
83 while (selected.length < numTraits) {
84 const t = TRAITS[Math.floor(Math.random() * TRAITS.length)];
85 if (!selected.includes(t))
86 selected.push(t);
87 }
88 const traitLines = selected.map(t => `• ${t}: ${Math.floor(Math.random() * 41) + 60}%`);
89 const analysis = `🔮 *Character Analysis* 🔮\n\n` +
90 `👤 *User:* ${displayName}\n\n` +
91 `✨ *Key Traits:*\n${traitLines.join('\n')}\n\n` +
92 `🎯 *Overall Rating:* ${Math.floor(Math.random() * 21) + 80}%\n\n` +
93 `_Note: This is a fun analysis, don't take it seriously!_`;
94 await sock.sendMessage(chatId, {
95 image: { url: profilePic },
96 caption: analysis,
97 mentions: [userJid],
98 ...channelInfo
99 }, { quoted: message });
100 }
101 catch {
102 await sock.sendMessage(chatId, {
103 text: '❌ Failed to analyze character! Try again later.',

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected