Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const { Client, MessageMedia } = require('whatsapp-web.js');
- var qrcode = require('qrcode-terminal');
- const axios = require('axios');
- const Scraper = require('@yimura/scraper').default;
- const youtube = new Scraper();
- function downloadGambar(url){
- return axios.get(url, {responseType: 'arraybuffer'})
- .then(response => Buffer.from(response.data, "binary").toString("base64"))
- }
- const client = new Client();
- client.on('authenticated', (session) => {
- console.log('AUTHENTICATED', session);
- });
- client.on('qr', (qr) => {
- // Generate and scan this code with your phone
- console.log('QR RECEIVED', qr);
- qrcode.generate(qr, {small: true}, function (qrcode) {
- console.log(qrcode)
- });
- });
- client.on('ready', () => {
- console.log('Client is ready!');
- });
- const prefix = "!";
- client.on('message', async msg => {
- if (msg.body == '!ping') {
- msg.reply('pong');
- }
- if (msg.body == "selamat pagi") {
- client.sendMessage(msg.from, 'selamat pagi juga');
- }
- if (msg.body[0] == prefix){
- var [cmd, ...args] = msg.body.slice(1).split(" ");
- args = args.join(" ");
- if (cmd == "say"){
- client.sendMessage(msg.from, args);
- }
- if (cmd == "gambar"){
- const media = MessageMedia.fromFilePath('./anime/anime-cry.gif');
- client.sendMessage(msg.from, media);
- }
- if (cmd == "kanata"){
- //https://i.waifu.pics/sS-rREz.jpg
- const gambar = await downloadGambar("https://i.waifu.pics/sS-rREz.jpg");
- const media = new MessageMedia('image/jpg', gambar);
- client.sendMessage(msg.from, media);
- }
- if (cmd == "yt" || cmd == "youtube"){
- youtube.search(args).then(results => {
- //console.log(results.videos[0]);
- client.sendMessage(msg.from, results.videos[0].description + " " + results.videos[0].link );
- });
- }
- }
- });
- client.initialize();
Add Comment
Please, Sign In to add comment