MCPcopy Create free account
hub / github.com/Xchristech2/Zenitsu-Bot / stupidCommand

Function stupidCommand

commands/stupid.js:3–48  ·  view source on GitHub ↗
(sock, chatId, quotedMsg, mentionedJid, sender, args)

Source from the content-addressed store, hash-verified

1const fetch = require('node-fetch');
2
3async function stupidCommand(sock, chatId, quotedMsg, mentionedJid, sender, args) {
4 try {
5 // Determine the target user
6 let who = quotedMsg
7 ? quotedMsg.sender
8 : mentionedJid && mentionedJid[0]
9 ? mentionedJid[0]
10 : sender;
11
12 // Get the text for the stupid card (default to "im+stupid" if not provided)
13 let text = args && args.length > 0 ? args.join(' ') : 'im+stupid';
14
15 // Get the profile picture URL
16 let avatarUrl;
17 try {
18 avatarUrl = await sock.profilePictureUrl(who, 'image');
19 } catch (error) {
20 console.error('Error fetching profile picture:', error);
21 avatarUrl = 'https://telegra.ph/file/24fa902ead26340f3df2c.png'; // Default avatar
22 }
23
24 // Fetch the stupid card from the API
25 const apiUrl = `https://some-random-api.com/canvas/misc/its-so-stupid?avatar=${encodeURIComponent(avatarUrl)}&dog=${encodeURIComponent(text)}`;
26 const response = await fetch(apiUrl);
27
28 if (!response.ok) {
29 throw new Error(`API responded with status: ${response.status}`);
30 }
31
32 // Get the image buffer
33 const imageBuffer = await response.buffer();
34
35 // Send the image with caption
36 await sock.sendMessage(chatId, {
37 image: imageBuffer,
38 caption: `*@${who.split('@')[0]}*`,
39 mentions: [who]
40 });
41
42 } catch (error) {
43 console.error('Error in stupid command:', error);
44 await sock.sendMessage(chatId, {
45 text: '❌ Sorry, I couldn\'t generate the stupid card. Please try again later!'
46 });
47 }
48}
49
50module.exports = { stupidCommand };

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected