Advertisement
ngatmuri

Auto Typing WhatApp

Sep 24th, 2023
855
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const { Client, Location, List, Buttons, LocalAuth} = require('./index');
  2.  
  3. const qrcode = require('qrcode-terminal');
  4.  
  5.  
  6. const client = new Client({
  7.     authStrategy: new LocalAuth(),
  8.     puppeteer: {ffmpegPath: '/path/to/ffmpeg.exe',
  9.     args: ['--no-sandbox','--disable-setuid-sandbox'],
  10.     authStrategy: new LocalAuth()
  11. },
  12. });
  13.  
  14. client.initialize();
  15.  
  16. client.on('loading_screen', (percent, message) => {
  17.     console.log('LOADING SCREEN', percent, message);
  18. });
  19.  
  20. client.on('qr', (qr) => {
  21.     qrcode.generate(qr, {small: true});
  22.     // NOTE: This event will not be fired if a session is specified.
  23.     console.log('QR RECEIVED', qr);
  24. });
  25.  
  26. client.on('authenticated', () => {
  27.     console.log('AUTHENTICATED');
  28. });
  29.  
  30. client.on('auth_failure', msg => {
  31.     // Fired if session restore was unsuccessful
  32.     console.error('AUTHENTICATION FAILURE', msg);
  33. });
  34.  
  35. client.on('ready', () => {
  36.     console.log('READY');
  37. });
  38.  
  39. client.on('message', async msg => {
  40.     console.log('MESSAGE RECEIVED', msg);
  41.  
  42.     if (msg.body === '!ping reply') {
  43.         // Send a new message as a reply to the current one
  44.         msg.reply('pong');
  45.  
  46.     } else if (msg.body === '!ping') {
  47.         // Send a new message to the same chat
  48.         client.sendMessage(msg.from, 'pong');
  49.  
  50.     } else if (msg.body.startsWith('!sendto ')) {
  51.         // Direct send a new message to specific id
  52.         let number = msg.body.split(' ')[1];
  53.         let messageIndex = msg.body.indexOf(number) + number.length;
  54.         let message = msg.body.slice(messageIndex, msg.body.length);
  55.         number = number.includes('@c.us') ? number : `${number}@c.us`;
  56.         let chat = await msg.getChat();
  57.         chat.sendSeen();
  58.         client.sendMessage(number, message);
  59.  
  60.     } else if (msg.body.startsWith('!subject ')) {
  61.         // Change the group subject
  62.         let chat = await msg.getChat();
  63.         if (chat.isGroup) {
  64.             let newSubject = msg.body.slice(9);
  65.             chat.setSubject(newSubject);
  66.         } else {
  67.             msg.reply('This command can only be used in a group!');
  68.         }
  69.     } else if (msg.body.startsWith('!echo ')) {
  70.         // Replies with the same message
  71.         msg.reply(msg.body.slice(6));
  72.     } else if (msg.body.startsWith('!desc ')) {
  73.         // Change the group description
  74.         let chat = await msg.getChat();
  75.         if (chat.isGroup) {
  76.             let newDescription = msg.body.slice(6);
  77.             chat.setDescription(newDescription);
  78.         } else {
  79.             msg.reply('This command can only be used in a group!');
  80.         }
  81.     } else if (msg.body === '!leave') {
  82.         // Leave the group
  83.         let chat = await msg.getChat();
  84.         if (chat.isGroup) {
  85.             chat.leave();
  86.         } else {
  87.             msg.reply('This command can only be used in a group!');
  88.         }
  89.     } else if (msg.body.startsWith('!join ')) {
  90.         const inviteCode = msg.body.split(' ')[1];
  91.         try {
  92.             await client.acceptInvite(inviteCode);
  93.             msg.reply('Joined the group!');
  94.         } catch (e) {
  95.             msg.reply('That invite code seems to be invalid.');
  96.         }
  97.     } else if (msg.body === '!groupinfo') {
  98.         let chat = await msg.getChat();
  99.         if (chat.isGroup) {
  100.             msg.reply(`
  101.                 *Group Details*
  102.                 Name: ${chat.name}
  103.                 Description: ${chat.description}
  104.                 Created At: ${chat.createdAt.toString()}
  105.                 Created By: ${chat.owner.user}
  106.                 Participant count: ${chat.participants.length}
  107.             `);
  108.         } else {
  109.             msg.reply('This command can only be used in a group!');
  110.         }
  111.     } else if (msg.body === '!chats') {
  112.         const chats = await client.getChats();
  113.         client.sendMessage(msg.from, `The bot has ${chats.length} chats open.`);
  114.     } else if (msg.body === '!info') {
  115.         let info = client.info;
  116.         client.sendMessage(msg.from, `
  117.             *Connection info*
  118.             User name: ${info.pushname}
  119.             My number: ${info.wid.user}
  120.             Platform: ${info.platform}
  121.         `);
  122.     } else if (msg.body === '!mediainfo' && msg.hasMedia) {
  123.         const attachmentData = await msg.downloadMedia();
  124.         msg.reply(`
  125.             *Media info*
  126.             MimeType: ${attachmentData.mimetype}
  127.             Filename: ${attachmentData.filename}
  128.             Data (length): ${attachmentData.data.length}
  129.         `);
  130.     } else if (msg.body === '!quoteinfo' && msg.hasQuotedMsg) {
  131.         const quotedMsg = await msg.getQuotedMessage();
  132.  
  133.         quotedMsg.reply(`
  134.             ID: ${quotedMsg.id._serialized}
  135.             Type: ${quotedMsg.type}
  136.             Author: ${quotedMsg.author || quotedMsg.from}
  137.             Timestamp: ${quotedMsg.timestamp}
  138.             Has Media? ${quotedMsg.hasMedia}
  139.         `);
  140.     } else if (msg.body === '!resendmedia' && msg.hasQuotedMsg) {
  141.         const quotedMsg = await msg.getQuotedMessage();
  142.         if (quotedMsg.hasMedia) {
  143.             const attachmentData = await quotedMsg.downloadMedia();
  144.             client.sendMessage(msg.from, attachmentData, { caption: 'Here\'s your requested media.' });
  145.         }
  146.     } else if (msg.body === '!location') {
  147.         msg.reply(new Location(37.422, -122.084, 'Googleplex\nGoogle Headquarters'));
  148.     } else if (msg.location) {
  149.         msg.reply(msg.location);
  150.     } else if (msg.body.startsWith('!status ')) {
  151.         const newStatus = msg.body.split(' ')[1];
  152.         await client.setStatus(newStatus);
  153.         msg.reply(`Status was updated to *${newStatus}*`);
  154.     } else if (msg.body === '!mention') {
  155.         const contact = await msg.getContact();
  156.         const chat = await msg.getChat();
  157.         chat.sendMessage(`Hi @${contact.number}!`, {
  158.             mentions: [contact]
  159.         });
  160.     } else if (msg.body === '!delete') {
  161.         if (msg.hasQuotedMsg) {
  162.             const quotedMsg = await msg.getQuotedMessage();
  163.             if (quotedMsg.fromMe) {
  164.                 quotedMsg.delete(true);
  165.             } else {
  166.                 msg.reply('I can only delete my own messages');
  167.             }
  168.         }
  169.     } else if (msg.body === '!pin') {
  170.         const chat = await msg.getChat();
  171.         await chat.pin();
  172.     } else if (msg.body === '!archive') {
  173.         const chat = await msg.getChat();
  174.         await chat.archive();
  175.     } else if (msg.body === '!mute') {
  176.         const chat = await msg.getChat();
  177.         // mute the chat for 20 seconds
  178.         const unmuteDate = new Date();
  179.         unmuteDate.setSeconds(unmuteDate.getSeconds() + 20);
  180.         await chat.mute(unmuteDate);
  181.     } else if (msg.body === '!ketik') {
  182.         const chat = await msg.getChat();
  183.         // simulates typing in the chat
  184.         chat.sendStateTyping();
  185.     } else if (msg.body === '!rekam') {
  186.         const chat = await msg.getChat();
  187.         // simulates recording audio in the chat
  188.         chat.sendStateRecording();
  189.  
  190.  
  191.  
  192.     } else if (msg.body === '!clearstate') {
  193.         const chat = await msg.getChat();
  194.         // stops typing or recording in the chat
  195.         chat.clearState();
  196.     } else if (msg.body === '!jumpto') {
  197.         if (msg.hasQuotedMsg) {
  198.             const quotedMsg = await msg.getQuotedMessage();
  199.             client.interface.openChatWindowAt(quotedMsg.id._serialized);
  200.         }
  201.     } else if (msg.body === '!buttons') {
  202.         let button = new Buttons('Button body',[{body:'bt1'},{body:'bt2'},{body:'bt3'}],'title','footer');
  203.         client.sendMessage(msg.from, button);
  204.     } else if (msg.body === '!list') {
  205.         let sections = [{title:'sectionTitle',rows:[{title:'ListItem1', description: 'desc'},{title:'ListItem2'}]}];
  206.         let list = new List('List body','btnText',sections,'Title','footer');
  207.         client.sendMessage(msg.from, list);
  208.     } else if (msg.body === '!reaction') {
  209.         msg.react('👍');
  210.     }
  211. });
  212.  
  213.  
  214. function getRandomItem(arr) {
  215.  
  216.     // get random index value
  217.     const randomIndex = Math.floor(Math.random() * arr.length);
  218.  
  219.     // get random item
  220.     const item = arr[randomIndex];
  221.  
  222.     return item;
  223. }
  224.  
  225. const array = ['💛','💙','💜','💚','❤','💔','💗','💓','💕','💖','💞','💘','💌'];
  226.  
  227. const result = getRandomItem(array);
  228.  
  229.  
  230. client.on('message', async (msg) => {
  231.     const chat = await msg.getChat();
  232.     const contact = await msg.getContact();
  233.    
  234. await msg.react(getRandomItem(array));
  235. });
  236.  
  237.  
  238.  
  239. //disini Edit
  240.  
  241.  
  242. sleep(15000).then(() => {
  243.  
  244.    
  245.    
  246.    
  247. client.on('message', async (msg) => {
  248.     const chat = await msg.getChat();
  249.     const contact = await msg.getContact();
  250.    
  251.     chat.sendStateRecording();
  252.     // await chat.sendStateTyping();
  253.     var n=20000000;
  254.  
  255.     for(var i=1; i<=n; i++){
  256.         await sleep(15000);
  257.  
  258.     await  console.log(chat.sendStateTyping());
  259.     }
  260.     });
  261. })
  262.     function sleep(ms) {
  263.         return new Promise(resolve => setTimeout(resolve, ms));
  264.     }
  265.  
  266.    
  267.  
  268.         // Ketik
  269.  
  270.     //Rekam
  271.     /*
  272.     client.on('message', async (msg) => {
  273.         const chat = await msg.getChat();
  274.         const contact = await msg.getContact();
  275.        
  276.         await chat.sendStateTyping();
  277.  
  278.         }); */
  279.  
  280. client.on('message_create', (msg) => {
  281.     // Fired on all message creations, including your own
  282.     if (msg.fromMe) {
  283.         // do stuff here
  284.     }
  285. });
  286.  
  287. client.on('message_revoke_everyone', async (after, before) => {
  288.     // Fired whenever a message is deleted by anyone (including you)
  289.     console.log(after); // message after it was deleted.
  290.     if (before) {
  291.         console.log(before); // message before it was deleted.
  292.     }
  293. });
  294.  
  295. client.on('message_revoke_me', async (msg) => {
  296.     // Fired whenever a message is only deleted in your own view.
  297.     console.log(msg.body); // message before it was deleted.
  298. });
  299.  
  300. client.on('message_ack', (msg, ack) => {
  301.     /*
  302.         == ACK VALUES ==
  303.         ACK_ERROR: -1
  304.         ACK_PENDING: 0
  305.         ACK_SERVER: 1
  306.         ACK_DEVICE: 2
  307.         ACK_READ: 3
  308.         ACK_PLAYED: 4
  309.     */
  310.  
  311.     if(ack == 3) {
  312.         // The message was read
  313.     }
  314. });
  315.  
  316. client.on('group_join', (notification) => {
  317.     // User has joined or been added to the group.
  318.     console.log('join', notification);
  319.     notification.reply('Selamat Datang, yang baru Gabung..');
  320. });
  321.  
  322. client.on('group_leave', (notification) => {
  323.     // User has left or been kicked from the group.
  324.     console.log('leave', notification);
  325.     notification.reply('Yah, Ada yang Keluar...');
  326. });
  327.  
  328. client.on('group_update', (notification) => {
  329.     // Group picture, subject or description has been updated.
  330.     console.log('update', notification);
  331. });
  332.  
  333. client.on('change_state', state => {
  334.     console.log('CHANGE STATE', state );
  335. });
  336.  
  337. // Change to false if you don't want to reject incoming calls
  338. let rejectCalls = false; //false aktif
  339.  
  340. client.on('call', async (call) => {
  341.     console.log('Call received, rejecting. GOTO Line 261 to disable', call);
  342.     if (rejectCalls) await call.reject();
  343.     await client.sendMessage(call.from, `[${call.fromMe ? 'Outgoing' : 'Incoming'}] Phone call from ${call.from}, type ${call.isGroup ? 'group' : ''} ${call.isVideo ? 'video' : 'audio'} call. ${rejectCalls ? 'This call was automatically rejected by the script.' : ''}`);
  344. });
  345.  
  346. client.on('disconnected', (reason) => {
  347.     console.log('Client was logged out', reason);
  348. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement