popii-framework 0.6.1-beta.0 → 0.6.1-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +3 -3
- package/dist/index.js +45 -40
- package/dist/loader/index.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -170,7 +170,7 @@ async function scaffoldProject(opts) {
|
|
|
170
170
|
version: "1.0.0",
|
|
171
171
|
private: true,
|
|
172
172
|
scripts: { dev: "popii dev", start: "bun src/index.ts" },
|
|
173
|
-
dependencies: { popii: "latest", "discord.js": djsVersion, ...builtinDeps, ...communityDeps },
|
|
173
|
+
dependencies: { "popii-framework": "latest", "discord.js": djsVersion, ...builtinDeps, ...communityDeps },
|
|
174
174
|
devDependencies: { "@types/bun": "latest" }
|
|
175
175
|
};
|
|
176
176
|
await Bun.write(join(targetDir, "package.json"), JSON.stringify(pkgJson, null, 2));
|
|
@@ -223,7 +223,7 @@ services:
|
|
|
223
223
|
restart: unless-stopped
|
|
224
224
|
`);
|
|
225
225
|
}
|
|
226
|
-
const builtinImport = plugins.length > 0 ? `import { popiiClient, ${plugins.join(", ")} } from "popii";` : `import { popiiClient } from "popii";`;
|
|
226
|
+
const builtinImport = plugins.length > 0 ? `import { popiiClient, ${plugins.join(", ")} } from "popii-framework";` : `import { popiiClient } from "popii-framework";`;
|
|
227
227
|
const communityImportLines = communityPlugins.map((cp) => `import { ${cp.exportName} } from "${cp.npmName}";`).join(`
|
|
228
228
|
`);
|
|
229
229
|
const imports = communityImportLines ? `${builtinImport}
|
|
@@ -257,7 +257,7 @@ process.on("SIGINT", async () => {
|
|
|
257
257
|
});
|
|
258
258
|
`;
|
|
259
259
|
await Bun.write(join(targetDir, "src", "index.ts"), indexTs);
|
|
260
|
-
const pingTs = `import { command } from "popii";
|
|
260
|
+
const pingTs = `import { command } from "popii-framework";
|
|
261
261
|
|
|
262
262
|
export default command({
|
|
263
263
|
name: "ping",
|
package/dist/index.js
CHANGED
|
@@ -29,7 +29,8 @@ var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
|
29
29
|
|
|
30
30
|
// src/loader/index.ts
|
|
31
31
|
import { readdir } from "node:fs/promises";
|
|
32
|
-
import { join, dirname, relative } from "node:path";
|
|
32
|
+
import { join, dirname, relative, resolve } from "node:path";
|
|
33
|
+
import { pathToFileURL } from "node:url";
|
|
33
34
|
import { ApplicationCommandOptionType } from "discord.js";
|
|
34
35
|
function propagateProperties(parent) {
|
|
35
36
|
if (!parent.options)
|
|
@@ -57,9 +58,10 @@ function propagateProperties(parent) {
|
|
|
57
58
|
async function loadCommands(baseDir, useFolderRouting = true) {
|
|
58
59
|
const commands = new Map;
|
|
59
60
|
const rawModules = new Map;
|
|
61
|
+
const absBaseDir = resolve(baseDir);
|
|
60
62
|
let entries;
|
|
61
63
|
try {
|
|
62
|
-
entries = await readdir(
|
|
64
|
+
entries = await readdir(absBaseDir, { recursive: true, withFileTypes: true });
|
|
63
65
|
} catch (err) {
|
|
64
66
|
if (err.code === "ENOENT")
|
|
65
67
|
return commands;
|
|
@@ -70,10 +72,9 @@ async function loadCommands(baseDir, useFolderRouting = true) {
|
|
|
70
72
|
continue;
|
|
71
73
|
}
|
|
72
74
|
const fullPath = join(entry.parentPath, entry.name);
|
|
73
|
-
const relPath = relative(
|
|
75
|
+
const relPath = relative(absBaseDir, fullPath).replace(/\\/g, "/").replace(/\.(ts|js)$/, "");
|
|
74
76
|
let module;
|
|
75
|
-
|
|
76
|
-
module = __require(fullPath);
|
|
77
|
+
module = await import(pathToFileURL(fullPath).href);
|
|
77
78
|
const cmd = module.default;
|
|
78
79
|
if (!cmd || typeof cmd !== "object") {
|
|
79
80
|
throw new Error(`[Popii] Invalid command export in ${fullPath}. MUST export a default command definition.`);
|
|
@@ -200,12 +201,14 @@ var init_error = __esm(() => {
|
|
|
200
201
|
|
|
201
202
|
// src/loader/fizz.ts
|
|
202
203
|
import { readdir as readdir2 } from "node:fs/promises";
|
|
203
|
-
import { join as join2, parse } from "node:path";
|
|
204
|
+
import { join as join2, parse, resolve as resolve2 } from "node:path";
|
|
205
|
+
import { pathToFileURL as pathToFileURL2 } from "node:url";
|
|
204
206
|
async function loadFizz(baseDir) {
|
|
205
207
|
const events = new Map;
|
|
208
|
+
const absBaseDir = resolve2(baseDir);
|
|
206
209
|
let entries;
|
|
207
210
|
try {
|
|
208
|
-
entries = await readdir2(
|
|
211
|
+
entries = await readdir2(absBaseDir, { recursive: true, withFileTypes: true });
|
|
209
212
|
} catch (err) {
|
|
210
213
|
if (err.code === "ENOENT")
|
|
211
214
|
return events;
|
|
@@ -218,8 +221,7 @@ async function loadFizz(baseDir) {
|
|
|
218
221
|
const fullPath = join2(entry.parentPath, entry.name);
|
|
219
222
|
const { name } = parse(entry.name);
|
|
220
223
|
let module;
|
|
221
|
-
|
|
222
|
-
module = __require(fullPath);
|
|
224
|
+
module = await import(pathToFileURL2(fullPath).href);
|
|
223
225
|
const handler = module.default;
|
|
224
226
|
if (typeof handler !== "function") {
|
|
225
227
|
throw new PopiiError("Invalid event export. MUST export a default function.", "INVALID_EVENT", "Ensure your event file exports a default async function.", fullPath);
|
|
@@ -234,12 +236,14 @@ var init_fizz = __esm(() => {
|
|
|
234
236
|
|
|
235
237
|
// src/loader/snaps.ts
|
|
236
238
|
import { readdir as readdir3 } from "node:fs/promises";
|
|
237
|
-
import { join as join3 } from "node:path";
|
|
239
|
+
import { join as join3, resolve as resolve3 } from "node:path";
|
|
240
|
+
import { pathToFileURL as pathToFileURL3 } from "node:url";
|
|
238
241
|
async function loadSnaps(baseDir) {
|
|
239
242
|
const snaps = new Map;
|
|
243
|
+
const absBaseDir = resolve3(baseDir);
|
|
240
244
|
let entries;
|
|
241
245
|
try {
|
|
242
|
-
entries = await readdir3(
|
|
246
|
+
entries = await readdir3(absBaseDir, { recursive: true, withFileTypes: true });
|
|
243
247
|
} catch (err) {
|
|
244
248
|
if (err.code === "ENOENT")
|
|
245
249
|
return snaps;
|
|
@@ -251,8 +255,7 @@ async function loadSnaps(baseDir) {
|
|
|
251
255
|
}
|
|
252
256
|
const fullPath = join3(entry.parentPath, entry.name);
|
|
253
257
|
let module;
|
|
254
|
-
|
|
255
|
-
module = __require(fullPath);
|
|
258
|
+
module = await import(pathToFileURL3(fullPath).href);
|
|
256
259
|
const snap = module.default;
|
|
257
260
|
if (!snap || typeof snap !== "object") {
|
|
258
261
|
throw new PopiiError("Invalid snap export. MUST export a default component definition.", "INVALID_SNAP", "Ensure your snap file exports a default snap() definition.", fullPath);
|
|
@@ -293,12 +296,14 @@ var init_locales = () => {};
|
|
|
293
296
|
|
|
294
297
|
// src/loader/middleware.ts
|
|
295
298
|
import { readdir as readdir5 } from "node:fs/promises";
|
|
296
|
-
import { join as join5 } from "node:path";
|
|
299
|
+
import { join as join5, resolve as resolve4 } from "node:path";
|
|
300
|
+
import { pathToFileURL as pathToFileURL4 } from "node:url";
|
|
297
301
|
async function loadMiddlewares(baseDir) {
|
|
298
302
|
const middlewares = [];
|
|
303
|
+
const absBaseDir = resolve4(baseDir);
|
|
299
304
|
let entries;
|
|
300
305
|
try {
|
|
301
|
-
entries = await readdir5(
|
|
306
|
+
entries = await readdir5(absBaseDir, { recursive: true, withFileTypes: true });
|
|
302
307
|
entries.sort((a, b) => a.name.localeCompare(b.name));
|
|
303
308
|
} catch (err) {
|
|
304
309
|
if (err.code === "ENOENT")
|
|
@@ -310,8 +315,7 @@ async function loadMiddlewares(baseDir) {
|
|
|
310
315
|
continue;
|
|
311
316
|
}
|
|
312
317
|
const fullPath = join5(entry.parentPath, entry.name);
|
|
313
|
-
|
|
314
|
-
const module = __require(fullPath);
|
|
318
|
+
const module = await import(pathToFileURL4(fullPath).href);
|
|
315
319
|
if (typeof module.default === "function")
|
|
316
320
|
middlewares.push(module.default);
|
|
317
321
|
}
|
|
@@ -324,12 +328,14 @@ var init_middleware = () => {};
|
|
|
324
328
|
|
|
325
329
|
// src/loader/tasks.ts
|
|
326
330
|
import { readdir as readdir6 } from "node:fs/promises";
|
|
327
|
-
import { join as join6, parse as parse3 } from "node:path";
|
|
331
|
+
import { join as join6, parse as parse3, resolve as resolve5 } from "node:path";
|
|
332
|
+
import { pathToFileURL as pathToFileURL5 } from "node:url";
|
|
328
333
|
async function loadTasks(baseDir) {
|
|
329
334
|
const tasks = new Map;
|
|
335
|
+
const absBaseDir = resolve5(baseDir);
|
|
330
336
|
let entries;
|
|
331
337
|
try {
|
|
332
|
-
entries = await readdir6(
|
|
338
|
+
entries = await readdir6(absBaseDir, { recursive: true, withFileTypes: true });
|
|
333
339
|
} catch (err) {
|
|
334
340
|
if (err.code === "ENOENT")
|
|
335
341
|
return tasks;
|
|
@@ -340,8 +346,7 @@ async function loadTasks(baseDir) {
|
|
|
340
346
|
continue;
|
|
341
347
|
}
|
|
342
348
|
const fullPath = join6(entry.parentPath, entry.name);
|
|
343
|
-
|
|
344
|
-
const module = __require(fullPath);
|
|
349
|
+
const module = await import(pathToFileURL5(fullPath).href);
|
|
345
350
|
if (module.default && typeof module.default.run === "function") {
|
|
346
351
|
const name = module.default.name || parse3(entry.name).name;
|
|
347
352
|
tasks.set(name, module.default);
|
|
@@ -671,13 +676,13 @@ var init_middleware2 = __esm(() => {
|
|
|
671
676
|
import { createWriteStream, existsSync, mkdirSync } from "node:fs";
|
|
672
677
|
import { join as join7 } from "node:path";
|
|
673
678
|
function closeLogWriter() {
|
|
674
|
-
return new Promise((
|
|
679
|
+
return new Promise((resolve6) => {
|
|
675
680
|
if (logWriter) {
|
|
676
|
-
logWriter.end(
|
|
681
|
+
logWriter.end(resolve6);
|
|
677
682
|
logWriter = null;
|
|
678
683
|
currentLogDate = "";
|
|
679
684
|
} else {
|
|
680
|
-
|
|
685
|
+
resolve6();
|
|
681
686
|
}
|
|
682
687
|
});
|
|
683
688
|
}
|
|
@@ -3519,27 +3524,27 @@ function uiPlugin(options = {}) {
|
|
|
3519
3524
|
}
|
|
3520
3525
|
if (step.type === "text") {
|
|
3521
3526
|
let msgCollector = null;
|
|
3522
|
-
const replyPromise = !this.channel || typeof this.channel.createMessageCollector !== "function" ? new Promise(() => {}) : new Promise((
|
|
3527
|
+
const replyPromise = !this.channel || typeof this.channel.createMessageCollector !== "function" ? new Promise(() => {}) : new Promise((resolve6) => {
|
|
3523
3528
|
msgCollector = this.channel.createMessageCollector({ filter: (m) => m.author.id === this.user.id, time: timeoutMs, max: 1 });
|
|
3524
3529
|
msgCollector.on("collect", (m) => {
|
|
3525
3530
|
msgCollector.stop();
|
|
3526
|
-
|
|
3531
|
+
resolve6(m);
|
|
3527
3532
|
});
|
|
3528
3533
|
msgCollector.on("end", (collected, reason) => {
|
|
3529
3534
|
if (reason === "time")
|
|
3530
|
-
|
|
3535
|
+
resolve6(null);
|
|
3531
3536
|
});
|
|
3532
3537
|
});
|
|
3533
3538
|
let collector = null;
|
|
3534
|
-
const componentPromise = !lastMessage || typeof lastMessage.awaitMessageComponent !== "function" ? new Promise(() => {}) : new Promise((
|
|
3539
|
+
const componentPromise = !lastMessage || typeof lastMessage.awaitMessageComponent !== "function" ? new Promise(() => {}) : new Promise((resolve6) => {
|
|
3535
3540
|
collector = lastMessage.createMessageComponentCollector({ time: timeoutMs, filter: (int) => int.user.id === this.user.id });
|
|
3536
3541
|
collector.on("collect", (int) => {
|
|
3537
3542
|
collector.stop();
|
|
3538
|
-
|
|
3543
|
+
resolve6(int);
|
|
3539
3544
|
});
|
|
3540
3545
|
collector.on("end", (collected, reason) => {
|
|
3541
3546
|
if (reason === "time")
|
|
3542
|
-
|
|
3547
|
+
resolve6(null);
|
|
3543
3548
|
});
|
|
3544
3549
|
});
|
|
3545
3550
|
const result = await Promise.race([replyPromise, componentPromise]);
|
|
@@ -7451,12 +7456,12 @@ class Semaphore {
|
|
|
7451
7456
|
this.current++;
|
|
7452
7457
|
return;
|
|
7453
7458
|
}
|
|
7454
|
-
return new Promise((
|
|
7459
|
+
return new Promise((resolve6) => this.queue.push(resolve6));
|
|
7455
7460
|
}
|
|
7456
7461
|
release() {
|
|
7457
7462
|
if (this.queue.length > 0) {
|
|
7458
|
-
const
|
|
7459
|
-
|
|
7463
|
+
const resolve6 = this.queue.shift();
|
|
7464
|
+
resolve6();
|
|
7460
7465
|
} else {
|
|
7461
7466
|
this.current--;
|
|
7462
7467
|
}
|
|
@@ -7509,7 +7514,7 @@ function createYtdlpUtils(options, state) {
|
|
|
7509
7514
|
proc.kill();
|
|
7510
7515
|
} catch {}
|
|
7511
7516
|
};
|
|
7512
|
-
const spawnYtdlp = (args, timeoutMs) => new Promise((
|
|
7517
|
+
const spawnYtdlp = (args, timeoutMs) => new Promise((resolve6, reject) => {
|
|
7513
7518
|
const proc = nodeSpawn("yt-dlp", buildYtdlpArgs(args), { detached: process.platform !== "win32" });
|
|
7514
7519
|
state.activeProcesses.add(proc);
|
|
7515
7520
|
let out = "";
|
|
@@ -7521,7 +7526,7 @@ function createYtdlpUtils(options, state) {
|
|
|
7521
7526
|
proc.on("close", () => {
|
|
7522
7527
|
clearTimeout(timer);
|
|
7523
7528
|
state.activeProcesses.delete(proc);
|
|
7524
|
-
|
|
7529
|
+
resolve6(out);
|
|
7525
7530
|
});
|
|
7526
7531
|
proc.on("error", (e) => {
|
|
7527
7532
|
clearTimeout(timer);
|
|
@@ -7809,7 +7814,7 @@ function createResolver(options, state, utils, sb) {
|
|
|
7809
7814
|
} catch {}
|
|
7810
7815
|
}
|
|
7811
7816
|
});
|
|
7812
|
-
const procDone = new Promise((
|
|
7817
|
+
const procDone = new Promise((resolve6) => {
|
|
7813
7818
|
proc.on("close", () => {
|
|
7814
7819
|
clearTimeout(timer);
|
|
7815
7820
|
state.activeProcesses.delete(proc);
|
|
@@ -7817,7 +7822,7 @@ function createResolver(options, state, utils, sb) {
|
|
|
7817
7822
|
firstEntryResolve(null);
|
|
7818
7823
|
firstEntryResolve = null;
|
|
7819
7824
|
}
|
|
7820
|
-
|
|
7825
|
+
resolve6();
|
|
7821
7826
|
});
|
|
7822
7827
|
proc.on("error", () => {
|
|
7823
7828
|
clearTimeout(timer);
|
|
@@ -7826,7 +7831,7 @@ function createResolver(options, state, utils, sb) {
|
|
|
7826
7831
|
firstEntryResolve(null);
|
|
7827
7832
|
firstEntryResolve = null;
|
|
7828
7833
|
}
|
|
7829
|
-
|
|
7834
|
+
resolve6();
|
|
7830
7835
|
});
|
|
7831
7836
|
});
|
|
7832
7837
|
const firstEntry = await firstEntryPromise;
|
|
@@ -7844,7 +7849,7 @@ function createResolver(options, state, utils, sb) {
|
|
|
7844
7849
|
return { ...first, extraTracks };
|
|
7845
7850
|
}
|
|
7846
7851
|
pop.log.info(`Using yt-dlp to extract stream...`);
|
|
7847
|
-
const { stdout, stderr } = await new Promise((
|
|
7852
|
+
const { stdout, stderr } = await new Promise((resolve6, reject) => {
|
|
7848
7853
|
const args = ["--dump-json", "-f", "bestaudio/best", "--no-warnings"];
|
|
7849
7854
|
if (!isPlaylist)
|
|
7850
7855
|
args.push("--no-playlist");
|
|
@@ -7864,7 +7869,7 @@ function createResolver(options, state, utils, sb) {
|
|
|
7864
7869
|
proc.on("close", () => {
|
|
7865
7870
|
clearTimeout(timer);
|
|
7866
7871
|
state.activeProcesses.delete(proc);
|
|
7867
|
-
|
|
7872
|
+
resolve6({ stdout: out, stderr: err });
|
|
7868
7873
|
});
|
|
7869
7874
|
proc.on("error", (e) => {
|
|
7870
7875
|
clearTimeout(timer);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/loader/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AA6BvD,wBAAsB,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,gBAAgB,UAAO,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,sBAAsB,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/loader/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AA6BvD,wBAAsB,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,gBAAgB,UAAO,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,sBAAsB,CAAC,CAAC,CAkIzH"}
|