-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdevg.js
180 lines (155 loc) · 6.7 KB
/
devg.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
const { BufferJSON, WA_DEFAULT_EPHEMERAL, generateWAMessageFromContent, proto, generateWAMessageContent, generateWAMessage, prepareWAMessageMedia, areJidsSameUser, getContentType } = require("@adiwajshing/baileys");
const fs = require("fs");
const util = require("util");
const chalk = require("chalk");
const { Configuration, OpenAIApi } = require("openai");
let setting = require("dotenv").config().parsed ?? process.env;
const { getMenu, textDavinci003, memeHandler, stableDiffusionApi, dalleHandler, ytApiHandler, summaryHandler, freeBingGPT } = require("./functions");
const { startMLSCBot } = require("./index");
const Chat = require("./models/Chat");
module.exports = chatUpdateFunc = async (client, m, chatUpdate, store) => {
try {
var body =
m.mtype === "conversation"
? m.message.conversation
: m.mtype == "imageMessage"
? m.message.imageMessage.caption
: m.mtype == "videoMessage"
? m.message.videoMessage.caption
: m.mtype == "extendedTextMessage"
? m.message.extendedTextMessage.text
: m.mtype == "buttonsResponseMessage"
? m.message.buttonsResponseMessage.selectedButtonId
: m.mtype == "listResponseMessage"
? m.message.listResponseMessage.singleSelectReply.selectedRowId
: m.mtype == "templateButtonReplyMessage"
? m.message.templateButtonReplyMessage.selectedId
: m.mtype === "messageContextInfo"
? m.message.buttonsResponseMessage?.selectedButtonId || m.message.listResponseMessage?.singleSelectReply.selectedRowId || m.text
: "";
var messageBody = typeof m.text == "string" ? m.text : "";
// var prefix = /^[\\/!#.]/gi.test(body) ? body.match(/^[\\/!#.]/gi) : "/"
var prefix = /^[\\/!#.]/gi.test(body) ? body.match(/^[\\/!#.]/gi) : "/";
const isCmd2 = body.startsWith(prefix);
const command = body.replace(prefix, "").trim().split(/ +/).shift().toLowerCase();
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 ? true : false;
let text = (q = args.join(" "));
const arg = messageBody.trim().substring(messageBody.indexOf(" ") + 1);
const arg1 = arg.trim().substring(arg.indexOf(" ") + 1);
const from = m.chat;
const reply = m.reply;
const sender = m.sender;
const mek = chatUpdate.messages[0];
const color = (text, color) => {
return !color ? chalk.green(text) : chalk.keyword(color)(text);
};
// Group
const groupMetadata = m.isGroup ? await client.groupMetadata(m.chat).catch((e) => { }) : "";
const groupName = m.isGroup ? groupMetadata.subject : "";
// Push Message To Console
let argsLog = messageBody.length > 30 ? `${q.substring(0, 30)}...` : messageBody;
if (m.sender.replace("@s.whatsapp.net", "") == setting.owner) {
return;
}
// const emojiRegex = /\p{Emoji}/u;
// if (emojiRegex.test(body)) {
// return;
// }
var condition = isCmd2;
// var condition = isCmd2 && groupName == setting.group;
if (condition) {
switch (command) {
case "help":
case "menu":
m.reply(getMenu(prefix));
break;
case "bot": case "ai": case "openai":
try {
var resp = await textDavinci003(text);
m.reply(resp);
} catch (error) {
console.log(error);
m.reply("Sorry, there seems to be an error :" + error.message);
}
break;
case "video": case "Video": case "yt":
await ytApiHandler(client, text, from, m);
break;
case 'meme': case "Meme":
await memeHandler(client, mek, from);
case "imagine":
var image = await stableDiffusionApi(text);
client.sendImage(from, image, text, mek);
break;
case "img": case "ai-img": case "image": case "images":
var image = await dalleHandler(text, m);
client.sendImage(from, image, text, mek);
break;
case "summary":case "summarize":
await summaryHandler(groupMetadata,m);
case "freegpt":
await freeBingGPT(text,m);
default: {
if (isCmd2 && messageBody.toLowerCase() != undefined) {
if (m.chat.endsWith("broadcast")) return;
if (m.isBaileys) return;
if (!messageBody.toLowerCase()) return;
if (argsLog || (isCmd2 && !m.isGroup)) {
// client.sendReadReceipt(m.chat, m.sender, [m.key.id])
console.log(chalk.black(chalk.bgRed("[ ERROR ]")), color("command", "turquoise"), color(`${prefix}${command}`, "turquoise"), color("Command Not Found", "turquoise"));
} else if (argsLog || (isCmd2 && m.isGroup)) {
// client.sendReadReceipt(m.chat, m.sender, [m.key.id])
console.log(chalk.black(chalk.bgRed("[ ERROR ]")), color("command", "turquoise"), color(`${prefix}${command}`, "turquoise"), color("Command Not Found", "turquoise"));
}
}
}
}
}
if (m.isGroup && groupName == setting.group) {
// if (itsMe) {
// return;
// }
var finalMessage = {
from: m.sender,
mention: m.mentionedJid.join(','),
pushName: m.pushName,
body: m.body,
text: m.text,
key: JSON.stringify(m.key),
mid: m.key.id,
remoteJid: m.key.remoteJid,
messageTimestamp: m.messageTimestamp,
};
const insert = await Chat.create(finalMessage);
console.log(
chalk.black(chalk.bgWhite("[ LOGS ]")),
// chalk.grey(JSON.stringify(m)),
chalk.green(JSON.stringify(finalMessage), insert));
}
if (isCmd2 && (!m.isGroup || groupName == setting.group)) {
console.log(chalk.black(chalk.bgWhite("[ LOGS ]" + groupName == setting.group ? "Group" : "Personal")), color(argsLog, "turquoise"), chalk.magenta("From"), chalk.green(pushname), chalk.yellow(`[ ${m.sender.replace("@s.whatsapp.net", "")} ]`));
} else if (isCmd2 && m.isGroup) {
console.log(
chalk.black(chalk.bgWhite("[ LOGS ]")),
color(argsLog, "turquoise"),
chalk.magenta("From"),
chalk.green(pushname),
chalk.yellow(`[ ${m.sender.replace("@s.whatsapp.net", "")} ]`),
chalk.blueBright("IN"),
chalk.green(groupName)
);
}
} catch (err) {
console.log(util.format(err));
}
};
let file = require.resolve(__filename);
fs.watchFile(file, () => {
fs.unwatchFile(file);
console.log(chalk.redBright(`Update ${__filename}`));
delete require.cache[file];
require(file);
});