mirror of
https://github.com/cheveguerra/bot-whatsapp.git
synced 2026-04-20 12:39:24 +00:00
fix(provider): ⚡ baileys fix restart
This commit is contained in:
@@ -37,7 +37,7 @@ class BaileysProvider extends ProviderClass {
|
|||||||
saveCredsGlobal = null
|
saveCredsGlobal = null
|
||||||
constructor() {
|
constructor() {
|
||||||
super()
|
super()
|
||||||
this.initBailey().then(() => this.initBusEvents())
|
this.initBailey().then()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -63,18 +63,28 @@ class BaileysProvider extends ProviderClass {
|
|||||||
|
|
||||||
const statusCode = lastDisconnect?.error?.output?.statusCode
|
const statusCode = lastDisconnect?.error?.output?.statusCode
|
||||||
|
|
||||||
if (statusCode === DisconnectReason.loggedOut) {
|
/** Conexion cerrada por diferentes motivos */
|
||||||
rimraf(PATH_BASE, (err) => {
|
if (connection === 'close') {
|
||||||
if (err) return
|
if (statusCode !== DisconnectReason.loggedOut) {
|
||||||
})
|
this.initBailey()
|
||||||
|
}
|
||||||
|
|
||||||
this.initBailey()
|
if (statusCode === DisconnectReason.loggedOut) {
|
||||||
|
rimraf(PATH_BASE, (err) => {
|
||||||
|
if (err) return
|
||||||
|
})
|
||||||
|
|
||||||
|
this.initBailey()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (statusCode && statusCode !== DisconnectReason.loggedOut) {
|
/** Conexion abierta correctamente */
|
||||||
this.initBailey()
|
if (connection === 'open') {
|
||||||
|
this.emit('ready', true)
|
||||||
|
this.initBusEvents(sock)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** QR Code */
|
||||||
if (qr) {
|
if (qr) {
|
||||||
this.emit('require_action', {
|
this.emit('require_action', {
|
||||||
instructions: [
|
instructions: [
|
||||||
@@ -85,11 +95,11 @@ class BaileysProvider extends ProviderClass {
|
|||||||
})
|
})
|
||||||
await baileyGenerateImage(qr)
|
await baileyGenerateImage(qr)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (connection === 'open') this.emit('ready', true)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
this.vendor = sock
|
sock.ev.on('creds.update', async () => {
|
||||||
|
await saveCreds()
|
||||||
|
})
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger.log(e)
|
logger.log(e)
|
||||||
this.emit('auth_failure', [
|
this.emit('auth_failure', [
|
||||||
@@ -108,12 +118,6 @@ class BaileysProvider extends ProviderClass {
|
|||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
busEvents = () => [
|
busEvents = () => [
|
||||||
{
|
|
||||||
event: 'creds.update',
|
|
||||||
func: async () => {
|
|
||||||
await this.saveCredsGlobal()
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
event: 'messages.upsert',
|
event: 'messages.upsert',
|
||||||
func: ({ messages, type }) => {
|
func: ({ messages, type }) => {
|
||||||
@@ -144,7 +148,8 @@ class BaileysProvider extends ProviderClass {
|
|||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
initBusEvents = () => {
|
initBusEvents = (_sock) => {
|
||||||
|
this.vendor = _sock
|
||||||
const listEvents = this.busEvents()
|
const listEvents = this.busEvents()
|
||||||
|
|
||||||
for (const { event, func } of listEvents) {
|
for (const { event, func } of listEvents) {
|
||||||
|
|||||||
Reference in New Issue
Block a user