text: /**
     * Create By walker
     * Contact Me on wa.me/917356378949
  */
  
  require('./config')
  const { default: makeWASocket, useSingleFileAuthState, DisconnectReason, generateForwardMessageContent, prepareWAMessageMedia, generateWAMessageFromContent, generateMessageID, downloadContentFromMessage } = require("@adiwajshing/baileys-md")
  const { state, saveState } = useSingleFileAuthState(`./${sessionName}.json`)
  const pino = require('pino')
  const fs = require('fs')
  const chalk = require('chalk')
  const fetch = require('node-fetch')
  const FileType = require('file-type')
  const { imageToWebp, videoToWebp, writeExifImg, writeExifVid } = require('./lib/exif')
  const { smsg, isUrl, generateMessageTag } = require('./lib/myfunc')
  
  global.api = (name, path = '/', query = {}, apikeyqueryname) => (name in global.APIs ? global.APIs[name] : name) + path + (query || apikeyqueryname ? '?' + new URLSearchParams(Object.entries({ ...query, ...(apikeyqueryname ? { [apikeyqueryname]: global.APIKeys[name in global.APIs ? global.APIs[name] : name] } : {}) })) : '')
  
  
  async function startHisoka() {
      const hisoka = makeWASocket({
          logger: pino({ level: 'silent' }),
          printQRInTerminal: true,
          browser: ['walker md','Safari','1.0.0'],
          auth: state
      })
  
      hisoka.ev.on('messages.upsert', async chatUpdate => {
          //console.log(JSON.stringify(chatUpdate, undefined, 2))
          try {
          mek = chatUpdate.messages[0]
          if (!mek.message) return
          mek.message = (Object.keys(mek.message)[0] === 'ephemeralMessage') ? mek.message.ephemeralMessage.message : mek.message
          if (mek.key && mek.key.remoteJid === 'status@broadcast') return
          if (!hisoka.public && !mek.key.fromMe && chatUpdate.type === 'notify') return
          if (mek.key.id.startsWith('BAE5') && mek.key.id.length === 16) return
          m = smsg(hisoka, mek)
          require("./hisoka")(hisoka, m, chatUpdate)
          } catch (err) {
              console.log(err)
          }
      })
  
      hisoka.ev.on('group-participants.update', async (anu) => {
          console.log(anu)
          try {
              let metadata = await hisoka.groupMetadata(anu.id)
              let participants = anu.participants
              for (let num of participants) {
                  // Get Profile Picture User
                  try {
                      ppuser = await hisoka.profilePictureUrl(num, 'image')
                  } catch {
                      ppuser = 'https://i0.wp.com/www.gambarunik.id/wp-content/uploads/2019/06/Top-Gambar-Foto-Profil-Kosong-Lucu-Tergokil-.jpg'
                  }
  
                  // Get Profile Picture Group
                  try {
                      ppgroup = await hisoka.profilePictureUrl(anu.id, 'image')
                  } catch {
                      ppgroup = 'https://i0.wp.com/www.gambarunik.id/wp-content/uploads/2019/06/Top-Gambar-Foto-Profil-Kosong-Lucu-Tergokil-.jpg'
                  }
  
                  if (anu.action == 'add') {
                      hisoka.sendMessage(anu.id, { image: { url: ppuser }, contextInfo: { mentionedJid: [num] }, caption: `Welcome To ${metadata.subject} @${num.split("@")[0]}` })
                  } else if (anu.action == 'remove') {
                      hisoka.sendMessage(anu.id, { image: { url: ppuser }, contextInfo: { mentionedJid: [num] }, caption: `@${num.split("@")[0]} Leaving To ${metadata.subject}` })
                  }
              }
          } catch (err) {
              console.log(err)
          }
      })
  	
      // Setting
      hisoka.public = true
  
      hisoka.ev.on('connection.update', async (update) => {
          const { connection, lastDisconnect } = update
          if (connection === 'close') {
              lastDisconnect.error?.output?.statusCode !== DisconnectReason.loggedOut ? startHisoka() : console.log('Disconnected Connection...')
          }
          console.log('Connected Connection...', update)
      })
  
      hisoka.ev.on('creds.update', saveState)
  
      // Add Other
  
      /**
       * 
       * @param {*} jid 
       * @param {*} text 
       * @param {*} quoted 
       * @param {*} options 
       * @returns 
       */
      hisoka.sendText = (jid, text, quoted = '', options) => hisoka.sendMessage(jid, { text: text, ...options }, { quoted })
  
      /**
       * 
       * @param {*} jid 
       * @param {*} path 
       * @param {*} caption 
       * @param {*} quoted 
       * @param {*} options 
       * @returns 
       */
      hisoka.sendImage = async (jid, path, caption = '', quoted = '', options) => {
          let buffer = Buffer.isBuffer(path) ? path : /^data:.*?\/.*?;base64,/i.test(path) ? Buffer.from(path.split`,`[1], 'base64') : /^https?:\/\//.test(path) ? await (await fetch(path)).buffer() : fs.existsSync(path) ? fs.readFileSync(path) : Buffer.alloc(0)
          return await hisoka.sendMessage(jid, { image: buffer, caption: caption, ...options }, { quoted })
      }
  
      /**
       * 
       * @param {*} jid 
       * @param {*} path 
       * @param {*} caption 
       * @param {*} quoted 
       * @param {*} options 
       * @returns 
       */
      hisoka.sendVideo = async (jid, path, caption = '', quoted = '', gif = false, options) => {
          let buffer = Buffer.isBuffer(path) ? path : /^data:.*?\/.*?;base64,/i.test(path) ? Buffer.from(path.split`,`[1], 'base64') : /^https?:\/\//.test(path) ? await (await fetch(path)).buffer() : fs.existsSync(path) ? fs.readFileSync(path) : Buffer.alloc(0)
          return await hisoka.sendMessage(jid, { video: buffer, caption: caption, gifPlayback: gif, ...options }, { quoted })
      }
  
      /**
       * 
       * @param {*} jid 
       * @param {*} path 
       * @param {*} quoted 
       * @param {*} mime 
       * @param {*} options 
       * @returns 
       */
      hisoka.sendAudio = async (jid, path, quoted = '', ptt = false, options) => {
          let buffer = Buffer.isBuffer(path) ? path : /^data:.*?\/.*?;base64,/i.test(path) ? Buffer.from(path.split`,`[1], 'base64') : /^https?:\/\//.test(path) ? await (await fetch(path)).buffer() : fs.existsSync(path) ? fs.readFileSync(path) : Buffer.alloc(0)
          return await hisoka.sendMessage(jid, { audio: buffer, ptt: ptt, ...options }, { quoted })
      }
  
      /**
       * 
       * @param {*} jid 
       * @param {*} text 
       * @param {*} quoted 
       * @param {*} options 
       * @returns 
       */
      hisoka.sendTextWithMentions = async (jid, text, quoted, options = {}) => hisoka.sendMessage(jid, { text: text, contextInfo: { mentionedJid: [...text.matchAll(/@(\d{0,16})/g)].map(v => v[1] + '@s.whatsapp.net') }, ...options }, { quoted })
  
      /**
       * 
       * @param {*} jid 
       * @param {*} path 
       * @param {*} quoted 
       * @param {*} options 
       * @returns 
       */
      hisoka.sendImageAsSticker = async (jid, path, quoted, options = {}) => {
          let buff = Buffer.isBuffer(path) ? path : /^data:.*?\/.*?;base64,/i.test(path) ? Buffer.from(path.split`,`[1], 'base64') : /^https?:\/\//.test(path) ? await (await fetch(path)).buffer() : fs.existsSync(path) ? fs.readFileSync(path) : Buffer.alloc(0)
          let buffer
          if (options && (options.packname || options.author)) {
              buffer = await writeExifImg(buff, options)
          } else {
              buffer = await imageToWebp(buff)
          }
  
          await hisoka.sendMessage(jid, { sticker: { url: buffer }, ...options }, { quoted })
          return buffer
      }
  
      /**
       * 
       * @param {*} jid 
       * @param {*} path 
       * @param {*} quoted 
       * @param {*} options 
       * @returns 
       */
      hisoka.sendVideoAsSticker = async (jid, path, quoted, options = {}) => {
          let buff = Buffer.isBuffer(path) ? path : /^data:.*?\/.*?;base64,/i.test(path) ? Buffer.from(path.split`,`[1], 'base64') : /^https?:\/\//.test(path) ? await getBuffer(path) : fs.existsSync(path) ? fs.readFileSync(path) : Buffer.alloc(0)
          let buffer
          if (options && (options.packname || options.author)) {
              buffer = await writeExifVid(buff, options)
          } else {
              buffer = await videoToWebp(buff)
          }
  
          await hisoka.sendMessage(jid, { sticker: { url: buffer }, ...options }, { quoted })
          return buffer
      }
  	
      /**
       * 
       * @param {*} message 
       * @param {*} filename 
       * @param {*} attachExtension 
       * @returns 
       */
      hisoka.downloadAndSaveMediaMessage = async (message, filename, attachExtension = true) => {
          let quoted = message.msg ? message.msg : message
          let mime = (message.msg || message).mimetype || ''
          let messageType = mime.split('/')[0].replace('application', 'document') ? mime.split('/')[0].replace('application', 'document') : mime.split('/')[0]
          const stream = await downloadContentFromMessage(quoted, messageType)
          let buffer = Buffer.from([])
          for await(const chunk of stream) {
              buffer = Buffer.concat([buffer, chunk])
          }
  	let type = await FileType.fromBuffer(buffer)
          trueFileName = attachExtension ? (filename + '.' + type.ext) : filename
          // save to file
          await fs.writeFileSync(trueFileName, buffer)
          return trueFileName
      }
      
      /**
       * 
       * @param {*} jid 
       * @param {*} path 
       * @param {*} quoted 
       * @param {*} options 
       * @returns 
       */
      hisoka.sendMedia = async (jid, path, quoted, options = {}) => {
  	 let { ext, mime, data } = await hisoka.getFile(path)
  	 messageType = mime.split("/")[0]
  	 pase = messageType.replace('application', 'document') || messageType
  	 return await hisoka.sendMessage(m.chat, { [`${pase}`]: data, mimetype: mime, ...options }, { quoted })
      }
  
      /**
       * 
       * @param {*} jid 
       * @param {*} message 
       * @param {*} forceForward 
       * @param {*} options 
       * @returns 
       */
      hisoka.copyNForward = async (jid, message, forceForward = false, options = {}) => {
          let vtype
  		if (options.readViewOnce) {
  			message.message = message.message && message.message.ephemeralMessage && message.message.ephemeralMessage.message ? message.message.ephemeralMessage.message : (message.message || undefined)
  			vtype = Object.keys(message.message.viewOnceMessage.message)[0]
  			delete(message.message && message.message.ignore ? message.message.ignore : (message.message || undefined))
  			delete message.message.viewOnceMessage.message[vtype].viewOnce
  			message.message = {
  				...message.message.viewOnceMessage.message
  			}
  		}
  
          let mtype = Object.keys(message.message)[0]
          let content = await generateForwardMessageContent(message, forceForward)
          let ctype = Object.keys(content)[0]
  		let context = {}
          if (mtype != "conversation") context = message.message[mtype].contextInfo
          content[ctype].contextInfo = {
              ...context,
              ...content[ctype].contextInfo
          }
          const waMessage = await generateWAMessageFromContent(jid, content, options ? {
              ...content[ctype],
              ...options,
              ...(options.contextInfo ? {
                  contextInfo: {
                      ...content[ctype].contextInfo,
                      ...options.contextInfo
                  }
              } : {})
          } : {})
          await hisoka.relayMessage(jid, waMessage.message, { messageId:  waMessage.key.id })
          return waMessage
      }
  
      /**
       * 
       * @param {*} path 
       * @returns 
       */
      hisoka.getFile = async (path) => {
          let res
  		let data = Buffer.isBuffer(path) ? path : /^data:.*?\/.*?;base64,/i.test(path) ? Buffer.from(path.split`,` [1], 'base64') : /^https?:\/\//.test(path) ? await (res = await fetch(path)).buffer() : fs.existsSync(path) ? fs.readFileSync(path) : typeof path === 'string' ? path : Buffer.alloc(0)
  		if (!Buffer.isBuffer(data)) throw new TypeError('Result is not a buffer')
  		let type = await FileType.fromBuffer(data) || {
  			mime: 'application/octet-stream',
  			ext: '.bin'
  		}
  
  		return {
  			res,
  			...type,
  			data
  		}
      }
  
      return hisoka
  }
  
  startHisoka()
  
  
  let file = require.resolve(__filename)
  fs.watchFile(file, () => {
  	fs.unwatchFile(file)
  	console.log(chalk.redBright(`Update ${__filename}`))
  	delete require.cache[file]
  	require(file)
  })
  