Quick change to commands
This commit is contained in:
parent
b9c02a157b
commit
e5039e7d7b
3 changed files with 68 additions and 6 deletions
|
@ -27,7 +27,7 @@ export class UserCommand extends Command {
|
||||||
|
|
||||||
// Message command
|
// Message command
|
||||||
public async messageRun(message: Message, args: Args) {
|
public async messageRun(message: Message, args: Args) {
|
||||||
return this.ask(message, args.getOption('prompt') || message.content.split('!wryna ')[1]);
|
return this.ask(message, args.getOption('prompt') || message.content.split('!ask ')[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Chat Input (slash) command
|
// Chat Input (slash) command
|
||||||
|
|
50
src/commands/credits.ts
Normal file
50
src/commands/credits.ts
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
import { ApplyOptions } from '@sapphire/decorators';
|
||||||
|
import { Command } from '@sapphire/framework';
|
||||||
|
import { Message } from 'discord.js';
|
||||||
|
|
||||||
|
@ApplyOptions<Command.Options>({
|
||||||
|
description: 'Make a picture!'
|
||||||
|
})
|
||||||
|
export class UserCommand extends Command {
|
||||||
|
// Register Chat Input and Context Menu command
|
||||||
|
public override registerApplicationCommands(registry: Command.Registry) {
|
||||||
|
registry.registerChatInputCommand((builder) => builder.setName(this.name).setDescription(this.description));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Message command
|
||||||
|
public async messageRun(message: Message) {
|
||||||
|
return this.credits(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Chat Input (slash) command
|
||||||
|
public async chatInputRun(interaction: Command.ChatInputCommandInteraction) {
|
||||||
|
return this.credits(interaction);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async credits(interactionOrMessage: Message | Command.ChatInputCommandInteraction | Command.ContextMenuCommandInteraction) {
|
||||||
|
const askMessage =
|
||||||
|
interactionOrMessage instanceof Message
|
||||||
|
? await interactionOrMessage.channel.send({ content: '🤔 Thinking... 🤔' })
|
||||||
|
: await interactionOrMessage.reply({ content: '🤔 Thinking... 🤔', fetchReply: true });
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
const content = `I have ${balance} credits remaining for image generation!`;
|
||||||
|
|
||||||
|
if (interactionOrMessage instanceof Message) {
|
||||||
|
return askMessage.edit({ content });
|
||||||
|
}
|
||||||
|
|
||||||
|
return interactionOrMessage.editReply({
|
||||||
|
content: content
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,6 +2,8 @@ import { ApplyOptions } from '@sapphire/decorators';
|
||||||
import { Args, BucketScope, Command } from '@sapphire/framework';
|
import { Args, BucketScope, Command } from '@sapphire/framework';
|
||||||
import { AttachmentBuilder, Message } from 'discord.js';
|
import { AttachmentBuilder, Message } from 'discord.js';
|
||||||
|
|
||||||
|
// This is literally the worlds messiest TS code. Please don't judge me...
|
||||||
|
|
||||||
@ApplyOptions<Command.Options>({
|
@ApplyOptions<Command.Options>({
|
||||||
description: 'Make a picture!',
|
description: 'Make a picture!',
|
||||||
options: ['prompt'],
|
options: ['prompt'],
|
||||||
|
@ -25,7 +27,7 @@ export class UserCommand extends Command {
|
||||||
|
|
||||||
// Message command
|
// Message command
|
||||||
public async messageRun(message: Message, args: Args) {
|
public async messageRun(message: Message, args: Args) {
|
||||||
return this.pic(message, args.getOption('prompt') || message.content.split('!wryna ')[1]);
|
return this.pic(message, args.getOption('prompt') || message.content.split('!pic ')[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Chat Input (slash) command
|
// Chat Input (slash) command
|
||||||
|
@ -94,11 +96,21 @@ export class UserCommand extends Command {
|
||||||
const responseJSON = (await imageGenResponse.json()) as GenerationResponse;
|
const responseJSON = (await imageGenResponse.json()) as GenerationResponse;
|
||||||
const imageAttachment = new AttachmentBuilder(Buffer.from(responseJSON.artifacts[0].base64, 'base64'));
|
const imageAttachment = new AttachmentBuilder(Buffer.from(responseJSON.artifacts[0].base64, 'base64'));
|
||||||
|
|
||||||
|
const newCreditCountResponse = await fetch(`https://api.stability.ai/v1/user/balance`, {
|
||||||
|
method: 'GET',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
Authorization: `Bearer ${process.env.STABILITY_API_KEY}`
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const newBalance = (await newCreditCountResponse.json()).credits || 0;
|
||||||
|
|
||||||
const content =
|
const content =
|
||||||
`Prompt: ${prompt}${
|
`Credits Used: ${balance - newBalance}\nPrompt: ${prompt}${
|
||||||
balance &&
|
balance <= 300
|
||||||
balance <= 300 &&
|
? `\n\n⚠️I am now at ${balance} credits. If you'd like to help fund this command, please type "/support" for details!`
|
||||||
`\n\n⚠️I am now at ${balance} credits. If you'd like to help fund this command, please type "/support" for details!`
|
: ''
|
||||||
}` || 'ERROR!';
|
}` || 'ERROR!';
|
||||||
|
|
||||||
if (interactionOrMessage instanceof Message) {
|
if (interactionOrMessage instanceof Message) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue