Updates to commands
This commit is contained in:
parent
8f0deb0072
commit
6ed2f4f1a1
2 changed files with 109 additions and 82 deletions
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "himbot",
|
||||
"version": "1.0.0",
|
||||
"version": "4.2.0",
|
||||
"engines": {
|
||||
"node": ">=18.16.0"
|
||||
},
|
||||
|
|
|
@ -39,7 +39,18 @@ export class UserCommand extends Command {
|
|||
? await interactionOrMessage.channel.send({ content: '🤔 Thinking... 🤔' })
|
||||
: await interactionOrMessage.reply({ content: '🤔 Thinking... 🤔', fetchReply: true });
|
||||
|
||||
const response = await fetch(`https://api.stability.ai/v1/generation/stable-diffusion-xl-1024-v0-9/text-to-image`, {
|
||||
const creditCountResponse = await fetch(`https://api.stability.ai/v1/user/balance`, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: `Bearer ${process.env.STABILITY_API_KEY}`
|
||||
}
|
||||
});
|
||||
|
||||
const balance = (await creditCountResponse.json()).credits || 0;
|
||||
|
||||
if (balance > 5) {
|
||||
const imageGenResponse = await fetch(`https://api.stability.ai/v1/generation/stable-diffusion-xl-1024-v0-9/text-to-image`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
|
@ -69,7 +80,7 @@ export class UserCommand extends Command {
|
|||
}>;
|
||||
}
|
||||
|
||||
if (!response.ok) {
|
||||
if (!imageGenResponse.ok) {
|
||||
const content = `Sorry! I goofed up. Please ask my maker HimbothySwaggins about what could have happened!`;
|
||||
|
||||
if (interactionOrMessage instanceof Message) {
|
||||
|
@ -80,10 +91,15 @@ export class UserCommand extends Command {
|
|||
content: content
|
||||
});
|
||||
} else {
|
||||
const responseJSON = (await response.json()) as GenerationResponse;
|
||||
const responseJSON = (await imageGenResponse.json()) as GenerationResponse;
|
||||
const imageAttachment = new AttachmentBuilder(Buffer.from(responseJSON.artifacts[0].base64, 'base64'));
|
||||
|
||||
const content = `Prompt: ${prompt}` || 'ERROR!';
|
||||
const content =
|
||||
`Prompt: ${prompt}${
|
||||
balance &&
|
||||
balance <= 200 &&
|
||||
`\n\n... also, we are now at ${balance} credits. If you'd like to help fund this command, please type "/support" for details!`
|
||||
}` || 'ERROR!';
|
||||
|
||||
if (interactionOrMessage instanceof Message) {
|
||||
return askMessage.edit({ content, files: [imageAttachment] });
|
||||
|
@ -94,5 +110,16 @@ export class UserCommand extends Command {
|
|||
files: [imageAttachment]
|
||||
});
|
||||
}
|
||||
} else {
|
||||
const content = `Oops! We're out of credits for this. If you'd like to help fund this command, please type "/support" for details!`;
|
||||
|
||||
if (interactionOrMessage instanceof Message) {
|
||||
return askMessage.edit({ content });
|
||||
}
|
||||
|
||||
return interactionOrMessage.editReply({
|
||||
content: content
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue