forked from victorsouzaleal/lbot-whatsapp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
104 lines (92 loc) · 4.35 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
//REQUERINDO MODULOS
const moment = require("moment-timezone")
moment.tz.setDefault('America/Sao_Paulo')
require('dotenv').config()
const { create, Client } = require('@open-wa/wa-automate')
const {criarArquivosNecessarios, criarTexto, consoleErro, corTexto} = require('./lib/util')
const {verificacaoListaNegraGeral} = require(`./lib/listaNegra`)
const {atualizarParticipantes} = require("./lib/controleParticipantes")
const config = require('./config')
const checagemMensagem = require("./lib/checagemMensagem")
const chamadaComando = require("./lib/chamadaComando")
const msgs_texto = require("./lib/msgs")
const recarregarContagem = require("./lib/recarregarContagem")
const {botStart} = require('./lib/bot')
const {verificarEnv} = require('./lib/env')
const start = async (client = new Client()) => {
try{
//VERIFICA SE É NECESSÁRIO CRIAR ALGUM TIPO DE ARQUIVO NECESSÁRIO
let necessitaCriar = await criarArquivosNecessarios()
if(necessitaCriar){
console.log(corTexto(msgs_texto.inicio.arquivos_criados))
setTimeout(()=>{
return client.kill()
},5000)
} else {
const eventosGrupo = require('./lib/eventosGrupo')
const antiLink = require('./lib/antiLink')
const antiFlood = require('./lib/antiFlood')
const antiTrava = require('./lib/antiTrava')
const antiPorno = require('./lib/antiPorno')
const cadastrarGrupo = require('./lib/cadastrarGrupo')
//Cadastro de grupos
console.log(corTexto(await cadastrarGrupo("","inicio",client)))
//Verificar lista negra dos grupos
console.log(corTexto(await verificacaoListaNegraGeral(client)))
//Atualização dos participantes dos grupos
console.log(corTexto(await atualizarParticipantes(client)))
//Atualização da contagem de mensagens
console.log(corTexto(await recarregarContagem(client)))
//Pegando hora de inicialização do BOT
console.log(corTexto(await botStart()))
//Verificando se os campos do .env foram modificados e envia para o console
verificarEnv()
//INICIO DO SERVIDOR
console.log('[SERVIDOR] Servidor iniciado!')
// Forçando para continuar na sessão atual
client.onStateChanged((estado) => {
console.log('[ESTADO CLIENTE]', estado)
if (estado === 'CONFLICT' || estado === 'UNLAUNCHED') client.forceRefocus()
})
// Ouvindo mensagens
client.onMessage((async (message) => {
if(!await antiTrava(client,message)) return
if(!await antiLink(client,message)) return
if(!await antiFlood(client,message)) return
if(!await antiPorno(client, message)) return
if(!await checagemMensagem(client, message)) return
await chamadaComando(client, message)
}), {})
//Ouvindo entrada/saida de participantes dos grupo
client.onGlobalParticipantsChanged((async (ev) => {
await eventosGrupo(client, ev)
}))
//Ouvindo se a entrada do BOT em grupos
client.onAddedToGroup((async (chat) => {
await cadastrarGrupo(chat.id, "added", client)
let gInfo = await client.getGroupInfo(chat.id)
await client.sendText(chat.id, criarTexto(msgs_texto.geral.entrada_grupo, gInfo.title))
}))
// Ouvindo ligações recebidas
client.onIncomingCall(( async (call) => {
await client.sendText(call.peerJid, msgs_texto.geral.sem_ligacoes).then(async ()=>{
client.contactBlock(call.peerJid)
})
}))
/* PARA FINS DE TESTE
client.onAnyMessage((async (message) =>{
if (message.fromMe) await chamadaComando(client, message)
})) */
}
} catch(err) {
//Faça algo se der erro em alguma das funções acima
console.log(err)
console.error(corTexto("[ERRO FATAL]","#d63e3e"), err.message)
setTimeout(()=>{
return client.kill()
},10000)
}
}
create(config(true, start))
.then(client => start(client))
.catch((error) => consoleErro(error, 'OPEN-WA'))