From b6f244aaa0a04db370ab9ee7dbf1e1199859b012 Mon Sep 17 00:00:00 2001 From: itsMapleLeaf <19603573+itsMapleLeaf@users.noreply.github.com> Date: Sun, 2 Oct 2022 17:57:49 -0500 Subject: [PATCH] wip more stuff --- packages/helpers/async-queue.ts | 6 +- packages/playground/package.json | 21 +++ packages/playground/src/main.tsx | 54 ++++++ packages/playground/tsconfig.json | 3 + packages/reacord/src/reacord-client.ts | 40 ++++- packages/reacord/src/reacord-instance.ts | 33 ++-- packages/reacord/src/renderer.ts | 200 ++++++++++++++++++----- pnpm-lock.yaml | 75 ++++----- 8 files changed, 315 insertions(+), 117 deletions(-) create mode 100644 packages/playground/package.json create mode 100644 packages/playground/src/main.tsx create mode 100644 packages/playground/tsconfig.json diff --git a/packages/helpers/async-queue.ts b/packages/helpers/async-queue.ts index f9421a7..3dea11b 100644 --- a/packages/helpers/async-queue.ts +++ b/packages/helpers/async-queue.ts @@ -10,14 +10,14 @@ export class AsyncQueue { private items: QueueItem[] = [] private running = false - add(callback: AsyncCallback): Promise> { + append(callback: AsyncCallback): Promise> { return new Promise((resolve, reject) => { this.items.push({ callback, resolve: resolve as any, reject }) - void this.runQueue() + void this.run() }) } - private async runQueue() { + private async run() { if (this.running) return this.running = true diff --git a/packages/playground/package.json b/packages/playground/package.json new file mode 100644 index 0000000..9bb8638 --- /dev/null +++ b/packages/playground/package.json @@ -0,0 +1,21 @@ +{ + "name": "@reacord/playground", + "version": "0.0.0", + "type": "module", + "scripts": { + "dev": "tsx watch src/main.tsx" + }, + "dependencies": { + "@reacord/helpers": "workspace:*", + "discord.js": "^14.1.2", + "dotenv": "^16.0.1", + "ora": "^6.1.2", + "react": "^18.2.0" + }, + "devDependencies": { + "@types/node": "*", + "@types/react": "^18.0.16", + "tsx": "^3.8.0", + "typescript": "^4.7.4" + } +} diff --git a/packages/playground/src/main.tsx b/packages/playground/src/main.tsx new file mode 100644 index 0000000..670fc4e --- /dev/null +++ b/packages/playground/src/main.tsx @@ -0,0 +1,54 @@ +import { raise } from "@reacord/helpers/raise" +import { Client, GatewayIntentBits } from "discord.js" +import * as dotenv from "dotenv" +import { join } from "node:path" +import { fileURLToPath } from "node:url" +import { oraPromise } from "ora" +import React from "react" +import { Button, ReacordClient } from "../../reacord/src/main" + +dotenv.config({ + path: join(fileURLToPath(import.meta.url), "../../../../.env"), + override: true, +}) + +const token = process.env.TEST_BOT_TOKEN ?? raise("TEST_BOT_TOKEN not defined") + +const client = new Client({ intents: [GatewayIntentBits.Guilds] }) +const reacord = new ReacordClient({ token }) + +client.once("ready", async (client) => { + try { + await oraPromise( + client.application.commands.create({ + name: "counter", + description: "counts things", + }), + "Registering commands", + ) + } catch (error) { + console.error("Failed to register commands:", error) + } +}) + +client.on("interactionCreate", async (interaction) => { + if ( + interaction.isChatInputCommand() && + interaction.commandName === "counter" + ) { + reacord.reply(interaction, ) + // reacord.reply(interaction, "test3").render("test4") + } +}) + +await oraPromise(client.login(token), "Logging in") + +function Counter() { + const [count, setCount] = React.useState(0) + return ( + <> + count: {count} +