forked from Samue-l1/Classic-V4
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart.js
165 lines (136 loc) ยท 6.02 KB
/
start.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
require("./doc/global");
const func = require("./doc/place");
const readline = require("readline");
const yargs = require('yargs/yargs');
const _ = require('lodash');
const usePairingCode = true;
async function fetchJsonMulti(url) {
const fetch = require("node-fetch")
const response = await fetch(url);
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json();
}
const question = (text) => {
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
return new Promise((resolve) => {
rl.question(text, resolve);
});
};
async function startSesi() {
const store = makeInMemoryStore({ logger: pino().child({ level: 'silent', stream: 'store' }) });
const { state, saveCreds } = await useMultiFileAuthState(`./session`);
const { version, isLatest } = await fetchLatestBaileysVersion();
const getMessage = async (key) => {
if (store) {
const msg = await store.loadMessage(key.remoteJid, key.id, undefined);
return msg?.message || undefined;
}
return { conversation: 'WHATSAPP' };
};
const connectionOptions = {
isLatest,
getMessage,
keepAliveIntervalMs: 30000,
printQRInTerminal: !usePairingCode,
logger: pino({ level: "fatal" }),
auth: state,
browser: ['Ubuntu', 'Chrome', '20.0.04']
};
const sam = func.makeWASocket(connectionOptions);
if (usePairingCode && !sam.authState.creds.registered) {
const botnumber = await question(chalk.green.bold(`
please enter your number without (+) 254xxxx:
`));
{
console.log(chalk.blue.bold(`๐ฉ YOUR NUMBER IS CONNECTED SUCCEFUL\n`))
await sleep(1500)
const code = await sam.requestPairingCode(botnumber.trim())
console.log(chalk.green.bold(`[ WhatsApp bot code ] ${code}`))
}}
store.bind(sam.ev)
sam.ev.on('connection.update', async (update) => {
const { connection, lastDisconnect } = update
if (connection === 'close') {
const reason = new Boom(lastDisconnect?.error)?.output.statusCode
console.log(color(lastDisconnect.error, 'deeppink'))
if (lastDisconnect.error == 'Error: Stream Errored (unknown)') {
process.exit()
} else if (reason === DisconnectReason.badSession) {
console.log(color(`Bad Session File, Please Delete Session and Scan Again`))
process.exit()
} else if (reason === DisconnectReason.connectionClosed) {
console.log(color('[SYSTEM]', 'white'), color('Connection closed, reconnecting...', 'deeppink'))
process.exit()
} else if (reason === DisconnectReason.connectionLost) {
console.log(color('[SYSTEM]', 'white'), color('Connection lost, trying to reconnect', 'deeppink'))
process.exit()
} else if (reason === DisconnectReason.connectionReplaced) {
console.log(color('Connection Replaced, Another New Session Opened, Please Close Current Session First'))
sam.logout()
} else if (reason === DisconnectReason.loggedOut) {
console.log(color(`Device Logged Out, Please Scan Again And Run.`))
sam.logout()
} else if (reason === DisconnectReason.restartRequired) {
console.log(color('Restart Required, Restarting...'))
await startSesi()
} else if (reason === DisconnectReason.timedOut) {
console.log(color('Connection TimedOut, Reconnecting...'))
startSesi()
}
} else if (connection === "connecting") {
console.log(chalk.blue.bold(`
๐๐๐๐๐ ๐๐๐ ๐ท๏ธ
,๐๐๐๐๐๐-๐ ๐๐ ๐๐๐๐๐๐ ๐ธ๏ธ`));
} else if (connection === "open") {
let teksnotif = `๐ช\`๐พ๐ก๐๐จ๐จ๐๐ ๐๐จ ๐๐ค๐ฃ๐ฃ๐๐๐ฉ๐๐ ๐ฉ๐ค ${sam.user.id.split(":")[0]}\`
๐
๐ค๐๐ฃ ๐ค๐ช๐ง ๐พ๐๐๐ฃ๐ฃ๐๐ก : https://whatsapp.com/channel/0029VaaqaSp0LKZDuwe5SI3e
๐๐๐ก๐๐๐ง๐๐ข : https://t.me/KingSamHub
๐ฅ ๐๐ฃ๐๐ค๐ฎ ๐ฉ๐๐ ๐ฝ๐ค๐ฉ`;
sam.sendMessage(m.chat, { text: teksnotif });
console.log(chalk.blue.bold(`
๐๐๐๐๐๐๐ ๐4 ๐๐ ๐๐๐๐๐๐
๐๐ ๐ถ๐๐๐ ๐พ๐๐
`));
}
});
sam.ev.on('call', async (user) => {
if (!global.anticall) return;
for (let ff of user) {
if (ff.isGroup == false) {
if (ff.status == "offer") {
let sendcall = await sam.sendMessage(ff.from, { text: `@${ff.from.split("@")[0]} mf`, contextInfo: { mentionedJid: [ff.from], externalAdReply: { showAdAttribution: true, thumbnail: fs.readFileSync("./Media/spider.jpg"), title: "๏ฝข CALL DETECTED ๏ฝฃ", previewType: "PHOTO" } } }, { quoted: null });
sam.sendContact(ff.from, [owner], "Developer WhatsApp Bot", sendcall);
await sleep(10000);
await sam.updateBlockStatus(ff.from, "block");
}
}
}
});
sam.ev.on('messages.upsert', async (chatUpdate) => {
try {
let m = chatUpdate.messages[0];
if (!m.message) return;
m.message = (Object.keys(m.message)[0] === 'ephemeralMessage') ? m.message.ephemeralMessage.message : m.message;
if (m.key && m.key.remoteJid === 'status@broadcast') return sam.readMessages([m.key]);
if (!sam.public && m.key.remoteJid !== global.owner + "@s.whatsapp.net" && !m.key.fromMe && chatUpdate.type === 'notify') return;
if (m.key.id.startsWith('BAE5') && m.key.id.length === 16) return;
if (global.autoread) sam.readMessages([m.key]);
m = func.smsg(sam, m, store);
require("./classic4.js")(sam, m, store);
} catch (err) {
console.log(err);
}
});
sam.public = true;
sam.ev.on('creds.update', saveCreds);
return sam;
}
startSesi();
process.on('uncaughtException', function (err) {
console.log('Caught exception: ', err);
});