This repository has been archived by the owner on Oct 11, 2023. It is now read-only.
forked from ObamaKntl/YoshinoBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
183 lines (167 loc) · 6.52 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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/**
* Created by Riy
* WhatsApp wa.me/6281575886399
* Follow me on Instagram @riycoders
*/
"use strict";
const {
default: makeWASocket,
BufferJSON,
initInMemoryKeyStore,
jidDecode,
DisconnectReason,
AnyMessageContent,
makeInMemoryStore,
useMultiFileAuthState,
delay
} = require("@whiskeysockets/baileys")
const PhoneNumber = require('awesome-phonenumber');
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 Riy ]')}\n\n${chalk.red('New Bot')} : ${chalk.white('WhatsApp Bot Multi Device')}\n${chalk.red('Follow Insta Dev')} : ${chalk.white('@riycoders')}\n${chalk.red('Message Me On WhatsApp')} : ${chalk.white('+62 815-7588-6399')}\n${chalk.red('Donate')} : ${chalk.white('081575886399 ( Dana/Gopay/Pulsa )')}\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 riyStart() {
const connectToWhatsApp = async () => {
const { state, saveCreds } = await useMultiFileAuthState('auth_info_baileys')
const conn = makeWASocket({
printQRInTerminal: true,
logger: logg({ level: 'fatal' }),
auth: state,
browser: ["New 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 })
conn.decodeJid = (jid) => {
if (!jid) return jid;
if (/:\d+@/gi.test(jid)) {
let decode = jidDecode(jid) || {};
return decode.user && decode.server && decode.user + '@' + decode.server || jid
} else return jid;
};
conn.getName = (jid, withoutContact = false) => {
var id = conn.decodeJid(jid) || jid;
withoutContact = conn.withoutContact || withoutContact;
let v;
if (id.endsWith("@g.us")) return new Promise(async (resolve) => {
v = store.contacts[id] || {};
if (!(v.name || v.subject)) v = conn.groupMetadata(id) || {};
resolve(v.name || v.subject || PhoneNumber('+' + id.replace('@s.whatsapp.net', '')).getNumber('international'));
})
else v = id === '[email protected]' ? {
id,
name: 'WhatsApp',
} : id === conn.decodeJid(conn.user.id) ?
conn.user :
(store.contacts[id] || {})
return (withoutContact ? '' : v.name) || v.subject || v.verifiedName || PhoneNumber('+' + jid.replace('@s.whatsapp.net', '')).getNumber('international');
}
return conn
}
connectToWhatsApp()
.catch(err => console.log(err))
}
riyStart()