-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathmain.js
223 lines (203 loc) Β· 7.52 KB
/
main.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
require("./global")
const fs = require("fs");
const path = require("path");
const { Boom } = require("@hapi/boom");
const log = (pino = require("pino"));
const cron = require("node-cron");
const moment = require("moment");
const chalk = require('chalk')
const figlet = require('figlet')
const { color } = require("./lib/function")
const utils = require("./lib/utils");
const {
fetchLatestBaileysVersion,
makeInMemoryStore,
default: Baileys,
useSingleFileAuthState,
jidDecode,
DisconnectReason,
delay,
} = require("@adiwajshing/baileys");
try {
var { state, saveState } = useSingleFileAuthState(path.join(__dirname, `./lib/database/${config.session ? config.session : "session"}.json`), log({ level: "silent" }));
} catch {
fs.unlinkSync(`./lib/database/${config.session ? config.session : "session"}.json`)
var { state, saveState } = useSingleFileAuthState(`./lib/database/${config.session ? config.session : "session"}.json`);
}
moment.locale("id");
const attr = {};
attr.prefix = ".";
attr.uptime = new Date();
attr.command = new Map();
attr.lockcmd = new Map();
attr.isSelf = config.self
global.addMap = (x) => {
attr[x] = new Map();
};
// Store
global.store = makeInMemoryStore({ logger: pino().child({ level: "silent", stream: "store" }) });
const ReadFitur = () => {
let pathdir = path.join(__dirname, "./plugin");
let fitur = fs.readdirSync(pathdir);
console.log(chalk.green('Cargando comandos..'))
fitur.forEach(async (res) => {
const commands = fs.readdirSync(`${pathdir}/${res}`).filter((file) => file.endsWith(".js"));
for (let file of commands) {
const command = require(`${pathdir}/${res}/${file}`);
if (typeof command.run != "function") continue;
const cmdOptions = {
name: "plugin",
alias: [""],
desc: "",
use: "",
type: "", // default: changelog
category: typeof command.category == "undefined" ? "No Category" : res.toLowerCase(),
wait: false,
isOwner: false,
isAdmin: false,
isQuoted: false,
isGroup: false,
isBotAdmin: false,
query: false,
isPrivate: false,
noPrefix: false,
isMedia: {
isQVideo: false,
isQAudio: false,
isQImage: false,
isQSticker: false,
isQDocument: false,
},
disable: false,
isUrl: false,
run: () => {},
};
let cmd = utils.parseOptions(cmdOptions, command);
let options = {};
for (var k in cmd)
typeof cmd[k] == "boolean"
? (options[k] = cmd[k])
: k == "query" || k == "isMedia"
? (options[k] = cmd[k])
: "";
let cmdObject = {
name: cmd.name,
alias: cmd.alias,
desc: cmd.desc,
use: cmd.use,
type: cmd.type,
category: cmd.category,
options: options,
run: cmd.run,
};
attr.command.set(cmd.name, cmdObject);
require("delay")(100);
global.reloadFile(`./plugin/${res}/${file}`);
}
});
console.log(chalk.yellow('Comando cargado con Γ©xitoβ'))
};
// cmd
ReadFitur();
const connect = async() => {
start()
}
async function start(){
let { version, isLatest } = await fetchLatestBaileysVersion()
console.clear();
console.log(color('------------------------------------------------------------------------', 'white'))
// Si el error figlet (Doom), elimine la consola a continuaciΓ³n. [ Para el usuario heroku :v ]
// console.log(color(figlet.textSync('Crls', { font: 'doom', horizontalLayout: 'default' })))
console.log(color('------------------------------------------------------------------------', 'white'))
console.log(color('[CREATOR]', 'aqua'), color(config.author, 'magenta'))
console.log(color('[BOT]', 'aqua'), color('bot nuevo conectado con exitoβ
!', 'magenta'))
console.log(color('[VER]', 'aqua'), color(`${version}`, 'magenta'))
const conn = Baileys({
printQRInTerminal: true,
auth: state,
browser: [config.namebot, "Safari", "1.0.0"],
logger: log({ level: "silent" }),
version,
})
const decodeJid = (jid) => {
if (/:\d+@/gi.test(jid)) {
const decode = jidDecode(jid) || {};
return ((decode.user && decode.server && decode.user + "@" + decode.server) || jid).trim();
} else return jid.trim();
};
store.bind(conn.ev);
conn.ev.on("creds.update", saveState);
conn.ev.on("connection.update", async (ktl) => {
const { lastDisconnect, connection } = ktl;
if (connection == "connecting") console.log(chalk.cyan('ConexiΓ³n al bot de WhatsApp...'))
if (connection) {
if (connection != "connecting")
console.log(chalk.yellow("Connection: " + connection))
}
if (connection == "open") {
console.log(chalk.yellow("Conectado exitosamente a whatsapp"))
conn.sendMessage(config.owner[0],{text: "_*Bot nuevo conectado con Γ©xito β
!*_"})
}
if (connection === "close") {
let reason = new Boom(lastDisconnect.error).output.statusCode;
if (reason === DisconnectReason.badSession) {
console.log(chalk.red(`Archivo de sesiΓ³n incorrecto, elimine la sesiΓ³n y vuelva a escanear`));
conn.logout();
} else if (reason === DisconnectReason.connectionClosed) {
console.log(chalk.red("ConexiΓ³n cerrada, reconectando...."));
start();
} else if (reason === DisconnectReason.connectionLost) {
console.log(chalk.red("ConexiΓ³n perdida del servidor, reconectando..."));
start();
} else if (reason === DisconnectReason.connectionReplaced) {
console.log(chalk.red("ConexiΓ³n reemplazada, otra nueva sesiΓ³n abierta, cierre la sesiΓ³n actual primero"));
conn.logout();
} else if (reason === DisconnectReason.loggedOut) {
console.log(chalk.red(`Dispositivo cerrado, por favor elimine la sesiΓ³n y vuelva a escanear.`));
conn.logout();
} else if (reason === DisconnectReason.restartRequired) {
console.log(chalk.yellow("Reinicio requerido, reiniciar..."));
start();
} else if (reason === DisconnectReason.timedOut) {
console.log("Se agotΓ³ el tiempo de conexiΓ³n, reconectando...");
start();
} else {
conn.end(`Motivo de desconexiΓ³n desconocido: ${reason}|${lastDisconnect.error}`);
}
}
})
conn.ev.on("call", async (senku) => {
console.log(senku)
for(let sen of senku){
if(sen.isGroup == false){
if(sen.status == "offer"){
teks = `*${conn.user.name}* no puedo recibir llamadas ${sen.isVideo ? `video` : `suara`}. Β‘Lo siento, serΓ‘s bloqueado! Si es por accidente, comunΓquese con el propietario.\n\nNΓΊmero de propietario :\n${config.owner.map((a) => `${a.split(`@`)[0]} | ${conn.getName(a).includes("+593") ? "No Detect" : conn.getName(a)
}`).join("\n")}`
conn.sendMessage(sen.from, {text : teks})
await require("delay")(5000);
await conn.updateBlockStatus(sen.from, "block")
}
}
}
})
//contact update
conn.ev.on("contacts.update", (m) => {
for (let kontak of m) {
let jid = decodeJid(kontak.id);
if (store && store.contacts) store.contacts[jid] = { jid, name: kontak.notify };
}
});
// Welcome
conn.ev.on("group-participants.update", async (msg) => {
require("./lib/function/groupUpdate").welcome(conn, msg);
require("./lib/function/groupUpdate").left(conn, msg);
require("./lib/function/groupUpdate").antiluar(conn, msg);
});
conn.ev.on("messages.upsert", async (mek) => {
const msg = mek.messages[0];
const type = msg.message ? Object.keys(msg.message)[0] : "";
if(msg && type == "protocolMessage") conn.ev.emit("message.delete", msg.message.protocolMessage.key);
require('./handler')(mek, conn, attr)
})
}
connect();