-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathindex.js
More file actions
225 lines (201 loc) · 7.7 KB
/
index.js
File metadata and controls
225 lines (201 loc) · 7.7 KB
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
require('./settings');
const figlet = require('figlet');
const fs = require('fs');
const pino = require('pino');
const path = require('path');
const axios = require('axios');
const chalk = require('chalk');
const readline = require('readline');
const FileType = require('file-type');
const { Boom } = require('@hapi/boom');
const NodeCache = require('node-cache');
const { exec, spawn, execSync } = require('child_process');
const { parsePhoneNumber } = require('awesome-phonenumber');
const { default: WAConnection, useMultiFileAuthState, Browsers, DisconnectReason, makeInMemoryStore, makeCacheableSignalKeyStore, fetchLatestBaileysVersion, proto, getAggregateVotesInPollMessage } = require('@whiskeysockets/baileys');
const pairingCode = process.argv.includes('--qr') ? false : process.argv.includes('--pairing-code') || global.pairing_code;
const rl = readline.createInterface({ input: process.stdin, output: process.stdout })
const store = makeInMemoryStore({ logger: pino().child({ level: 'silent', stream: 'store' }) })
const question = (text) => new Promise((resolve) => rl.question(text, resolve))
global.api = (name, path = '/', query = {}, apikeyqueryname) => (name in global.APIs ? global.APIs[name] : name) + path + (query || apikeyqueryname ? '?' + decodeURIComponent(new URLSearchParams(Object.entries({ ...query, ...(apikeyqueryname ? { [apikeyqueryname]: global.APIKeys[name in global.APIs ? global.APIs[name] : name] } : {}) }))) : '')
const DataBase = require('./src/database');
const database = new DataBase(global.tempatDB);
const msgRetryCounterCache = new NodeCache();
(async () => {
const loadData = await database.read()
if (loadData && Object.keys(loadData).length === 0) {
global.db = {
set: {},
users: {},
game: {},
groups: {},
database: {},
...(loadData || {}),
}
await database.write(global.db)
} else {
global.db = loadData
}
setInterval(async () => {
if (global.db) await database.write(global.db)
}, 30000)
})();
const { GroupUpdate, GroupParticipantsUpdate, MessagesUpsert, Solving } = require('./src/message');
const { isUrl, generateMessageTag, getBuffer, getSizeMedia, fetchJson, sleep } = require('./lib/function');
/*
* Recide By Sychyy @Naze
* Follow https://github.com/nazedev
* Whatsapp : https://wa.me/6287862997267
*/
figlet('SYCH', { font: 'Big' }, (err, data) => {
if (err) {
console.log('Error with figlet...');
return;
}
console.log(chalk.green(data)); // Display the banner in green
});
async function startSychBot() {
const { state, saveCreds } = await useMultiFileAuthState('nazedev');
const { version, isLatest } = await fetchLatestBaileysVersion();
const level = pino({ level: 'silent' })
const getMessage = async (key) => {
if (store) {
const msg = await store.loadMessage(key.remoteJid, key.id);
return msg?.message || ''
}
return {
conversation: 'Halo Saya sychy Bot'
}
}
const sych = WAConnection({
isLatest,
logger: level,
getMessage,
syncFullHistory: true,
maxMsgRetryCount: 15,
msgRetryCounterCache,
retryRequestDelayMs: 10,
defaultQueryTimeoutMs: 0,
printQRInTerminal: !pairingCode,
browser: Browsers.ubuntu('Chrome'),
generateHighQualityLinkPreview: true,
transactionOpts: {
maxCommitRetries: 10,
delayBetweenTriesMs: 10,
},
appStateMacVerification: {
patch: true,
snapshot: true,
},
auth: {
creds: state.creds,
keys: makeCacheableSignalKeyStore(state.keys, level),
},
})
if (pairingCode && !sych.authState.creds.registered) {
let phoneNumber;
async function getPhoneNumber() {
phoneNumber = await question('Please type your WhatsApp number : ');
phoneNumber = phoneNumber.replace(/[^0-9]/g, '')
if (!parsePhoneNumber(phoneNumber).valid && phoneNumber.length < 6) {
console.log(chalk.bgBlack(chalk.redBright('Start with your Country WhatsApp code') + chalk.whiteBright(',') + chalk.greenBright(' Example : 62xxx')));
await getPhoneNumber()
}
}
setTimeout(async () => {
await getPhoneNumber()
await exec('rm -rf ./nazedev/*')
let code = await sych.requestPairingCode(phoneNumber);
console.log(`Your Pairing Code : ${code}`);
}, 3000)
}
store.bind(sych.ev)
await Solving(sych, store)
sych.ev.on('creds.update', saveCreds)
sych.ev.on('connection.update', async (update) => {
const { connection, lastDisconnect, receivedPendingNotifications } = update
if (connection === 'close') {
const reason = new Boom(lastDisconnect?.error)?.output.statusCode
if (reason === DisconnectReason.connectionLost) {
console.log('Connection to Server Lost, Attempting to Reconnect...');
startSychBot()
} else if (reason === DisconnectReason.connectionClosed) {
console.log('Connection closed, Attempting to Reconnect...');
startSychBot()
} else if (reason === DisconnectReason.restartRequired) {
console.log('Restart Required...');
startSychBot()
} else if (reason === DisconnectReason.timedOut) {
console.log('Connection Timed Out, Attempting to Reconnect...');
startSychBot()
} else if (reason === DisconnectReason.badSession) {
console.log('Delete Session and Scan again...');
startSychBot()
} else if (reason === DisconnectReason.connectionReplaced) {
console.log('Close current Session first...');
startSychBot()
} else if (reason === DisconnectReason.loggedOut) {
console.log('Scan again and Run...');
exec('rm -rf ./nazedev/*')
process.exit(1)
} else if (reason === DisconnectReason.Multidevicemismatch) {
console.log('Scan again...');
exec('rm -rf ./nazedev/*')
process.exit(0)
} else {
sych.end(`Unknown DisconnectReason : ${reason}|${connection}`)
}
}
if (connection == 'open') {
console.log('Connected to : ' + JSON.stringify(sych.user, null, 2));
let botNumber = await sych.decodeJid(sych.user.id);
if (db.set[botNumber] && !db.set[botNumber]?.join) {
if (global.my.gc.length > 0 && global.my.gc.includes('whatsapp.com')) {
await sych.groupAcceptInvite(global.my.gc?.split('https://chat.whatsapp.com/')[1]).then(async grupnya => {
await sych.chatModify({ archive: true }, grupnya, [])
db.set[botNumber].join = true
});
}
}
}
if (receivedPendingNotifications == 'true') {
console.log('Please wait About 1 Minute...')
sych.ev.flush()
}
});
sych.ev.on('contacts.update', (update) => {
for (let contact of update) {
let id = sych.decodeJid(contact.id)
if (store && store.contacts) store.contacts[id] = { id, name: contact.notify }
}
});
sych.ev.on('call', async (call) => {
let botNumber = await sych.decodeJid(sych.user.id);
if (db.set[botNumber].anticall) {
for (let id of call) {
if (id.status === 'offer') {
let msg = await sych.sendMessage(id.from, { text: `Saat Ini, Kami Tidak Dapat Menerima Panggilan ${id.isVideo ? 'Video' : 'Suara'}.\nJika @${id.from.split('@')[0]} Memerlukan Bantuan, Silakan Hubungi Owner :)`, mentions: [id.from]});
await sych.sendContact(id.from, global.owner, msg);
await sych.rejectCall(id.id, id.from)
}
}
}
});
sych.ev.on('groups.update', async (update) => {
await GroupUpdate(sych, update, store);
});
sych.ev.on('group-participants.update', async (update) => {
await GroupParticipantsUpdate(sych, update, store);
});
sych.ev.on('messages.upsert', async (message) => {
await MessagesUpsert(sych, message, store);
});
return sych
}
startSychBot()
let file = require.resolve(__filename)
fs.watchFile(file, () => {
fs.unwatchFile(file)
console.log(chalk.redBright(`Update ${__filename}`))
delete require.cache[file]
require(file)
});