-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
237 lines (222 loc) · 8.91 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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
/**
* Edit features in './message/msg.js'
* Contact me on WhatsApp wa.me/6285791458996
* 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,
useSingleFileAuthState,
makeInMemoryStore,
delay,
downloadContentFromMessage,
jidDecode,
generateForwardMessageContent,
generateWAMessageFromContent,
proto,
prepareWAMessageMedia
} = 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, getBuffer } = 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`
const { state, saveState } = useSingleFileAuthState(session)
let welcome = JSON.parse(fs.readFileSync('./database/welcome.json'));
function title() {
console.clear()
console.log(chalk.bold.green(figlet.textSync('Kurumi Tokisaki-Md', {
font: 'Standard',
horizontalLayout: 'default',
verticalLayout: 'default',
width: 80,
whitespaceBreak: false
})))
console.log(chalk.yellow(`\n ${chalk.yellow('[ Created By Satganz Devs ]')}\n\n${chalk.red('Satganz Devs')} : ${chalk.white('WhatsApp Bot Multi Device')}\n${chalk.red('Subs Channel Devs')} : ${chalk.white('SatganzDevs')}\n${chalk.red('Message Me On WhatsApp')} : ${chalk.white('6281316701742')}\n${chalk.red('Donate')} : ${chalk.white('6282398383300 ( Gopay )')}\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' }) })
const connectToWhatsApp = async () => {
const conn = makeWASocket({
printQRInTerminal: true,
logger: logg({ level: 'fatal' }),
auth: state,
browser: ["Satganz Devs", "Safari", "1.0.0"]
})
title()
store.bind(conn.ev)
/* Auto Update */
require('./message/help')
require('./lib/myfunc')
require('./message/msg')
nocache('./message/help', module => console.log(chalk.greenBright('[ SATGANZDEVS ] ') + time + chalk.cyanBright(` "${module}" Telah diupdate!`)))
nocache('./lib/myfunc', module => console.log(chalk.greenBright('[ SATGANZDEVS ] ') + time + chalk.cyanBright(` "${module}" Telah diupdate!`)))
nocache('./message/msg', module => console.log(chalk.greenBright('[ SATGANZDEVS ] ') + time + chalk.cyanBright(` "${module}" Telah diupdate!`)))
conn.multi = true
conn.nopref = false
conn.prefa = ''
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) => {
const { connection, lastDisconnect } = update
if (connection === 'close') {
status.stop()
reconnect.stop()
starting.stop()
console.log(mylog('Server Ready ✓'))
lastDisconnect.error?.output?.statusCode !== DisconnectReason.loggedOut
? connectToWhatsApp()
: console.log(mylog('Wa web terlogout...'))
}
})
conn.ev.on('creds.update', () => saveState)
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 })
// Set Bio
conn.setStatus = (status) => {
conn.query({
tag: 'iq',
attrs: {
to: '@s.whatsapp.net',
type: 'set',
xmlns: 'status',
},
content: [{
tag: 'status',
attrs: {},
content: Buffer.from(status, 'utf-8')
}]
})
return status
}
conn.downloadAndSaveMediaMessage = async(msg, type_file, path_file) => {
if (type_file === 'image') {
var stream = await downloadContentFromMessage(msg.message.imageMessage || msg.message.extendedTextMessage?.contextInfo.quotedMessage.imageMessage, 'image')
let buffer = Buffer.from([])
for await(const chunk of stream) {
buffer = Buffer.concat([buffer, chunk])
}
fs.writeFileSync(path_file, buffer)
return path_file
} else if (type_file === 'video') {
var stream = await downloadContentFromMessage(msg.message.videoMessage || msg.message.extendedTextMessage?.contextInfo.quotedMessage.videoMessage, 'video')
let buffer = Buffer.from([])
for await(const chunk of stream) {
buffer = Buffer.concat([buffer, chunk])
}
fs.writeFileSync(path_file, buffer)
return path_file
} else if (type_file === 'sticker') {
var stream = await downloadContentFromMessage(msg.message.stickerMessage || msg.message.extendedTextMessage?.contextInfo.quotedMessage.stickerMessage, 'sticker')
let buffer = Buffer.from([])
for await(const chunk of stream) {
buffer = Buffer.concat([buffer, chunk])
}
fs.writeFileSync(path_file, buffer)
return path_file
} else if (type_file === 'audio') {
var stream = await downloadContentFromMessage(msg.message.audioMessage || msg.message.extendedTextMessage?.contextInfo.quotedMessage.audioMessage, 'audio')
let buffer = Buffer.from([])
for await(const chunk of stream) {
buffer = Buffer.concat([buffer, chunk])
}
fs.writeFileSync(path_file, buffer)
return path_file
}
}
// Resize
conn.reSize = async (image, width, height) => {
let jimp = require('jimp')
var oyy = await jimp.read(image);
var kiyomasa = await oyy.resize(width, height).getBufferAsync(jimp.MIME_JPEG)
return kiyomasa
}
// Send 5 Button Location
conn.send5ButLoc = async (jid , text = '' , footer = '', lok, but = [], options = {}) =>{
let resize = await conn.reSize(lok, 300, 150)
var template = generateWAMessageFromContent(jid, {
"templateMessage": {
"hydratedTemplate": {
"locationMessage": {
"degreesLatitude": 0,
"degreesLongitude": 0,
"jpegThumbnail": resize,
"thumbnailUrl": setting.group
},
"hydratedContentText": text,
"hydratedFooterText": footer,
"hydratedButtons": but
}
}
}, options)
conn.relayMessage(jid, template.message, { messageId: template.key.id })
}
return conn
}
connectToWhatsApp()
.catch(err => console.log(err))