forked from Keithkeizzah/KEITH-MD
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkeith.js
151 lines (128 loc) · 6.48 KB
/
keith.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
const {
BufferJSON, WA_DEFAULT_EPHEMERAL, generateWAMessageFromContent, proto, generateWAMessageContent,
generateWAMessage, prepareWAMessageMedia, areJidsSameUser, getContentType
} = require("@whiskeysockets/baileys");
const fs = require("fs");
const util = require("util");
const chalk = require("chalk");
const speed = require("performance-now");
const {
smsg, formatp, tanggal, formatDate, getTime, sleep, clockString, fetchJson, getBuffer, jsonformat, generateProfilePicture,
parseMention, getRandom, fetchBuffer
} = require('./lib/botFunctions.js');
const daddy = "[email protected]";
const { exec, spawn, execSync } = require("child_process");
const { TelegraPh, UploadFileUgu } = require("./lib/toUrl");
const uploadtoimgur = require('./lib/Imgur');
const ytmp3 = require('./lib/ytmp3');
const path = require('path');
const { commands, totalCommands } = require('./commandHandler');
const blocked_users = require('./Functions/blocked_users');
const status_saver = require('./Functions/status_saver');
const eval2 = require('./Functions/eval2');
const eval = require('./Functions/eval');
const antiviewonce = require('./Functions/antiviewonce');
const gcPresence = require('./Functions/gcPresence');
const antilinkgc = require('./Functions/antilink');
const antitaggc = require('./Functions/antitag');
const antibadgc = require('./Functions/antibad');
const antidel = require('./Functions/antidelete');
const antibotgc = require('./Functions/antibot');
const masterEval = require('./Functions/masterEval');
const {
presence, autoread, botname, mode, prefix, mycode, author, packname,
dev, gcpresence, antionce, permit, antitag, antibad, antibot, antilink, antidelete
} = require('./settings');
module.exports = Keith = async (client, m, chatUpdate, message, store) => {
try {
let body = m.mtype === "conversation" ? m.message.conversation :
m.mtype === "imageMessage" ? m.message.imageMessage.caption :
m.mtype === "extendedTextMessage" ? m.message.extendedTextMessage.text : "";
const Tag = m.mtype === "extendedTextMessage" && m.message.extendedTextMessage.contextInfo != null
? m.message.extendedTextMessage.contextInfo.mentionedJid
: [];
let msgKeith = m.message.extendedTextMessage?.contextInfo?.quotedMessage;
let budy = typeof m.text === "string" ? m.text : "";
const timestamp = speed();
const Keithspeed = speed() - timestamp;
const cmd = body.startsWith(prefix);
const args = body.trim().split(/ +/).slice(1);
const pushname = m.pushName || "No Name";
const botNumber = await client.decodeJid(client.user.id);
const itsMe = m.sender === botNumber;
const isBotMessage = m.sender === botNumber;
let text = args.join(" ");
const arg = budy.trim().substring(budy.indexOf(" ") + 1);
const arg1 = arg.trim().substring(arg.indexOf(" ") + 1);
const getGroupAdmins = (participants) => {
let admins = [];
for (let i of participants) {
if (i.admin === "superadmin") admins.push(i.id);
if (i.admin === "admin") admins.push(i.id);
}
return admins || [];
};
const keizzah = m.quoted || m;
const quoted = keizzah.mtype === 'buttonsMessage' ? keizzah[Object.keys(keizzah)[1]] :
keizzah.mtype === 'templateMessage' ? keizzah.hydratedTemplate[Object.keys(keizzah.hydratedTemplate)[1]] :
keizzah.mtype === 'product' ? keizzah[Object.keys(keizzah)[0]] : m.quoted ? m.quoted : m;
const color = (text, color) => {
return color ? chalk.keyword(color)(text) : chalk.green(text);
};
const mime = quoted.mimetype || "";
const qmsg = quoted;
const DevKeith = dev.split(",");
const Owner = DevKeith.map(v => v.replace(/[^0-9]/g, "") + "@s.whatsapp.net").includes(m.sender);
const groupMetadata = m.isGroup ? await client.groupMetadata(m.chat).catch(() => {}) : "";
const groupName = m.isGroup && groupMetadata ? groupMetadata.subject : "";
const participants = m.isGroup && groupMetadata ? groupMetadata.participants : [];
const groupAdmin = m.isGroup ? getGroupAdmins(participants) : [];
const isBotAdmin = m.isGroup ? groupAdmin.includes(botNumber) : false;
const isAdmin = m.isGroup ? groupAdmin.includes(m.sender) : false;
const IsGroup = m.chat?.endsWith("@g.us");
const context = {
client, m, text, isBotMessage, message, Owner, chatUpdate, store, isBotAdmin, isAdmin, IsGroup,
participants, pushname, body, budy, totalCommands, args, mime, qmsg, msgKeith, botNumber, itsMe, packname,
author, generateProfilePicture, groupMetadata, Keithspeed, mycode, fetchJson, exec, antibad, getRandom, UploadFileUgu,
TelegraPh, prefix, cmd, botname, mode, gcpresence, antibot, permit, antitag, antilink, antidelete, antionce, fetchBuffer,
store, uploadtoimgur, chatUpdate, ytmp3, getGroupAdmins, Tag
};
if (cmd && mode === 'private' && !itsMe && !Owner && m.sender !== daddy) {
return;
}
if (m.chat.endsWith('@s.whatsapp.net') && cmd && permit === 'true' && !Owner) {
await m.reply("Access denied");
return;
}
if (await blocked_users(client, m, cmd)) {
await m.reply("You are blocked from using bot commands.");
return;
}
await status_saver(client, m, Owner, prefix);
await eval2(client, m, Owner, budy, fetchJson);
await eval(client, m, Owner, budy, fetchJson, store);
await antilinkgc(client, m, isBotAdmin, itsMe, isAdmin, Owner, body, antilink);
await antiviewonce(client, m, antionce);
await antidel(client, m, antidelete);
await gcPresence(client, m, gcpresence);
await antibadgc(client, m, isBotAdmin, itsMe, isAdmin, Owner, body, antibad);
await antitaggc(client, m, isBotAdmin, itsMe, isAdmin, Owner, body, antitag);
await antibotgc(client, m, isBotAdmin, itsMe, isAdmin, Owner, body, isBotMessage, message, antibot);
await masterEval(client, m, Owner, budy, fetchJson, store);
const command = cmd ? body.replace(prefix, "").trim().split(/ +/).shift().toLowerCase() : null;
if (commands[command]) {
await commands[command](context);
}
} catch (err) {
console.error(util.format(err));
}
process.on('uncaughtException', (errr) => {
let e = String(errr);
if (e.includes("conflict") || e.includes("not-authorized") || e.includes("Socket connection timeout") ||
e.includes("rate-overlimit") || e.includes("Connection Closed") || e.includes("Timed Out") ||
e.includes("Value not found")) {
return;
}
console.error('Caught exception: ', errr);
});
};