Updates to commands
This commit is contained in:
parent
8f0deb0072
commit
6ed2f4f1a1
2 changed files with 109 additions and 82 deletions
84
package.json
84
package.json
|
@ -1,43 +1,43 @@
|
|||
{
|
||||
"name": "himbot",
|
||||
"version": "1.0.0",
|
||||
"engines": {
|
||||
"node": ">=18.16.0"
|
||||
},
|
||||
"main": "dist/index.js",
|
||||
"author": "@sapphire",
|
||||
"license": "UNLICENSE",
|
||||
"type": "commonjs",
|
||||
"dependencies": {
|
||||
"@sapphire/decorators": "^6.0.1",
|
||||
"@sapphire/discord.js-utilities": "7.0.0",
|
||||
"@sapphire/framework": "^4.5.0",
|
||||
"@sapphire/plugin-logger": "^3.0.4",
|
||||
"@sapphire/utilities": "^3.12.0",
|
||||
"@skyra/env-utilities": "^1.2.1",
|
||||
"colorette": "^2.0.20",
|
||||
"discord.js": "^14.11.0",
|
||||
"openai": "^3.3.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@sapphire/cli": "^1.6.1",
|
||||
"@sapphire/prettier-config": "^1.4.5",
|
||||
"@sapphire/ts-config": "^4.0.0",
|
||||
"@types/node": "^20.3.3",
|
||||
"@types/ws": "^8.5.5",
|
||||
"prettier": "^2.8.8",
|
||||
"tsc-watch": "^6.0.4",
|
||||
"typescript": "^5.1.6"
|
||||
},
|
||||
"scripts": {
|
||||
"sapphire": "sapphire",
|
||||
"generate": "sapphire generate",
|
||||
"build": "tsc",
|
||||
"watch": "tsc -w",
|
||||
"start": "node dist/index.js",
|
||||
"dev": "npm run build && npm run start",
|
||||
"watch:start": "tsc-watch --onSuccess \"npm run start\"",
|
||||
"format": "prettier --write \"src/\""
|
||||
},
|
||||
"prettier": "@sapphire/prettier-config"
|
||||
}
|
||||
"name": "himbot",
|
||||
"version": "4.2.0",
|
||||
"engines": {
|
||||
"node": ">=18.16.0"
|
||||
},
|
||||
"main": "dist/index.js",
|
||||
"author": "@sapphire",
|
||||
"license": "UNLICENSE",
|
||||
"type": "commonjs",
|
||||
"dependencies": {
|
||||
"@sapphire/decorators": "^6.0.1",
|
||||
"@sapphire/discord.js-utilities": "7.0.0",
|
||||
"@sapphire/framework": "^4.5.0",
|
||||
"@sapphire/plugin-logger": "^3.0.4",
|
||||
"@sapphire/utilities": "^3.12.0",
|
||||
"@skyra/env-utilities": "^1.2.1",
|
||||
"colorette": "^2.0.20",
|
||||
"discord.js": "^14.11.0",
|
||||
"openai": "^3.3.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@sapphire/cli": "^1.6.1",
|
||||
"@sapphire/prettier-config": "^1.4.5",
|
||||
"@sapphire/ts-config": "^4.0.0",
|
||||
"@types/node": "^20.3.3",
|
||||
"@types/ws": "^8.5.5",
|
||||
"prettier": "^2.8.8",
|
||||
"tsc-watch": "^6.0.4",
|
||||
"typescript": "^5.1.6"
|
||||
},
|
||||
"scripts": {
|
||||
"sapphire": "sapphire",
|
||||
"generate": "sapphire generate",
|
||||
"build": "tsc",
|
||||
"watch": "tsc -w",
|
||||
"start": "node dist/index.js",
|
||||
"dev": "npm run build && npm run start",
|
||||
"watch:start": "tsc-watch --onSuccess \"npm run start\"",
|
||||
"format": "prettier --write \"src/\""
|
||||
},
|
||||
"prettier": "@sapphire/prettier-config"
|
||||
}
|
||||
|
|
|
@ -39,38 +39,79 @@ 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`, {
|
||||
method: 'POST',
|
||||
const creditCountResponse = await fetch(`https://api.stability.ai/v1/user/balance`, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Accept: 'application/json',
|
||||
Authorization: `Bearer ${process.env.STABILITY_API_KEY}`
|
||||
},
|
||||
body: JSON.stringify({
|
||||
text_prompts: [
|
||||
{
|
||||
text: prompt
|
||||
}
|
||||
],
|
||||
cfg_scale: 6,
|
||||
clip_guidance_preset: 'FAST_BLUE',
|
||||
height: 1024,
|
||||
width: 1024,
|
||||
samples: 1,
|
||||
steps: 32
|
||||
})
|
||||
}
|
||||
});
|
||||
|
||||
interface GenerationResponse {
|
||||
artifacts: Array<{
|
||||
base64: string;
|
||||
seed: number;
|
||||
finishReason: string;
|
||||
}>;
|
||||
}
|
||||
const balance = (await creditCountResponse.json()).credits || 0;
|
||||
|
||||
if (!response.ok) {
|
||||
const content = `Sorry! I goofed up. Please ask my maker HimbothySwaggins about what could have happened!`;
|
||||
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',
|
||||
Accept: 'application/json',
|
||||
Authorization: `Bearer ${process.env.STABILITY_API_KEY}`
|
||||
},
|
||||
body: JSON.stringify({
|
||||
text_prompts: [
|
||||
{
|
||||
text: prompt
|
||||
}
|
||||
],
|
||||
cfg_scale: 6,
|
||||
clip_guidance_preset: 'FAST_BLUE',
|
||||
height: 1024,
|
||||
width: 1024,
|
||||
samples: 1,
|
||||
steps: 32
|
||||
})
|
||||
});
|
||||
|
||||
interface GenerationResponse {
|
||||
artifacts: Array<{
|
||||
base64: string;
|
||||
seed: number;
|
||||
finishReason: string;
|
||||
}>;
|
||||
}
|
||||
|
||||
if (!imageGenResponse.ok) {
|
||||
const content = `Sorry! I goofed up. Please ask my maker HimbothySwaggins about what could have happened!`;
|
||||
|
||||
if (interactionOrMessage instanceof Message) {
|
||||
return askMessage.edit({ content });
|
||||
}
|
||||
|
||||
return interactionOrMessage.editReply({
|
||||
content: content
|
||||
});
|
||||
} else {
|
||||
const responseJSON = (await imageGenResponse.json()) as GenerationResponse;
|
||||
const imageAttachment = new AttachmentBuilder(Buffer.from(responseJSON.artifacts[0].base64, 'base64'));
|
||||
|
||||
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] });
|
||||
}
|
||||
|
||||
return interactionOrMessage.editReply({
|
||||
content: content,
|
||||
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 });
|
||||
|
@ -79,20 +120,6 @@ export class UserCommand extends Command {
|
|||
return interactionOrMessage.editReply({
|
||||
content: content
|
||||
});
|
||||
} else {
|
||||
const responseJSON = (await response.json()) as GenerationResponse;
|
||||
const imageAttachment = new AttachmentBuilder(Buffer.from(responseJSON.artifacts[0].base64, 'base64'));
|
||||
|
||||
const content = `Prompt: ${prompt}` || 'ERROR!';
|
||||
|
||||
if (interactionOrMessage instanceof Message) {
|
||||
return askMessage.edit({ content, files: [imageAttachment] });
|
||||
}
|
||||
|
||||
return interactionOrMessage.editReply({
|
||||
content: content,
|
||||
files: [imageAttachment]
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue