misc: add generate command
This commit is contained in:
parent
dc03de59c4
commit
a3a693a727
1 changed files with 36 additions and 0 deletions
|
@ -394,3 +394,39 @@ shodan.callback = async function (msg, line) {
|
|||
};
|
||||
};
|
||||
hf.registerCommand(shodan);
|
||||
|
||||
const GENERATE_HEADERS = {
|
||||
Accept: "application/json",
|
||||
"Content-Type": "application/json",
|
||||
};
|
||||
const generate = new Command("generate");
|
||||
generate.category = CATEGORY;
|
||||
generate.helpText = "Generate images from prompt via craiyon";
|
||||
generate.callback = async function (msg, line) {
|
||||
if (!line || line.length === 0) return "Arguments required.";
|
||||
|
||||
let request = await fetch("https://backend.craiyon.com/generate", {
|
||||
headers: GENERATE_HEADERS,
|
||||
body: JSON.stringify({prompt: line}),
|
||||
});
|
||||
while (request.status !== 200) {
|
||||
request = await fetch("https://backend.craiyon.com/generate", {
|
||||
headers: GENERATE_HEADERS,
|
||||
body: JSON.stringify({prompt: line}),
|
||||
});
|
||||
}
|
||||
|
||||
const data = await request.json();
|
||||
const images = data.images.map((img) => Buffer.from(img, "base64"));
|
||||
|
||||
for (const index in images) {
|
||||
const img = images[index];
|
||||
await msg.channel.createMessage(
|
||||
`Response ${Number(index) + 1} for \`${safeString(line)}\`:`,
|
||||
{file: img, name: `${index}.jpg`}
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
hf.registerCommand(generate);
|
||||
|
|
Loading…
Reference in a new issue