Commands updated

This commit is contained in:
Atridad Lahiji 2023-12-03 16:05:43 -07:00
parent 43b7b3fd2e
commit 2d0e8ab106
No known key found for this signature in database

View file

@ -1,6 +1,6 @@
import { ApplyOptions } from '@sapphire/decorators'; import { ApplyOptions } from '@sapphire/decorators';
import { Args, BucketScope, Command } from '@sapphire/framework'; import { Args, BucketScope, Command } from '@sapphire/framework';
import { Message } from 'discord.js'; import { AttachmentBuilder, Message } from 'discord.js';
import Replicate from 'replicate'; import Replicate from 'replicate';
const replicate = new Replicate({ const replicate = new Replicate({
@ -49,13 +49,17 @@ export class UserCommand extends Command {
let result = (await replicate.run('stability-ai/sdxl:39ed52f2a78e934b3ba6e2a89f5b1c712de7dfea535525255b1aa35c5565e08b', { let result = (await replicate.run('stability-ai/sdxl:39ed52f2a78e934b3ba6e2a89f5b1c712de7dfea535525255b1aa35c5565e08b', {
input: { input: {
width: 1024,
height: 1024,
prompt, prompt,
disable_safety_checker: true, disable_safety_checker: true,
refine: 'expert_ensemble_refiner', refine: 'expert_ensemble_refiner',
num_inference_steps: 50, scheduler: 'KarrasDPM',
scheduler: 'K_EULER', num_outputs: 1,
width: 1024, guidance_scale: 7.5,
height: 1024 high_noise_frac: 0.8,
prompt_strength: 0.8,
num_inference_steps: 50
} }
})) as string[]; })) as string[];
@ -70,14 +74,28 @@ export class UserCommand extends Command {
content: content content: content
}); });
} else { } else {
const content = `Prompt: ${prompt}\n URL: ${result[0]}`; const imageUrl = result[0] || '';
// get an array buffer
const imageBuffer = await fetch(imageUrl).then((r) => r.arrayBuffer());
const imageAttachment: AttachmentBuilder[] = [];
imageAttachment.push(
new AttachmentBuilder(Buffer.from(new Uint8Array(imageBuffer)), {
name: 'himbot_response.jpg',
description: `An image generated by Himbot using the prompt: ${prompt}`
})
);
const content = `Prompt: ${prompt}`;
if (interactionOrMessage instanceof Message) { if (interactionOrMessage instanceof Message) {
return askMessage.edit({ content }); return askMessage.edit({ content, files: imageAttachment });
} }
return interactionOrMessage.editReply({ return interactionOrMessage.editReply({
content content,
files: imageAttachment
}); });
} }
} }