Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
235 changes: 167 additions & 68 deletions scripts/cmds/gpt.js
Original file line number Diff line number Diff line change
@@ -1,93 +1,192 @@
const axios = require('axios');
const tracker = {};
const fs = require('fs-extra');
const path = require('path');
const ytdl = require("@neoxr/ytdl-core");
const yts = require("yt-search");

/*
A Turtle APIs Production created by Turtle Rehat.
Do not alter the credited information any attempt to do so may result in a permanent ban from Project86 APIs and Turtle APIs.
*/
async function lado(api, event, args, message) {
try {
const songName = args.join(" ");
const searchResults = await yts(songName);

module.exports = {
config: {
name: "gpt",
version: "1.0",
author: "rehat--",
countDown: 5,
role: 0,
longDescription: "Chat GPT 4 Most Advance LLM",
category: "ai",
guide: { en: "{pn} <query>" },
},
clearHistory: function () {
global.GoatBot.onReply.clear();
},
onStart: async function ({ message, event, args, usersData, api, commandName }) {
const prompt = args.join(' ');
const userID = event.senderID;
const mid = event.messageID;
if (!searchResults.videos.length) {
message.reply("No song found for the given query.");
return;
}

if (!args[0]) return message.reply('Please enter a query.');
const video = searchResults.videos[0];
const videoUrl = video.url;
const stream = ytdl(videoUrl, { filter: "audioonly" });
const fileName = `music.mp3`;
const filePath = path.join(__dirname, "tmp", fileName);

if (args[0] == 'clear') {
this.clearHistory();
const c = await clean(userID);
if (c) return message.reply('Conversation history cleared.');
}
stream.pipe(fs.createWriteStream(filePath));

api.setMessageReaction('⏳', mid, () => {}, true);
gpt(prompt, userID, message, mid, api);
},
stream.on('response', () => {
console.info('[DOWNLOADER]', 'Starting download now!');
});

onReply: async function ({ Reply, message, event, args, api, usersData }) {
const { author } = Reply;
if (author !== event.senderID) return;
stream.on('info', (info) => {
console.info('[DOWNLOADER]', `Downloading ${info.videoDetails.title} by ${info.videoDetails.author.name}`);
});

const mid = event.messageID;
const prompt = args.join(' ');
const userID = event.senderID;
stream.on('end', () => {
const audioStream = fs.createReadStream(filePath);
message.reply({ attachment: audioStream });
api.setMessageReaction("✅", event.messageID, () => {}, true);
});
} catch (error) {
console.error("Error:", error);
message.reply("Sorry, an error occurred while processing your request.");
}
}

if (args[0] == 'clear') {
this.clearHistory();
const c = await clean(userID);
if (c) return message.reply('Conversation history cleared.');
async function kshitiz(api, event, args, message) {
try {
const query = args.join(" ");
const searchResults = await yts(query);

if (!searchResults.videos.length) {
message.reply("No videos found for the given query.");
return;
}

api.setMessageReaction('⏳', mid, () => {}, true);
gpt(prompt, userID, message, mid, api);
const video = searchResults.videos[0];
const videoUrl = video.url;
const stream = ytdl(videoUrl, { filter: "audioandvideo" });
const fileName = `music.mp4`;
const filePath = path.join(__dirname, "tmp", fileName);

stream.pipe(fs.createWriteStream(filePath));

stream.on('response', () => {
console.info('[DOWNLOADER]', 'Starting download now!');
});

stream.on('info', (info) => {
console.info('[DOWNLOADER]', `Downloading ${info.videoDetails.title} by ${info.videoDetails.author.name}`);
});

stream.on('end', () => {
const videoStream = fs.createReadStream(filePath);
message.reply({ attachment: videoStream });
api.setMessageReaction("✅", event.messageID, () => {}, true);
});
} catch (error) {
console.error(error);
message.reply("Sorry, an error occurred while processing your request.");
}
}


const a = {
name: "gpt",
aliases: ["chatgpt"],
version: "3.0",
author: "vex_kshitiz",
countDown: 5,
role: 0,
longDescription: "Chat with GPT-4",
category: "ai",
guide: {
en: "{p}gpt {prompt}"
}
};

async function clean(userID) {
if (!tracker[userID]) return true;
if (tracker[userID]) {
delete tracker[userID];
return true;
async function b(c, d, e, f) {
try {
const g = await axios.get(`https://ai-tools.replit.app/gpt?prompt=${encodeURIComponent(c)}&uid=${d}&apikey=kshitiz`);
return g.data.gpt4;
} catch (h) {
throw h;
}
}

async function gpt(text, userID, message, mid, api) {
tracker[userID] = tracker[userID] || '';
tracker[userID] += `${text}.\n`;
async function i(c) {
try {
const j = await axios.get(`https://ai-tools.replit.app/sdxl?prompt=${encodeURIComponent(c)}&styles=7`, { responseType: 'arraybuffer' });
return j.data;
} catch (k) {
throw k;
}
}

async function describeImage(prompt, photoUrl) {
try {
const url = 'https://project86.cyclic.app/api/chat';

const conversationHistory = encodeURIComponent(tracker[userID]);
const getUrl = `${url}?query=${conversationHistory}`;
const url = `https://sandipbaruwal.onrender.com/gemini2?prompt=${encodeURIComponent(prompt)}&url=${encodeURIComponent(photoUrl)}`;
const response = await axios.get(url);
return response.data.answer;
} catch (error) {
throw error;
}
}

const response = await axios.post(getUrl);
async function l({ api, message, event, args }) {
try {
const m = event.senderID;
const n = args.join(" ").trim();
const draw = args[0].toLowerCase() === "draw";
const prompt = args[0].toLowerCase() === "prompt";
const sendTikTok = args[0].toLowerCase() === "send";
const sing = args[0].toLowerCase() === "sing";

const resultText = response.data.answer;
tracker[userID] = `${tracker[userID]}${text}.\n${resultText}`;
if (!n) {
return message.reply("Please provide a prompt.");
}

api.setMessageReaction('✅', mid, () => {}, true);
message.reply(`${resultText}\n\n𝙔𝙤𝙪 𝙘𝙖𝙣 𝙧𝙚𝙥𝙡𝙮 𝙩𝙤 𝙘𝙤𝙣𝙩𝙞𝙣𝙪𝙚 𝙘𝙝𝙖𝙩𝙩𝙞𝙣𝙜.`, (error, info) => {
global.GoatBot.onReply.set(info.messageID, {
commandName: 'gpt',
author: userID,
if (draw) {
await drawImage(message, n);
} else if (prompt) {
if (event.messageReply && event.messageReply.attachments && event.messageReply.attachments.length > 0) {
const photoUrl = event.messageReply.attachments[0].url;
const description = await describeImage(n, photoUrl);
message.reply(`Description: ${description}`);
} else {
return message.reply("Please reply to an image to describe it.");
}
} else if (sendTikTok) {
await kshitiz(api, event, args.slice(1), message);
} else if (sing) {
await lado(api, event, args.slice(1), message);
} else {
const q = await b(n, m);
message.reply(q, (r, s) => {
global.GoatBot.onReply.set(s.messageID, {
commandName: a.name,
uid: m
});
});
}
} catch (t) {
console.error("Error:", t.message);
message.reply("An error occurred while processing the request.");
}
}

async function drawImage(message, prompt) {
try {
const u = await i(prompt);

const v = path.join(__dirname, 'cache', `image_${Date.now()}.png`);
fs.writeFileSync(v, u);

message.reply({
body: "Generated image:",
attachment: fs.createReadStream(v)
});
} catch (error) {
api.setMessageReaction('❌', mid, () => {}, true);
message.reply('An error occurred.');
} catch (w) {
console.error("Error:", w.message);
message.reply("An error occurred while processing the request.");
}
}
}

module.exports = {
config: a,
handleCommand: l,
onStart: function ({ api, message, event, args }) {
return l({ api, message, event, args });
},
onReply: function ({ api, message, event, args }) {
return l({ api, message, event, args });
}
};