index.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. const { create, Client } = require('@open-wa/wa-automate')
  2. const welcome = require('./lib/welcome')
  3. const msgHandler = require('./msgHndlr')
  4. const options = require('./options')
  5. const start = async (client = new Client()) => {
  6. console.log('[SERVER] Server Started!')
  7. // Force it to keep the current session
  8. client.onStateChanged((state) => {
  9. console.log('[Client State]', state)
  10. if (state === 'CONFLICT' || state === 'UNLAUNCHED') client.forceRefocus()
  11. })
  12. // listening on message
  13. client.onMessage((async (message) => {
  14. client.getAmountOfLoadedMessages()
  15. .then((msg) => {
  16. if (msg >= 3000) {
  17. client.cutMsgCache()
  18. }
  19. })
  20. msgHandler(client, message)
  21. }))
  22. client.onGlobalParicipantsChanged((async (heuh) => {
  23. await welcome(client, heuh)
  24. //left(client, heuh)
  25. }))
  26. client.onAddedToGroup(((chat) => {
  27. let totalMem = chat.groupMetadata.participants.length
  28. if (totalMem < 30) {
  29. client.sendText(chat.id, `Cih member nya cuma ${totalMem}, Kalo mau invite bot, minimal jumlah mem ada 30`).then(() => client.leaveGroup(chat.id)).then(() => client.deleteChat(chat.id))
  30. } else {
  31. client.sendText(chat.groupMetadata.id, `Halo warga grup *${chat.contact.name}* terimakasih sudah menginvite bot ini, untuk melihat menu silahkan kirim *!help*`)
  32. }
  33. }))
  34. /*client.onAck((x => {
  35. const { from, to, ack } = x
  36. if (x !== 3) client.sendSeen(to)
  37. }))*/
  38. // listening on Incoming Call
  39. client.onIncomingCall(( async (call) => {
  40. await client.sendText(call.peerJid, 'Maaf, saya tidak bisa menerima panggilan. nelfon = block!')
  41. .then(() => client.contactBlock(call.peerJid))
  42. }))
  43. }
  44. create(options(true, start))
  45. .then(client => start(client))
  46. .catch((error) => console.log(error))