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

Function handler

plugins/character.ts:49–119  ·  view source on GitHub ↗
(sock: any, message: any, args: string[], context: BotContext)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected