text: /* Copyright (C) 2020 farhan-dqz.
  any can add bgm with names
  julie 
  */
  const fs = require('fs')
  const Julie = require('../events');
  const {MessageType, Mimetype } = require('@adiwajshing/baileys');
  const FilterDb = require('./sql/filters');
  const Config = require('../config')
  const jid = Config.DISBGM !== false ? Config.DISBGM.split(',') : [];
  const afn = Config.PLKS !== false ? Config.PLKS.split(',') : [];
  const afnp = Config.THERI_KICK !== false ? Config.THERI_KICK.split(',') : [];
  const Language = require('../language');
  const Lang = Language.getString('filters');
  
  
  Julie.addCommand({pattern: 'filter ?(.*)', fromMe: true, desc: Lang.FILTER_DESC, dontAddCommandList: true}, (async (message, match) => {
      match = match[1].match(/[\'\"\“](.*?)[\'\"\“]/gsm);
  
      if (match === null) {
          filtreler = await FilterDb.getFilter(message.jid);
          if (filtreler === false) {
              await message.client.sendMessage(message.jid,Lang.NO_FILTER,MessageType.text)
          } else {
              var mesaj = Lang.FILTERS + '\n';
              filtreler.map((filter) => mesaj += '```' + filter.dataValues.pattern + '```\n');
              await message.client.sendMessage(message.jid,mesaj,MessageType.text);
          }
      } else {
          if (match.length < 2) {
              return await message.client.sendMessage(message.jid,Lang.NEED_REPLY + ' ```.filter "sa" "as"',MessageType.text);
          }
          await FilterDb.setFilter(message.jid, match[0].replace(/['"“]+/g, ''), match[1].replace(/['"“]+/g, '').replace(/[#]+/g, '\n'), match[0][0] === "'" ? true : false);
          await message.client.sendMessage(message.jid,Lang.FILTERED.format(match[0].replace(/['"]+/g, '')),MessageType.text);
      }
  }));
  Julie.addCommand({pattern: 'stop ?(.*)', fromMe: true, desc: Lang.STOP_DESC, dontAddCommandList: true}, (async (message, match) => {
      match = match[1].match(/[\'\"\“](.*?)[\'\"\“]/gsm);
      if (match === null) {
          return await message.client.sendMessage(message.jid,Lang.NEED_REPLY + '\n*Example:* ```.stop "hello"```',MessageType.text)
      }
  
      del = await FilterDb.deleteFilter(message.jid, match[0].replace(/['"“]+/g, ''));
      
      if (!del) {
          await message.client.sendMessage(message.jid,Lang.ALREADY_NO_FILTER, MessageType.text)
      } else {
          await message.client.sendMessage(message.jid,Lang.DELETED, MessageType.text)
      }
  }));
  
      async function checkUsAdmin(message, user = message.data.participant) {
      var grup = await message.client.groupMetadata(message.jid);
      var sonuc = grup['participants'].map((member) => {     
          if (member.jid.split("@")[0] == user.split("@")[0] && member.isAdmin) return true; else; return false;
      });
      return sonuc.includes(true);
  }
  async function checkImAdmin(message, user = message.client.user.jid) {
      var grup = await message.client.groupMetadata(message.jid);
      var sonuc = grup['participants'].map((member) => {     
          if (member.jid.split("@")[0] == user.split("@")[0] && member.isAdmin) return true; else; return false;
      });
      return sonuc.includes(true);
  }
   
  Julie.addCommand({on: 'text', fromMe: false,onlyGroup: true}, (async (message, match) => {
  
      if(Config.THERI_KICK){
      let banned = jid.find( Jid => Jid === message.jid);
      if(banned !== undefined) return
      
  const array = afn 
  array.map( async (a) => {
  let pattern = new RegExp(`\\b${a}\\b`, 'g');
  if(pattern.test(message.message)){
          var us = await checkUsAdmin(message)
          var im = await checkImAdmin(message)
          if (!im) return;
          if (us) return;
  await message.client.sendMessage(message.jid,Lang.KICK, MessageType.text, {quoted: message.data });  
  await message.client.groupRemove(message.jid, [message.data.participant]);                
  }
  });
  }
  
  var filtreler = await FilterDb.getFilter(message.jid);
  if (!filtreler) return; 
  filtreler.map(
      async (filter) => {
          pattern = new RegExp(filter.dataValues.regex ? filter.dataValues.pattern : ('\\b(' + filter.dataValues.pattern + ')\\b'), 'gm');
      }
  );
  }));
   Julie.addCommand({on: 'text', fromMe: false, onlyPm: true}, (async (message, match) => {
  
      if(Config.PLKS){
  const array = afnp 
  array.map( async (a) => {
  let pattern = new RegExp(`\\b${a}\\b`, 'g');
  if(pattern.test(message.message)){          
  await message.client.sendMessage(message.jid,Lang.KICK2, MessageType.text, {quoted: message.data });               
  }
  });
  }
  
  var filtreler = await FilterDb.getFilter(message.jid);
  if (!filtreler) return; 
  filtreler.map(
      async (filter) => {
          pattern = new RegExp(filter.dataValues.regex ? filter.dataValues.pattern : ('\\b(' + filter.dataValues.pattern + ')\\b'), 'gm');
      }
  );
  }));
  