Discord bot to open dong files
1import { 2 AttachmentBuilder, 3 ChatInputCommandInteraction, 4 SlashCommandBuilder, 5} from "discord.js"; 6import type { customClient } from "../../index.ts"; 7import { createDong } from "../../lib/dong-io.ts"; 8import { download } from "../../lib/download.ts"; 9import { Buffer } from "node:buffer"; 10 11export const data = new SlashCommandBuilder() 12 .setName("create") 13 .setDescription("Create a dong file!") 14 .addAttachmentOption((opt) => 15 opt 16 .setName("image") 17 .setDescription("The image of the dong file") 18 .setRequired(true) 19 ) 20 .addAttachmentOption((opt) => 21 opt 22 .setName("audio") 23 .setDescription("The audio of the dong file") 24 .setRequired(true) 25 ) 26 .addStringOption((opt) => 27 opt 28 .setName("name") 29 .setDescription("Filename of the dong file") 30 .setRequired(true) 31 ); 32export const execute = async ( 33 interaction: ChatInputCommandInteraction & { client: customClient } 34) => { 35 const filename = interaction.options.getString("name", true) + ".dong"; 36 const image = interaction.options.getAttachment("image", true); 37 const audio = interaction.options.getAttachment("audio", true); 38 39 if (!image.contentType?.startsWith("image/")) { 40 await interaction.reply("Image is not a valid image!"); 41 return; 42 } 43 if (!audio.contentType?.startsWith("audio/")) { 44 await interaction.reply("Audio is not a valid audio!"); 45 return; 46 } 47 48 await interaction.deferReply(); 49 50 const downloaded = { 51 image: await download(image), 52 audio: await download(audio), 53 }; 54 55 const dong = new File( 56 [await createDong(downloaded.image, downloaded.audio)], 57 filename, 58 { type: "application/prs.vielle.dong" } 59 ); 60 61 await interaction.editReply({ 62 files: [ 63 new AttachmentBuilder(Buffer.from(await dong.arrayBuffer()), { 64 name: dong.name, 65 }), 66 ], 67 }); 68};