text: /*
  * "Wahai orang-orang yang beriman, mengapakah kamu mengatakan sesuatu yang tidak kamu kerjakan?
  * Amat besar kebencian di sisi Allah bahwa kamu mengatakan apa-apa yang tidak kamu kerjakan."
  * (QS ash-Shaff: 2-3).
  */
  
  /**
   * REFACTORING CODE by Ibnusyawall (https://github.com/ibnusyawall)
   * Don't delete this comment!
   */
  
  const qrcode = require("qrcode-terminal")
  const moment = require("moment-timezone")
  const fs = require("fs")
  
  const time = moment().tz('Asia/Jakarta').format("HH:mm:ss")
  const arrayBulan = ['Januari', 'Februari', 'Maret', 'April', 'Mei', 'Juni', 'Juli', 'Agustus', 'September', 'Oktober', 'November', 'Desember']
  
  const bulan = arrayBulan[moment().format('MM') - 1]
  
  const config = {
      BotName: 'AINE BOT',
      instagram: 'https://instagram.com/anemio999',
      whatsapp: 'wa.me/62895330379186',
      kapanbotaktif: '24 JAM',
      tanggal: `TANGGAL: ${moment().format('DD')} ${bulan} ${moment().format('YYYY')}`,
      waktu: time
  }
  
  const { BotName, tanggal, waktu, instagram, whatsapp, kapanbotaktif: ontime } = config
  
  const
  {
     WAConnection,
     MessageType,
     Presence,
     MessageOptions,
     Mimetype,
     WALocationMessage,
     WA_MESSAGE_STUB_TYPES,
     ReconnectMode,
     ProxyAgent,
     waChatKey,
  } = require("@adiwajshing/baileys")
  
  const {
      menu,
      info,
      donasi,
      alay,
      artinama,
      corona,
      downloadImage,
      igStalk,
      jodoh,
      jsholat,
      lirik,
      nulis,
      readTextInImage,
      pantun,
      quotes,
      searchYoutube,
      surah,
      tiktokdl,
      tweetdl,
      wiki,
      ytdl
  } = require('./lib')
  
  const { animPict, cewePict, cowoPict } = require('./lib/pict')
  
  const { exec } = require("child_process")
  
  const client = new WAConnection()
  
  client.on('qr', qr => {
     qrcode.generate(qr, { small: true })
     console.log(`[ ${time} ] Scan kode qr dengan whatsapp!`)
  })
  
  client.on('credentials-updated', () => {
     const authInfo = client.base64EncodedAuthInfo()
     console.log(`credentials updated!`)
  
     fs.writeFileSync('./session.json', JSON.stringify(authInfo, null, '\t'))
  })
  
  fs.existsSync('./session.json') && client.loadAuthInfo('./session.json')
  
  client.connect();
  
  // client.on('user-presence-update', json => console.log(json.id + ' presence is => ' + json.type)) || console.log(`${time}: Bot by ig:@anemio999`)
  
  client.on('message-status-update', json => {
     const participant = json.participant ? ' (' + json.participant + ')' : ''
     console.log(`[ ${time} ] => bot by ig:@anemio999`)
  })
  
  client.on('message-new', async (m) => {
     const messageContent = m.message
     const text = m.message.conversation
     const messageType = Object.keys(messageContent)[0]
  
     const re = /[\#\!\+\$\@\.]/
  
     const value = text.split(' ').splice(1).join(' ')
  
     let id = m.key.remoteJid
     let imageMessage = m.message.imageMessage
  
     const prefix = messageType === 'imageMessage' ? imageMessage.caption.split(' ')[0].split(re)[1] : text.split(' ')[0].split(re)[1] // multiple prefix
  
     console.log(`[ ${time} ] => Nomor: [ ${id.split("@s.whatsapp.net")[0]} ] => ${text}`);
  
     switch (prefix) {
         case 'menu':
             client.sendMessage(id, menu.menu(id, BotName, tanggal, waktu, instagram, whatsapp, ontime), MessageType.text)
             break
         case 'info':
             client.sendMessage(id, info.info(id, BotName, tanggal, waktu, instagram, whatsapp, ontime), MessageType.text)
             break
         case 'donasi':
             client.sendMessage(id, donasi.donasi(id, BotName, tanggal, waktu, instagram, whatsapp, ontime), MessageType.text)
             break
         case 'nulis':
             nulis(value)
                 .then(data => {
                     client.sendMessage(id, '[ WAIT ] Sedang di proses⏳ silahkan tunggu sebentar', MessageType.text)
                     client.sendMessage(id, data, MessageType.image)
                 })
                 .catch(err => {
                     console.log(err)
                 })
             break
         case 'say':
             await client.sendMessage(id, value, MessageType.text)
             break
         case 'ytmp3':
             ytdl('mp3', value)
                 .then(data => {
                     const { judul, size, hasil: link } = data
                     let hasil = `✅ Lagu Berhasil Di Download, silahkan klik link dan download hasilnya\nKlik link dibawah🗡️\n\nJudul: ${judul}\n\nUkuran audio: ${size}\n\nLink: ${link}`
                     client.sendMessage(id, '[ WAIT ] Sedang di proses⏳ silahkan tunggu sebentar', MessageType.text)
                     client.sendMessage(id, hasil, MessageType.text)
                 })
                 .catch(err => {
                     console.log(err)
                 })
             break
         case 'ytmp4':
             ytdl('mp4', value)
                 .then(data => {
                     const { judul, size, hasil: link } = data
                     let hasil = `✅ Video Berhasil Di Download, silahkan klik link dan download hasilnya\nKlik link dibawah🗡️\n\nJudul: ${judul}\n\nUkuran audio: ${size}\n\nLink: ${link}`
                     client.sendMessage(id, '[ WAIT ] Sedang di proses⏳ silahkan tunggu sebentar', MessageType.text)
                     client.sendMessage(id, hasil, MessageType.text)
                 })
                 .catch(err => {
                     console.log(err)
                 })
             break
         case 'twt':
             tweetdl(value)
                 .then(data => {
                      const { size, hasil: link } = data
                      let hasil = `✅ Berhasil! silahkan klik link di bawah untuk mendownload hasilnya!\nKlik link dibawah🗡️\n\nSize: ${size}\n\nLink: ${link}`
                      client.sendMessage(id, '[ WAIT ] Sedang di proses⏳ silahkan tunggu sebentar', MessageType.text)
                      client.sendMessage(id, hasil ,MessageType.text)
                 })
                 .catch(err => {
                     console.log(err)
                 })
             break
         case 'tiktok':
             tiktokdl(value)
                 .then(data => {
                      const { url, nama, durasi, deskripsi } = data
                      let hasil = `✅ Berhasil!!! Silahkan klik link dibawah ini untuk mendownload hasilnya! \nKlik link dibawah🗡️\n\nJudul: ${deskripsi} \n\nDurasi: ${durasi}\n\nNama: ${nama}\n\nUrl: ${url}`;
                      client.sendMessage(id, hasil, MessageType.text)
                 })
                 .catch(err => {
                     console.log(err)
                 })
             break
         case 'wiki':
             wiki(value)
                 .then(data => {
                      const { hasil: res } = data
                      let hasil = `📝Menurut Wikipedia:\n\n${res}`
                      client.sendMessage(id, hasil, MessageType.text)
                 })
                 .catch(err => {
                     console.log(err)
                 })
             break
         case 'sholat':
             jsholat(value)
                 .then(data => {
                     const { Imsyak, Subuh, Dzuhur, Ashar, Maghrib, Isya, Dhuha } = data
                     let hasil = `Jadwal sholat di *${value}* hari ini adalah\n\n⚡Imsyak : ${Imsyak}\n⚡Subuh : ${Subuh} WIB\n⚡Dzuhur : ${Dzuhur}WIB\n⚡Ashar : ${Ashar} WIB\n⚡Maghrib : ${Maghrib}\n⚡Isya : ${Isya} WIB\n⚡Tengah malam : ${Dhuha} WIB`
                     client.sendMessage(id, hasil, MessageType.text)
                 })
                 .catch(err => {
                     console.log(err)
                 })
             break
         case 'quran':
             surah()
                 .then(data => {
                     const re = /{(.*?)}/gi
                     const { acak, surat } = data
  
                     const keterangan = acak.id.ayat.replace(re, '')
                     const arText = acak.ar.teks
                     const idText = acak.id.teks
                     const surah= surat.nama
  
                     let hasil = `[${keterangan}]   ${arText}\n\n${idText}(QS.${surah}, Ayat ${keterangan})`;
                     client.sendMessage(id, hasil, MessageType.text);
                 })
                 .catch(err => {
                     console.log(err)
                 })
             break
         case 'pantun':
             pantun()
                 .then(data => {
                     client.sendMessage(id, data, MessageType.text)
                 })
                 .catch(err => {
                     console.log(err)
                 })
             break
         case 'covid':
             corona()
                 .then(data => {
                     const { meninggal, sembuh, positif } = data
                     let hasil = `📌DATA WABAH COVID-19 TERBARU DI INDONESIA\n\n📍Positif ==> ${positif} \n📍Sembuh ==> ${sembuh} \n📍Meninggal ==> ${meninggal}`
                     client.sendMessage(id, hasil, MessageType.text)
                 })
                 .catch(err => {
                     console.log(err)
                 })
             break
         case 'quotes':
             quotes()
                 .then(data => {
                     const { author, quotes } = data
                     let hasil = `_${quotes}_\n\n~${author}`
                     client.sendMessage(id, hasil, MessageType.text)
                 })
                 .catch(err => {
                     console.log(err)
                 })
             break
         case 'nama':
             artinama(value)
                 .then(data => {
                     const { result: arti } = data
                     let hasil = `\nArti nama mu adalah\n\n***********************************\n\n       _${value}_ ${arti}\n\n***********************************`
                     client.sendMessage(id, hasil, MessageType.text)
                 })
                 .catch(err => {
                     console.log(err)
                 })
             break
         case 'pasangan':
             jodoh(value)
                 .then(data => {
                     const { positif, negatif } = data
                     const nama = value.split(/[\&\-\/\+]/)
                     let hasil = `\nKecocokan jodoh\n\n************************************\n\nPasangan 1: *${nama[0].trim()}*\nPasangan 2: *${nama[1].trim()}*\n\nsisi positif: ${positif}\nsisi negatif: ${negatif}\n\n***********************************`
                     client.sendMessage(id, hasil, MessageType.text)
                 })
                 .catch(err => {
                     console.log(err)
                 })
             break
         case 'pict':
             switch (value) {
                 case 'cewek':
                     cewePict()
                         .then(buffer => {
                             client.sendMessage(id, '[ WAIT ] Sedang di proses⏳ silahkan tunggu sebentar', MessageType.text)
                             client.sendMessage(id, buffer, MessageType.image)
                         })
                         .catch(err => {
                             console.log(err)
                         })
                     break
                 case 'cowok':
                     cowoPict()
                         .then(buffer => {
                             client.sendMessage(id, '[ WAIT ] Sedang di proses⏳ silahkan tunggu sebentar', MessageType.text)
                             client.sendMessage(id, buffer, MessageType.image)
                         })
                         .catch(err => {
                             console.log(err)
                         })
                     break
                 default:
                     client.sendMessage(id, 'ulangi dengan  !pict cewek/cowok\n\nMisal: !pict cowok', MessageType.text)
                     break
             }
             break
         case 'animepict':
             animPict()
                 .then(buffer => {
                     client.sendMessage(id, '[ WAIT ] Sedang di proses⏳ silahkan tunggu sebentar', MessageType.text)
                     client.sendMessage(id, buffer, MessageType.image)
                 })
                 .catch(err => {
                     console.log(err)
                 })
             break
         case 'lirik':
             lirik(value)
                 .then(data => {
                     const { hasil: lirik } = data
                     let hasil = `📍lirik lagu📍 *${value}* \n\n\n${lirik}`
                     client.sendMessage(id, hasil, MessageType.text)
                 })
                 .catch(err => {
                     console.log(err)
                 })
             break
         case 'alay':
             alay(value)
                 .then(data => {
                     const { hasil: alay } = data
                     client.sendMessage(id, alay, MessageType.text)
                 })
                 .catch(err => {
                     console.log(err)
                 })
             break
         case 'sticker':
             const image = await client.downloadAndSaveMediaMessage(m)
             exec('cwebp -q 50 ' + image + ' -o temp/' + time + '.webp', (error, stdout, stderr) => {
                 let result = fs.readFileSync('temp/' + time + '.webp')
                 client.sendMessage(id, result, MessageType.sticker)
             })
             break
         case 'ocr':
             const media = await client.downloadAndSaveMediaMessage(m)
             readTextInImage(media)
                 .then(data => {
                     client.sendMessage(id, `*Read Data Text in Image* \n\nHasil: \n\n${data}`, MessageType.text);
                 })
                 .catch(err => {
                     console.log(err)
                 })
             break
         case 'igstalk':
             igStalk(value)
                 .then(data => {
                     const { Username, Jumlah_Followers, Jumlah_Following, Name, Jumlah_Post } = data
                     client.sendMessage(id, '[WAIT] Stalking...⏳', MessageType.text)
                     let hasil = `✨Biodata Instagram _${value}_ \n\n 🧶 *Username* : ${Username}_ \n 🌀 *Nama* : _${Name}_ \n 🌟 *Jumlah Followers* : _${Jumlah_Followers}_ \n 🌠 *Jumlah_Following* : _${Jumlah_Following}_ \n ⭐ *Jumlah_Post* : _${Jumlah_Post}_ `
                     client.sendMessage(id, hasil, MessageType.text)
                 })
                 .catch(err => {
                     client.sendMessage(id, err, MessageType.text)
                 })
             break
         default:
             break
     }
  })
  