forked from mahmud-aura/HINATA
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgemini.js
More file actions
111 lines (94 loc) · 3.12 KB
/
Copy pathgemini.js
File metadata and controls
111 lines (94 loc) · 3.12 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
const axios = require("axios");
const baseApiUrl = async () => {
const base = await axios.get("https://raw.githubusercontent.com/mahmudx7/exe/main/baseApiUrl.json");
return base.data.mahmud
};
module.exports = {
config: {
name: "gemini",
version: "1.7",
author: "MahMUD",
countDown: 5,
role: 0,
category: "ai",
guide: {
en: "{pn} message | reply with an image",
},
},
onStart: async function ({ api, args, event }) {
const apiUrl = `${await baseApiUrl()}/api/gemini`;
const prompt = args.join(" ");
if (!prompt) {
return api.sendMessage(
"Please provide a question to answer.\n\nExample:\n{pn} What is AI?",
event.threadID,
event.messageID
);
}
let requestBody = { prompt };
if (event.type === "message_reply" && event.messageReply.attachments.length > 0) {
const attachment = event.messageReply.attachments[0];
if (attachment.type === "photo") {
requestBody.imageUrl = attachment.url;
}
}
try {
const response = await axios.post(apiUrl, requestBody, {
headers: {
"Content-Type": "application/json",
"author": module.exports.config.author
}
});
if (response.data.error) {
return api.sendMessage(response.data.error, event.threadID, event.messageID);
}
const replyText = response.data.response || "No response received.";
api.sendMessage({ body: replyText }, event.threadID, (error, info) => {
if (!error) {
global.GoatBot.onReply.set(info.messageID, {
commandName: this.config.name,
type: "reply",
messageID: info.messageID,
author: event.senderID,
link: replyText,
});
}
}, event.messageID);
} catch (error) {
console.error("Error:", error);
api.sendMessage("An error occurred. Please try again later.", event.threadID, event.messageID);
}
},
onReply: async function ({ api, args, event, Reply }) {
if (Reply.author !== event.senderID) return;
const apiUrl = `${await baseApiUrl()}/api/gemini`;
const prompt = args.join(" ");
if (!prompt) return;
try {
const response = await axios.post(apiUrl, { prompt }, {
headers: {
"Content-Type": "application/json",
"author": module.exports.config.author
}
});
if (response.data.error) {
return api.sendMessage(response.data.error, event.threadID, event.messageID);
}
const replyText = response.data.response || "No response received.";
api.sendMessage({ body: replyText }, event.threadID, (error, info) => {
if (!error) {
global.GoatBot.onReply.set(info.messageID, {
commandName: this.config.name,
type: "reply",
messageID: info.messageID,
author: event.senderID,
link: replyText,
});
}
}, event.messageID);
} catch (error) {
console.error("Error:", error);
api.sendMessage("error janu, Please try again later 🥹", event.threadID, event.messageID);
}
}
};