-
Notifications
You must be signed in to change notification settings - Fork 10
/
index.js
131 lines (118 loc) · 4.35 KB
/
index.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
"use strict";
const {
default: makeWASocket,
BufferJSON,
initInMemoryKeyStore,
DisconnectReason,
AnyMessageContent,
makeInMemoryStore,
useMultiFileAuthState,
delay,
generateWAMessageFromContent
} = require("baileys-md")
const figlet = require("figlet");
const fs = require("fs");
const moment = require('moment')
const chalk = require('chalk')
const logg = require('pino')
const clui = require('clui')
const { Spinner } = clui
const { serialize } = require("./lib/myfunc");
const { color, mylog, infolog } = require("./lib/color");
const time = moment(new Date()).format('HH:mm:ss DD/MM/YYYY')
let setting = JSON.parse(fs.readFileSync('./config.json'));
function title() {
console.clear()
console.log(chalk.bold.green(figlet.textSync('Bot Menfess', {
font: 'Standard',
horizontalLayout: 'default',
verticalLayout: 'default',
width: 80,
whitespaceBreak: false
})))
console.log(chalk.yellow(`\n ${chalk.yellow('[ Created By Irfan ]')}\n\n${chalk.red('Bot Menfess')} : ${chalk.white('WhatsApp Bot For Send Secret Message')}\n${chalk.red('Follow Insta Dev')} : ${chalk.white('@irfann._x')}\n${chalk.red('Message Me On WhatsApp')} : ${chalk.white('+62 851-7522-2272')}\n`))
}
/**
* Uncache if there is file change;
* @param {string} module Module name or path;
* @param {function} cb <optional> ;
*/
function nocache(module, cb = () => { }) {
console.log(`Module ${module} sedang diperhatikan terhadap perubahan`)
fs.watchFile(require.resolve(module), async () => {
await uncache(require.resolve(module))
cb(module)
})
}
/**
* Uncache a module
* @param {string} module Module name or path;
*/
function uncache(module = '.') {
return new Promise((resolve, reject) => {
try {
delete require.cache[require.resolve(module)]
resolve()
} catch (e) {
reject(e)
}
})
}
const status = new Spinner(chalk.cyan(` Booting WhatsApp Bot`))
const starting = new Spinner(chalk.cyan(` Preparing After Connect`))
const reconnect = new Spinner(chalk.redBright(` Reconnecting WhatsApp Bot`))
const store = makeInMemoryStore({ logger: logg().child({ level: 'fatal', stream: 'store' }) })
async function fanStart() {
const connectToWhatsApp = async () => {
const { state, saveCreds } = await useMultiFileAuthState('auth_info_baileys')
const conn = makeWASocket({
printQRInTerminal: true,
logger: logg({ level: 'fatal' }),
auth: state,
browser: ["Bot Confess", "Safari", "3.0"],
getMessage: async key => {
return {
}
}
})
title()
store.bind(conn.ev)
/* Auto Update */
require('./lib/myfunc')
require('./message/msg')
nocache('./lib/myfunc', module => console.log(chalk.greenBright('[ WHATSAPP BOT ] ') + time + chalk.cyanBright(` "${module}" Telah diupdate!`)))
nocache('./message/msg', module => console.log(chalk.greenBright('[ WHATSAPP BOT ] ') + time + chalk.cyanBright(` "${module}" Telah diupdate!`)))
conn.multi = true
conn.nopref = false
conn.prefa = 'anjing'
conn.ev.on('messages.upsert', async m => {
if (!m.messages) return;
var msg = m.messages[0]
try { if (msg.message.messageContextInfo) delete msg.message.messageContextInfo } catch { }
msg = serialize(conn, msg)
msg.isBaileys = msg.key.id.startsWith('BAE5')
require('./message/msg')(conn, msg, m, setting, store)
})
conn.ev.on('connection.update', (update) => {
if (global.qr !== update.qr) {
global.qr = update.qr
}
const { connection, lastDisconnect } = update
if (connection === 'close') {
lastDisconnect.error?.output?.statusCode !== DisconnectReason.loggedOut ? connectToWhatsApp() : console.log('connection logged out...')
}
})
conn.ev.on('creds.update', await saveCreds)
conn.reply = (from, content, msg) => conn.sendMessage(from, { text: content }, { quoted: msg })
conn.sendMessageFromContent = async(jid, message, options = {}) => {
var option = { contextInfo: {}, ...options }
var prepare = await generateWAMessageFromContent(jid, message, option)
await conn.relayMessage(jid, prepare.message, { messageId: prepare.key.id })
return prepare
}
return conn
}
connectToWhatsApp()
.catch(err => console.log(err))
}
fanStart()