Discord bot to open dong files
1import {
2 AttachmentBuilder,
3 ChatInputCommandInteraction,
4 SlashCommandBuilder,
5} from "discord.js";
6import type { customClient } from "../..";
7import { download } from "../../lib/download";
8import { readDong } from "../../lib/dong-io";
9import { Mime } from "mime";
10import standardTypes from "mime/types/standard.js";
11import otherTypes from "mime/types/other.js";
12
13const mime = new Mime(standardTypes, otherTypes);
14mime.define({ "audio/mpeg": ["mp3"] });
15
16export const data = new SlashCommandBuilder()
17 .setName("open")
18 .setDescription("Open a dong file!")
19 .addAttachmentOption((opt) =>
20 opt.setName("dong").setDescription("The dong file").setRequired(true)
21 );
22export const execute = async (
23 interaction: ChatInputCommandInteraction & { client: customClient }
24) => {
25 const dong = interaction.options.getAttachment("dong", true);
26 await interaction.deferReply();
27
28 const downloadedDong = await download(dong);
29 console.log(downloadedDong);
30
31 const output = await readDong(downloadedDong);
32 if (typeof output === "string") {
33 await interaction.editReply(output);
34 return;
35 }
36 const { image, audio } = output;
37
38 console.log(image, audio);
39
40 await interaction.editReply({
41 files: [
42 (() => {
43 const img = new AttachmentBuilder(Buffer.from(image.data.buffer), {
44 name: `${dong.name.match(/^.*(?=\.dong$)/gm)}.${mime.getExtension(
45 image.mime
46 )}`,
47 });
48 img.setSpoiler(true);
49 return img;
50 })(),
51 new AttachmentBuilder(Buffer.from(audio.data.buffer), {
52 name: `${dong.name.match(/^.*(?=\.dong$)/gm)}.${mime.getExtension(
53 audio.mime
54 )}`,
55 }),
56 ],
57 });
58};