Discord bot to open dong files

make more deno-y

vielle.dev 30243ae4 51e09bde

verified
Changed files
+19 -26
src
+3 -3
src/commands/dong/create.ts
···
import {
-
Attachment,
AttachmentBuilder,
ChatInputCommandInteraction,
SlashCommandBuilder,
} from "discord.js";
-
import type { customClient } from "../..";
+
import type { customClient } from "../../index.ts";
import { createDong } from "../../lib/dong-io.ts";
import { download } from "../../lib/download.ts";
+
import { Buffer } from "node:buffer";
export const data = new SlashCommandBuilder()
.setName("create")
···
await interaction.deferReply();
-
let downloaded = {
+
const downloaded = {
image: await download(image),
audio: await download(audio),
};
+1
src/commands/dong/open.ts
···
import { Mime } from "mime";
import standardTypes from "mime/types/standard.js";
import otherTypes from "mime/types/other.js";
+
import { Buffer } from "node:buffer";
const mime = new Mime(standardTypes, otherTypes);
mime.define({ "audio/mpeg": ["mp3"] });
+2 -5
src/commands/util/ping.ts
···
-
import {
-
ChatInputCommandInteraction,
-
SlashCommandBuilder,
-
} from "discord.js";
-
import type { customClient } from "../..";
+
import { ChatInputCommandInteraction, SlashCommandBuilder } from "discord.js";
+
import type { customClient } from "../../index.ts";
export const data = new SlashCommandBuilder()
.setName("ping")
+7 -5
src/index.ts
···
type Interaction,
} from "discord.js";
import { glob } from "node:fs/promises";
-
import path from "node:path";
-
console.log(process.env);
-
-
const token = process.env.TOKEN;
+
const token = Deno.env.get("TOKEN");
if (!token) throw new Error("Token required. Please fill in TOKEN in .env");
console.log("Token Valid!");
···
for await (const file of glob("src/commands/**/*.ts", {
exclude: ["node_modules"],
})) {
-
const command = await import("file:///" + path.join(__dirname, "..", file));
+
console.log(file);
+
const command = await import(`../${file}`);
// check command contains all required properties
if (
"data" in command &&
···
console.error(`No command ${interaction.commandName}`);
return;
}
+
+
console.log(
+
`Got command /${interaction.commandName} from @${interaction.user.username}`
+
);
try {
await command.execute(interaction);
+1 -12
src/lib/dong-io.ts
···
}
}
-
const blobBytes = async (blob: Blob) => {
+
const blobBytes = (blob: Blob) => {
if ("bytes" in blob) return blob.bytes();
return new Response(blob).arrayBuffer().then((buffer) => {
const uint = new Uint8Array(buffer);
···
},
};
}
-
-
export const download = (file: File) => {
-
const url = URL.createObjectURL(file);
-
const a = document.createElement("a");
-
a.href = url;
-
a.download = file.name;
-
document.body.appendChild(a);
-
a.click();
-
document.body.removeChild(a);
-
URL.revokeObjectURL(url);
-
};
+5 -1
src/sync.js
···
import { REST, Routes } from "discord.js";
-
const { CLIENT: clientId, TOKEN: token } = process.env;
import fs from "node:fs";
import path from "node:path";
+
+
const clientId = Deno.env.get("CLIENT");
+
const token = Deno.env.get("TOKEN");
+
if (!clientId) throw "CLIENT not defined";
+
if (!token) throw "TOKEN not defined";
const commands = [];
// Grab all the command folders from the commands directory you created earlier