From a58eb676bd37cda10fcb711fcf6599c294133bb7 Mon Sep 17 00:00:00 2001 From: atridadl Date: Fri, 10 Nov 2023 23:52:39 -0700 Subject: [PATCH] tts --- src/commands/fancypic.ts | 42 ++++++++++++++-------------------------- src/commands/pic.ts | 42 ++++++++++++++-------------------------- src/commands/tts.ts | 21 +++++++++++++++----- src/index.ts | 6 +++--- 4 files changed, 49 insertions(+), 62 deletions(-) diff --git a/src/commands/fancypic.ts b/src/commands/fancypic.ts index 2d8f3ae..64f9e27 100644 --- a/src/commands/fancypic.ts +++ b/src/commands/fancypic.ts @@ -59,37 +59,25 @@ export class UserCommand extends Command { // get an array buffer const imageBuffer = await fetch(imageUrl).then((r) => r.arrayBuffer()); - if (response.data.length === 0) { - const content = `Sorry, I can't complete the prompt for: ${prompt}`; + const imageAttachment: AttachmentBuilder[] = []; - if (interactionOrMessage instanceof Message) { - return askMessage.edit({ content }); - } + imageAttachment.push( + new AttachmentBuilder(Buffer.from(new Uint8Array(imageBuffer)), { + name: 'himbot_response.jpg', + description: `An image generated by Himbot using the prompt: ${prompt}` + }) + ); - return interactionOrMessage.editReply({ - content: content - }); - } else { - const imageAttachment: AttachmentBuilder[] = []; + const content = `Prompt: ${prompt}:`; - 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) { - return askMessage.edit({ content, files: imageAttachment }); - } - - return interactionOrMessage.editReply({ - content, - files: imageAttachment - }); + if (interactionOrMessage instanceof Message) { + return askMessage.edit({ content, files: imageAttachment }); } + + return interactionOrMessage.editReply({ + content, + files: imageAttachment + }); } catch (error) { const content = "Sorry, I can't complete the prompt for: " + prompt + '\n' + error; diff --git a/src/commands/pic.ts b/src/commands/pic.ts index 3856b0d..98bfeea 100644 --- a/src/commands/pic.ts +++ b/src/commands/pic.ts @@ -59,37 +59,25 @@ export class UserCommand extends Command { // get an array buffer const imageBuffer = await fetch(imageUrl).then((r) => r.arrayBuffer()); - if (response.data.length === 0) { - const content = `Sorry, I can't complete the prompt for: ${prompt}`; + const imageAttachment: AttachmentBuilder[] = []; - if (interactionOrMessage instanceof Message) { - return askMessage.edit({ content }); - } + imageAttachment.push( + new AttachmentBuilder(Buffer.from(new Uint8Array(imageBuffer)), { + name: 'himbot_response.jpg', + description: `An image generated by Himbot using the prompt: ${prompt}` + }) + ); - return interactionOrMessage.editReply({ - content: content - }); - } else { - const imageAttachment: AttachmentBuilder[] = []; + const content = `Prompt: ${prompt}:`; - 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) { - return askMessage.edit({ content, files: imageAttachment }); - } - - return interactionOrMessage.editReply({ - content, - files: imageAttachment - }); + if (interactionOrMessage instanceof Message) { + return askMessage.edit({ content, files: imageAttachment }); } + + return interactionOrMessage.editReply({ + content, + files: imageAttachment + }); } catch (error) { const content = "Sorry, I can't complete the prompt for: " + prompt + '\n' + error; diff --git a/src/commands/tts.ts b/src/commands/tts.ts index 8db4347..2a0aa4e 100644 --- a/src/commands/tts.ts +++ b/src/commands/tts.ts @@ -1,6 +1,6 @@ import { ApplyOptions } from '@sapphire/decorators'; import { Args, BucketScope, Command } from '@sapphire/framework'; -import { AttachmentBuilder, Message } from 'discord.js'; +import { AttachmentBuilder, Message, MessageFlags } from 'discord.js'; import OpenAI from 'openai'; const openai = new OpenAI({ @@ -64,21 +64,32 @@ export class UserCommand extends Command { const content = `Prompt: ${prompt}:`; if (interactionOrMessage instanceof Message) { - return askMessage.edit({ content, files: mp3Attachment }); + return askMessage.edit({ + content, + files: mp3Attachment, + flags: '8192' + }); } return interactionOrMessage.editReply({ content, - files: mp3Attachment + files: mp3Attachment, + options: { + flags: MessageFlags.IsVoiceMessage.valueOf() + } }); } catch (error) { const content = "Sorry, I can't complete the prompt for: " + prompt + '\n' + error; if (interactionOrMessage instanceof Message) { - return askMessage.edit({ content }); + return askMessage.edit({ + content + }); } - return interactionOrMessage.editReply({ content }); + return interactionOrMessage.editReply({ + content + }); } } } diff --git a/src/index.ts b/src/index.ts index 64879e1..0ebbc69 100644 --- a/src/index.ts +++ b/src/index.ts @@ -8,8 +8,8 @@ const client = new SapphireClient({ status: 'online', activities: [ { - name: 'BOAT PARADE! BOAT PARADE! BOAT PARADE!', - type: ActivityType.Listening + name: 'idk', + type: ActivityType.Custom } ] }, @@ -22,7 +22,7 @@ const client = new SapphireClient({ defaultCooldown: { // 10s delay: 10_000, - filteredCommands: ['disclosure', 'support', 'ping', 'wryna'], + filteredCommands: ['support', 'ping', 'wryna'], limit: 2, // Yes... I did hardcode myself. filteredUsers: ['83679718401904640'],