-
Notifications
You must be signed in to change notification settings - Fork 120
/
Copy pathindex.js
156 lines (142 loc) · 5.59 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/**
* Edit features in './message/msg.js'
* Contact me on WhatsApp wa.me/628988808885
* Follow https://github.com/rtwone
* If you want to buy an updated script that is not encrypted, please WhatsApp me
*/
"use strict";
const {
default: makeWASocket,
BufferJSON,
initInMemoryKeyStore,
DisconnectReason,
AnyMessageContent,
makeInMemoryStore,
useMultiFileAuthState,
delay
} = require("@adiwajshing/baileys")
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'));
let session = `./${setting.sessionName}.json`
let welcome = JSON.parse(fs.readFileSync('./database/welcome.json'));
function title() {
console.clear()
console.log(chalk.bold.green(figlet.textSync('WaBot MD', {
font: 'Standard',
horizontalLayout: 'default',
verticalLayout: 'default',
width: 80,
whitespaceBreak: false
})))
console.log(chalk.yellow(`\n ${chalk.yellow('[ Created By Irfan ]')}\n\n${chalk.red('Chitanda Eru Bot')} : ${chalk.white('WhatsApp Bot Multi Device')}\n${chalk.red('Follow Insta Dev')} : ${chalk.white('@irfann._x')}\n${chalk.red('Message Me On WhatsApp')} : ${chalk.white('+62 857-9145-8996')}\n${chalk.red('Donate')} : ${chalk.white('085791458996 ( Ovo/Pulsa/Dana )')}\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: ["Chitanda Eru Multi Device", "Safari", "3.0"],
getMessage: async key => {
return {
}
}
})
title()
store.bind(conn.ev)
/* Auto Update */
require('./message/help')
require('./lib/myfunc')
require('./message/msg')
nocache('./message/help', module => console.log(chalk.greenBright('[ WHATSAPP BOT ] ') + time + chalk.cyanBright(` "${module}" Telah diupdate!`)))
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.mode = 'public'
conn.ev.on('messages.upsert', async m => {
if (!m.messages) return;
var msg = m.messages[0]
msg = serialize(conn, msg)
msg.isBaileys = msg.key.id.startsWith('BAE5') || msg.key.id.startsWith('3EB0')
require('./message/msg')(conn, msg, m, setting, store, welcome)
})
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.ev.on('group-participants.update', async (data) => {
const isWelcome = welcome.includes(data.id) ? true : false
if (isWelcome) {
try {
for (let i of data.participants) {
try {
var pp_user = await conn.profilePictureUrl(i, 'image')
} catch {
var pp_user = 'https://i0.wp.com/www.gambarunik.id/wp-content/uploads/2019/06/Top-Gambar-Foto-Profil-Kosong-Lucu-Tergokil-.jpg'
}
if (data.action == "add") {
conn.sendMessage(data.id, { image: { url: pp_user }, caption: `Welcome @${i.split("@")[0]}`, mentions: [i] })
} else if (data.action == "remove") {
conn.sendMessage(data.id, { image: { url: pp_user }, caption: `Sayonara @${i.split("@")[0]}`, mentions: [i] })
}
}
} catch (e) {
console.log(e)
}
}
})
conn.reply = (from, content, msg) => conn.sendMessage(from, { text: content }, { quoted: msg })
return conn
}
connectToWhatsApp()
.catch(err => console.log(err))
}
fanStart()