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",
|
"name": "himbot",
|
||||||
"version": "1.0.0",
|
"version": "4.2.0",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=18.16.0"
|
"node": ">=18.16.0"
|
||||||
},
|
},
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"author": "@sapphire",
|
"author": "@sapphire",
|
||||||
"license": "UNLICENSE",
|
"license": "UNLICENSE",
|
||||||
"type": "commonjs",
|
"type": "commonjs",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@sapphire/decorators": "^6.0.1",
|
"@sapphire/decorators": "^6.0.1",
|
||||||
"@sapphire/discord.js-utilities": "7.0.0",
|
"@sapphire/discord.js-utilities": "7.0.0",
|
||||||
"@sapphire/framework": "^4.5.0",
|
"@sapphire/framework": "^4.5.0",
|
||||||
"@sapphire/plugin-logger": "^3.0.4",
|
"@sapphire/plugin-logger": "^3.0.4",
|
||||||
"@sapphire/utilities": "^3.12.0",
|
"@sapphire/utilities": "^3.12.0",
|
||||||
"@skyra/env-utilities": "^1.2.1",
|
"@skyra/env-utilities": "^1.2.1",
|
||||||
"colorette": "^2.0.20",
|
"colorette": "^2.0.20",
|
||||||
"discord.js": "^14.11.0",
|
"discord.js": "^14.11.0",
|
||||||
"openai": "^3.3.0"
|
"openai": "^3.3.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@sapphire/cli": "^1.6.1",
|
"@sapphire/cli": "^1.6.1",
|
||||||
"@sapphire/prettier-config": "^1.4.5",
|
"@sapphire/prettier-config": "^1.4.5",
|
||||||
"@sapphire/ts-config": "^4.0.0",
|
"@sapphire/ts-config": "^4.0.0",
|
||||||
"@types/node": "^20.3.3",
|
"@types/node": "^20.3.3",
|
||||||
"@types/ws": "^8.5.5",
|
"@types/ws": "^8.5.5",
|
||||||
"prettier": "^2.8.8",
|
"prettier": "^2.8.8",
|
||||||
"tsc-watch": "^6.0.4",
|
"tsc-watch": "^6.0.4",
|
||||||
"typescript": "^5.1.6"
|
"typescript": "^5.1.6"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"sapphire": "sapphire",
|
"sapphire": "sapphire",
|
||||||
"generate": "sapphire generate",
|
"generate": "sapphire generate",
|
||||||
"build": "tsc",
|
"build": "tsc",
|
||||||
"watch": "tsc -w",
|
"watch": "tsc -w",
|
||||||
"start": "node dist/index.js",
|
"start": "node dist/index.js",
|
||||||
"dev": "npm run build && npm run start",
|
"dev": "npm run build && npm run start",
|
||||||
"watch:start": "tsc-watch --onSuccess \"npm run start\"",
|
"watch:start": "tsc-watch --onSuccess \"npm run start\"",
|
||||||
"format": "prettier --write \"src/\""
|
"format": "prettier --write \"src/\""
|
||||||
},
|
},
|
||||||
"prettier": "@sapphire/prettier-config"
|
"prettier": "@sapphire/prettier-config"
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,38 +39,79 @@ export class UserCommand extends Command {
|
||||||
? await interactionOrMessage.channel.send({ content: '🤔 Thinking... 🤔' })
|
? await interactionOrMessage.channel.send({ content: '🤔 Thinking... 🤔' })
|
||||||
: await interactionOrMessage.reply({ content: '🤔 Thinking... 🤔', fetchReply: true });
|
: 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: 'POST',
|
method: 'GET',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
Accept: 'application/json',
|
|
||||||
Authorization: `Bearer ${process.env.STABILITY_API_KEY}`
|
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 {
|
const balance = (await creditCountResponse.json()).credits || 0;
|
||||||
artifacts: Array<{
|
|
||||||
base64: string;
|
|
||||||
seed: number;
|
|
||||||
finishReason: string;
|
|
||||||
}>;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!response.ok) {
|
if (balance > 5) {
|
||||||
const content = `Sorry! I goofed up. Please ask my maker HimbothySwaggins about what could have happened!`;
|
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) {
|
if (interactionOrMessage instanceof Message) {
|
||||||
return askMessage.edit({ content });
|
return askMessage.edit({ content });
|
||||||
|
@ -79,20 +120,6 @@ export class UserCommand extends Command {
|
||||||
return interactionOrMessage.editReply({
|
return interactionOrMessage.editReply({
|
||||||
content: content
|
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