|
|
const util = require('util'); |
|
|
const fetch = require('node-fetch'); |
|
|
const yts = require('yt-search'); |
|
|
|
|
|
let handler = async (m, { conn, text }) => { |
|
|
|
|
|
conn.autoAiMode = conn.autoAiMode || {}; |
|
|
|
|
|
if (!text) throw `*β’ Contoh:* .autoai *[on/off]*`; |
|
|
|
|
|
if (text === "on") { |
|
|
conn.autoAiMode[m.sender] = { pesan: [] }; |
|
|
m.reply("Hai! Auto AI telah diaktifkan! πβ¨"); |
|
|
} else if (text === "off") { |
|
|
delete conn.autoAiMode[m.sender]; |
|
|
m.reply("Auto AI telah dinonaktifkan. Sampai jumpa! π"); |
|
|
} |
|
|
}; |
|
|
|
|
|
handler.before = async (m, { conn }) => { |
|
|
conn.autoAiMode = conn.autoAiMode || {}; |
|
|
if (m.isBaileys && m.fromMe) return; |
|
|
if (!m.text) return; |
|
|
if (!conn.autoAiMode[m.sender]) return; |
|
|
|
|
|
|
|
|
if (m.text.startsWith(".") || m.text.startsWith("#") || m.text.startsWith("!") || m.text.startsWith("/") || m.text.startsWith("\\")) return; |
|
|
|
|
|
|
|
|
if (m.text.toLowerCase().includes("siapa kamu") || m.text.toLowerCase().includes("siapa pembuatmu")) { |
|
|
m.reply("Saya adalah OpenAI Realtime buatan Rizki Irfan. Proyek ini masih baru dan saat ini hanya mendukung AI ,terabox dan mengunduh audio musik dari YouTube. untuk pertanyaan lainya kamu bisa bertanya lewat chat instagram https://www.instagram.com/ikykunnnn untuk *donasi* cukup ketik donasi ya cara penggunan nya cukup gampang misal untuk downlowd musik cukup ketik *tolong putarkan lagu bernadaya* gitu aja nanti respon fitur lain juga sama misal *tolong download kan file dari terabox* terus link nya untuk next fitur lain nya juga sama kaya gitu"); |
|
|
return; |
|
|
} |
|
|
if (m.text.toLowerCase().includes("donasi") || m.text.toLowerCase().includes("qiris")) { |
|
|
m.reply("jika ingin donasi bisa ke qiris ini https://pomf2.lain.la/f/yyj4kr8f.jpg"); |
|
|
return; |
|
|
} |
|
|
|
|
|
if (conn.autoAiMode[m.sender] && m.text) { |
|
|
let name = conn.getName(m.sender); |
|
|
|
|
|
if (m.text.toLowerCase().includes("terabox")) { |
|
|
try { |
|
|
|
|
|
const response = await fetch(`https://api.betabotz.eu.org/api/download/terabox?url=${encodeURIComponent(m.text)}&apikey=btzrizkiirfan1709`); |
|
|
|
|
|
if (!response.ok) throw new Error('Gagal mengambil data dari API Terabox'); |
|
|
|
|
|
const data = await response.json(); |
|
|
if (!data.status) throw new Error('Tidak ada hasil dari API Terabox'); |
|
|
|
|
|
|
|
|
for (let result of data.result) { |
|
|
let file = result.files[0]; |
|
|
let fileUrl = file.url; |
|
|
|
|
|
|
|
|
await conn.sendMessage(m.chat, { document: { url: fileUrl }, mimetype: 'application/octet-stream', fileName: file.filename }, { quoted: m }); |
|
|
} |
|
|
|
|
|
} catch (err) { |
|
|
console.error(err); |
|
|
m.reply(`Terjadi kesalahan: ${util.format(err)}`); |
|
|
} |
|
|
} else if (m.text.toLowerCase().includes("putarkan") || m.text.toLowerCase().includes("lagu") || m.text.toLowerCase().includes("music")) { |
|
|
try { |
|
|
|
|
|
const response = await fetch(`https://ikygantengbangetanjay-api.hf.space/yt?query=${encodeURIComponent(m.text)}`); |
|
|
|
|
|
if (!response.ok) throw new Error('Gagal mengambil data dari API'); |
|
|
|
|
|
const data = await response.json(); |
|
|
if (!data.success) throw new Error('Tidak ada hasil dari API'); |
|
|
|
|
|
let result = data.result; |
|
|
let audioUrl = result.download.audio; |
|
|
|
|
|
|
|
|
if (!audioUrl) throw new Error('URL audio tidak ditemukan'); |
|
|
|
|
|
|
|
|
await conn.sendMessage(m.chat, { audio: { url: audioUrl }, mimetype: 'audio/mpeg' }, { quoted: m }); |
|
|
|
|
|
|
|
|
let videoDetails = `π₯ *Judul:* ${result.title}\n*Link:* ${result.url}\n*Durasi:* ${result.timestamp}\n*Views:* ${result.views}\n*Dari:* [${result.author.name}](${result.author.url})`; |
|
|
await conn.sendMessage(m.chat, { text: videoDetails }, { quoted: m }); |
|
|
|
|
|
} catch (err) { |
|
|
console.error(err); |
|
|
m.reply(`Terjadi kesalahan: ${util.format(err)}`); |
|
|
} |
|
|
} else if (m.text.toLowerCase().includes("yt-search")) { |
|
|
|
|
|
try { |
|
|
const searchQuery = m.text.replace("yt-search", "").trim(); |
|
|
const searchResults = await yts(searchQuery); |
|
|
|
|
|
if (searchResults.videos.length > 0) { |
|
|
let video = searchResults.videos[0]; |
|
|
let hasil = `π₯ *Judul:* ${video.title}\n*Link:* ${video.url}\n*Durasi:* ${video.timestamp}\n*Views:* ${video.views}`; |
|
|
await conn.sendMessage(m.chat, { text: hasil }, { quoted: m }); |
|
|
} else { |
|
|
m.reply("Tidak ada hasil ditemukan di YouTube."); |
|
|
} |
|
|
|
|
|
} catch (err) { |
|
|
console.error(err); |
|
|
m.reply(`Terjadi kesalahan saat mencari di YouTube: ${util.format(err)}`); |
|
|
} |
|
|
} else { |
|
|
|
|
|
try { |
|
|
const response = await fetch(`https://loco.web.id/wp-content/uploads/api/v1/bingai.php?q=${encodeURIComponent(m.text)}`); |
|
|
if (!response.ok) throw new Error('Gagal mengambil data dari API'); |
|
|
|
|
|
const data = await response.json(); |
|
|
if (!data.status) throw new Error('Tidak ada hasil dari API'); |
|
|
|
|
|
let aiResponse = data.result.ai_response; |
|
|
let searchResults = data.result.search_results; |
|
|
|
|
|
|
|
|
if (searchResults && searchResults.length > 0) { |
|
|
let firstSearchResult = searchResults[0]; |
|
|
let hasil = `${aiResponse}\n\n**Hasil Pencarian Pertama:**\n[Link](${firstSearchResult.url})`; |
|
|
await conn.sendMessage(m.chat, { text: hasil }, { quoted: m }); |
|
|
} else { |
|
|
|
|
|
let hasil = `${aiResponse}\n\n**Tidak ada hasil pencarian yang ditemukan.**`; |
|
|
await conn.sendMessage(m.chat, { text: hasil }, { quoted: m }); |
|
|
} |
|
|
|
|
|
} catch (err) { |
|
|
console.error(err); |
|
|
m.reply(`Terjadi kesalahan: ${util.format(err)}`); |
|
|
} |
|
|
} |
|
|
} |
|
|
}; |
|
|
|
|
|
handler.command = /^(autoai)$/i; |
|
|
handler.help = ["autoai"]; |
|
|
handler.tags = ["ai"]; |
|
|
handler.limit = true; |
|
|
|
|
|
module.exports = handler; |