-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathfull.js
More file actions
207 lines (180 loc) · 8.46 KB
/
Copy pathfull.js
File metadata and controls
207 lines (180 loc) · 8.46 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
const axios = require("axios");
const mahmud = [
"baby",
"bby",
"babu",
"bbu",
"jan",
"bot",
"জান",
"জানু",
"বেবি",
"wifey",
"hinata",
];
const baseApiUrl = async () => {
const base = await axios.get(
"https://raw.githubusercontent.com/mahmudx7/exe/main/baseApiUrl.json"
);
return base.data.mahmud;
};
/**
* @author MahMUD
* @author: do not delete it
*/
module.exports.config = {
name: "hinata",
aliases: ["baby", "bby", "bbu", "jan", "janu", "wifey", "bot"],
version: "1.7",
author: "MahMUD",
role: 0,
category: "chat",
guide: {
en: "{pn} [message] OR teach [question] - [response1, response2,...] OR remove [question] - [index] OR list OR list all OR edit [question] - [newResponse] OR msg [question]"
}
};
module.exports.onStart = async ({ api, event, args, usersData }) => {
const obfuscatedAuthor = String.fromCharCode(77, 97, 104, 77, 85, 68); if (module.exports.config.author !== obfuscatedAuthor) { return api.sendMessage("You are not authorized to change the author name.", event.threadID, event.messageID); }
const msg = args.join(" ").toLowerCase();
const uid = event.senderID;
try {
if (!args[0]) {
const ran = ["Bolo baby", "hum", "type help baby", "type !baby hi"];
return api.sendMessage(ran[Math.floor(Math.random() * ran.length)], event.threadID, event.messageID);
}
if (args[0] === "teach") {
const mahmud = msg.replace("teach ", "");
const [trigger, ...responsesArr] = mahmud.split(" - ");
const responses = responsesArr.join(" - ");
if (!trigger || !responses) return api.sendMessage("❌ | teach [question] - [response1, response2,...]", event.threadID, event.messageID);
const response = await axios.post(`${await baseApiUrl()}/api/jan/teach2`, { trigger, responses, userID: uid, });
const userName = (await usersData.getName(uid)) || "Unknown User";
return api.sendMessage( `✅ Replies added: "${responses}" to "${trigger}"\n• 𝐓𝐞𝐚𝐜𝐡𝐞𝐫: ${userName}\n• 𝐓𝐨𝐭𝐚𝐥: ${response.data.count || 0}`, event.threadID, event.messageID );
}
if (args[0] === "remove") {
const mahmud = msg.replace("remove ", "");
const [trigger, index] = mahmud.split(" - ");
if (!trigger || !index || isNaN(index)) return api.sendMessage("❌ | remove [question] - [index]", event.threadID, event.messageID);
const response = await axios.delete(`${await baseApiUrl()}/api/jan/remove`, {
data: { trigger, index: parseInt(index, 10) }, });
return api.sendMessage(response.data.message, event.threadID, event.messageID);
}
if (args[0] === "list") {
const endpoint = args[1] === "all" ? "/list/all" : "/list";
const response = await axios.get(`${await baseApiUrl()}/api/jan${endpoint}`);
if (args[1] === "all") { let message = "👑 List of Hinata teachers:\n\n";
const data = Object.entries(response.data.data) .sort((a, b) => b[1] - a[1]) .slice(0, 15); for (let i = 0; i < data.length; i++) {
const [userID, count] = data[i];
const name = (await usersData.getName(userID)) || "Unknown"; message += `${i + 1}. ${name}: ${count}\n`; } return api.sendMessage(message, event.threadID, event.messageID); }
return api.sendMessage(response.data.message, event.threadID, event.messageID);
}
if (args[0] === "edit") {
const mahmud = msg.replace("edit ", "");
const [oldTrigger, ...newArr] = mahmud.split(" - ");
const newResponse = newArr.join(" - "); if (!oldTrigger || !newResponse)
return api.sendMessage("❌ | Format: edit [question] - [newResponse]", event.threadID, event.messageID);
await axios.put(`${await baseApiUrl()}/api/jan/edit2`, { oldTrigger, newResponse });
return api.sendMessage(`✅ Edited "${oldTrigger}" to "${newResponse}"`, event.threadID, event.messageID);
}
if (args[0] === "msg") {
const searchTrigger = args.slice(1).join(" ");
if (!searchTrigger) return api.sendMessage("Please provide a message to search.", event.threadID, event.messageID); try {
const response = await axios.get(`${await baseApiUrl()}/api/jan/msg`, { params: { userMessage: `msg ${searchTrigger}` }, });
return api.sendMessage(response.data.message || "No message found.", event.threadID, event.messageID); } catch (error) {
const errorMessage = error.response?.data?.error || error.message || "error";
return api.sendMessage(errorMessage, event.threadID, event.messageID); }
}
const getBotResponse = async (text, attachments) => { try {
const res = await axios.post(`${await baseApiUrl()}/api/hinata`, { text, style: 3, attachments }); return res.data.message; } catch { return "error janu🥹"; } };
const botResponse = await getBotResponse(msg, event.attachments || []);
api.sendMessage(botResponse, event.threadID, (err, info) => {
if (!err) {
global.GoatBot.onReply.set(info.messageID, {
commandName: "hinata",
type: "reply",
messageID: info.messageID,
author: uid,
text: botResponse
});
}
}, event.messageID);
} catch (err) {
console.error(err);
api.sendMessage(`${err.response?.data || err.message}`, event.threadID, event.messageID);
}
};
module.exports.onReply = async ({ api, event }) => {
if (event.type !== "message_reply") return; try { const getBotResponse = async (text, attachments) => { try {
const res = await axios.post(`${await baseApiUrl()}/api/hinata`, { text, style: 3, attachments }); return res.data.message; } catch { return "error janu🥹"; } };
const replyMessage = await getBotResponse(event.body?.toLowerCase() || "meow", event.attachments || []);
api.sendMessage(replyMessage, event.threadID, (err, info) => {
if (!err) {
global.GoatBot.onReply.set(info.messageID, {
commandName: "hinata",
type: "reply",
messageID: info.messageID,
author: event.senderID,
text: replyMessage
});
}
}, event.messageID);
} catch (err) {
console.error(err);
}
};
module.exports.onChat = async ({ api, event }) => {
try {
const message = event.body?.toLowerCase() || "";
const attachments = event.attachments || [];
if (event.type !== "message_reply" && mahmud.some(word => message.startsWith(word))) {
api.setMessageReaction("🪽", event.messageID, () => {}, true); api.sendTypingIndicator(event.threadID, true); const messageParts = message.trim().split(/\s+/);
const getBotResponse = async (text, attachments) => {
try {
const res = await axios.post(`${await baseApiUrl()}/api/hinata`, { text, style: 3, attachments }); return res.data.message; } catch { return "error janu🥹";
}
};
const randomMessage = [
"babu khuda lagse🥺",
"Hop beda😾,Boss বল boss😼",
"আমাকে ডাকলে ,আমি কিন্তূ কিস করে দেবো😘",
"🐒🐒🐒",
"bye",
"naw amr boss k message daw m.me/mahmud0x7",
"mb ney bye"
];
const hinataMessage = randomMessage[Math.floor(Math.random() * randomMessage.length)];
if (messageParts.length === 1 && attachments.length === 0) {
api.sendMessage(hinataMessage, event.threadID, (err, info) => {
if (!err) {
global.GoatBot.onReply.set(info.messageID, {
commandName: "hinata",
type: "reply",
messageID: info.messageID,
author: event.senderID,
text: hinataMessage
});
}
}, event.messageID);
} else { let userText = message; for (const prefix of mahmud) {
if (message.startsWith(prefix)) { userText = message.substring(prefix.length).trim();
break;
}
}
const botResponse = await getBotResponse(userText, attachments);
api.sendMessage(botResponse, event.threadID, (err, info) => {
if (!err) {
global.GoatBot.onReply.set(info.messageID, {
commandName: "hinata",
type: "reply",
messageID: info.messageID,
author: event.senderID,
text: botResponse
});
}
}, event.messageID);
}
}
} catch (err) {
console.error(err);
}
};