|
import wweb from 'whatsapp-web.js' |
|
var model ={ |
|
chat:process.env.chat_model, |
|
imagine:process.env.imagine_model |
|
} |
|
function buildResponse(message){ |
|
return {"messages":[message], |
|
"previewToken":null, |
|
"codeModelMode":true, |
|
"agentMode":{ |
|
"mode":true, |
|
"id":model.chat, |
|
"name":"CUSTOM"}, |
|
"trendingAgentMode":{}, |
|
"isMicMode":false, |
|
"isChromeExt":false, |
|
"githubToken":null, |
|
"clickedAnswer2":false, |
|
"clickedAnswer3":false, |
|
"clickedForceWebSearch":false, |
|
"visitFromDelta":null |
|
} |
|
|
|
|
|
} |
|
function getMessage(content,special,role){ |
|
return {"id":special.generateAlphanumericString(10), |
|
"content":content, |
|
"role":(role==undefined)?"user":role |
|
} |
|
} |
|
async function chat(msg,text,special){ |
|
let response=buildResponse(getMessage(text,special)) |
|
let r=await fetch("https://blackbox.ai/api/chat",{ |
|
method:"post", |
|
headers:{"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.3"}, |
|
body:JSON.stringify(response) |
|
}); |
|
let co=await r.text(); |
|
await special.delay(5000); |
|
await msg.reply(co.split("$@$").slice(2).join('$@$')); |
|
|
|
} |
|
async function imagine(msg,args,special){ |
|
let seed=special.between(1,100000); |
|
let prompt=args.shift(); |
|
let negative_prompt=(args.length>0)?args[0]:""; |
|
const sampler="DPM++ 2M Karras"; |
|
let params={ |
|
new:true, |
|
model: model.imagine, |
|
sampler: sampler, |
|
cfg:13, |
|
steps:20, |
|
seed:seed, |
|
prompt:prompt, |
|
negative_prompt:negative_prompt |
|
}; |
|
const url = "https://api.prodia.com/generate?"+new URLSearchParams(params).toString(); |
|
let resp=await fetch(url); |
|
let response=await resp.json(); |
|
await special.delay(5000); |
|
let r = await fetch("https://api.prodia.com/job/"+response.job); |
|
let s=await r.json(); |
|
while(s.status!="succeeded"){ |
|
await special.delay(500); |
|
r = await fetch("https://api.prodia.com/job/"+response.job); |
|
s=await r.json(); |
|
} |
|
const rurl="https://images.prodia.xyz/"+response.job+".png"; |
|
const pic =await wweb.MessageMedia.fromUrl(rurl); |
|
await special.delay(1000); |
|
await msg.reply(pic); |
|
} |
|
export default function(client,_,special){ |
|
client.on('message_create',async msg=>{ |
|
let texto=msg.body.toString() |
|
if(!texto.startsWith(special.prefix) || !msg.fromMe) return; |
|
let args=texto.slice(special.prefix.length).split(" "); |
|
let command=args.shift(); |
|
args=args.join(" ").split("|"); |
|
if(command=="ia"){ |
|
await chat(msg,args.join('|'),special); |
|
}else if(command=="imagine"){ |
|
await imagine(msg,args,special); |
|
} |
|
|
|
|
|
|
|
}); |
|
return {name:"IA External", |
|
comandos:[ |
|
{name:"ia",description:"Interactua con una ia",args:["[texto]"]}, |
|
{name:"imagine",description:"Imagina",args:["[prompt]","(negative prompt)"]} |
|
]} |
|
} |