Discord bot to open dong files

make more deno-y

vielle.dev 30243ae4 51e09bde

verified
+19 -26
+3 -3
src/commands/dong/create.ts
··· 1 import { 2 - Attachment, 3 AttachmentBuilder, 4 ChatInputCommandInteraction, 5 SlashCommandBuilder, 6 } from "discord.js"; 7 - import type { customClient } from "../.."; 8 import { createDong } from "../../lib/dong-io.ts"; 9 import { download } from "../../lib/download.ts"; 10 11 export const data = new SlashCommandBuilder() 12 .setName("create") ··· 47 48 await interaction.deferReply(); 49 50 - let downloaded = { 51 image: await download(image), 52 audio: await download(audio), 53 };
··· 1 import { 2 AttachmentBuilder, 3 ChatInputCommandInteraction, 4 SlashCommandBuilder, 5 } from "discord.js"; 6 + import type { customClient } from "../../index.ts"; 7 import { createDong } from "../../lib/dong-io.ts"; 8 import { download } from "../../lib/download.ts"; 9 + import { Buffer } from "node:buffer"; 10 11 export const data = new SlashCommandBuilder() 12 .setName("create") ··· 47 48 await interaction.deferReply(); 49 50 + const downloaded = { 51 image: await download(image), 52 audio: await download(audio), 53 };
+1
src/commands/dong/open.ts
··· 10 import { Mime } from "mime"; 11 import standardTypes from "mime/types/standard.js"; 12 import otherTypes from "mime/types/other.js"; 13 14 const mime = new Mime(standardTypes, otherTypes); 15 mime.define({ "audio/mpeg": ["mp3"] });
··· 10 import { Mime } from "mime"; 11 import standardTypes from "mime/types/standard.js"; 12 import otherTypes from "mime/types/other.js"; 13 + import { Buffer } from "node:buffer"; 14 15 const mime = new Mime(standardTypes, otherTypes); 16 mime.define({ "audio/mpeg": ["mp3"] });
+2 -5
src/commands/util/ping.ts
··· 1 - import { 2 - ChatInputCommandInteraction, 3 - SlashCommandBuilder, 4 - } from "discord.js"; 5 - import type { customClient } from "../.."; 6 7 export const data = new SlashCommandBuilder() 8 .setName("ping")
··· 1 + import { ChatInputCommandInteraction, SlashCommandBuilder } from "discord.js"; 2 + import type { customClient } from "../../index.ts"; 3 4 export const data = new SlashCommandBuilder() 5 .setName("ping")
+7 -5
src/index.ts
··· 8 type Interaction, 9 } from "discord.js"; 10 import { glob } from "node:fs/promises"; 11 - import path from "node:path"; 12 13 - console.log(process.env); 14 - 15 - const token = process.env.TOKEN; 16 if (!token) throw new Error("Token required. Please fill in TOKEN in .env"); 17 console.log("Token Valid!"); 18 ··· 42 for await (const file of glob("src/commands/**/*.ts", { 43 exclude: ["node_modules"], 44 })) { 45 - const command = await import("file:///" + path.join(__dirname, "..", file)); 46 // check command contains all required properties 47 if ( 48 "data" in command && ··· 76 console.error(`No command ${interaction.commandName}`); 77 return; 78 } 79 80 try { 81 await command.execute(interaction);
··· 8 type Interaction, 9 } from "discord.js"; 10 import { glob } from "node:fs/promises"; 11 12 + const token = Deno.env.get("TOKEN"); 13 if (!token) throw new Error("Token required. Please fill in TOKEN in .env"); 14 console.log("Token Valid!"); 15 ··· 39 for await (const file of glob("src/commands/**/*.ts", { 40 exclude: ["node_modules"], 41 })) { 42 + console.log(file); 43 + const command = await import(`../${file}`); 44 // check command contains all required properties 45 if ( 46 "data" in command && ··· 74 console.error(`No command ${interaction.commandName}`); 75 return; 76 } 77 + 78 + console.log( 79 + `Got command /${interaction.commandName} from @${interaction.user.username}` 80 + ); 81 82 try { 83 await command.execute(interaction);
+1 -12
src/lib/dong-io.ts
··· 4 } 5 } 6 7 - const blobBytes = async (blob: Blob) => { 8 if ("bytes" in blob) return blob.bytes(); 9 return new Response(blob).arrayBuffer().then((buffer) => { 10 const uint = new Uint8Array(buffer); ··· 107 }, 108 }; 109 } 110 - 111 - export const download = (file: File) => { 112 - const url = URL.createObjectURL(file); 113 - const a = document.createElement("a"); 114 - a.href = url; 115 - a.download = file.name; 116 - document.body.appendChild(a); 117 - a.click(); 118 - document.body.removeChild(a); 119 - URL.revokeObjectURL(url); 120 - };
··· 4 } 5 } 6 7 + const blobBytes = (blob: Blob) => { 8 if ("bytes" in blob) return blob.bytes(); 9 return new Response(blob).arrayBuffer().then((buffer) => { 10 const uint = new Uint8Array(buffer); ··· 107 }, 108 }; 109 }
+5 -1
src/sync.js
··· 1 import { REST, Routes } from "discord.js"; 2 - const { CLIENT: clientId, TOKEN: token } = process.env; 3 import fs from "node:fs"; 4 import path from "node:path"; 5 6 const commands = []; 7 // Grab all the command folders from the commands directory you created earlier
··· 1 import { REST, Routes } from "discord.js"; 2 import fs from "node:fs"; 3 import path from "node:path"; 4 + 5 + const clientId = Deno.env.get("CLIENT"); 6 + const token = Deno.env.get("TOKEN"); 7 + if (!clientId) throw "CLIENT not defined"; 8 + if (!token) throw "TOKEN not defined"; 9 10 const commands = []; 11 // Grab all the command folders from the commands directory you created earlier